Adding NPC through the player

Ales Ros

New member
Hi everyone
I'm trying to add NPC through the player itself.

Yes, I know that the "normal" method is add through the stages files (same thing with enemies, weapons or objects in general), but the main problem about this method is that the NPCs would have to be added at ALL stages, every single file....which is painful. Not to mention that if I wanted to change some NPC, would have to change every file, every line too... yea, just no.

(Of course, if there is a way NPC remain through the game (stages) that would solve the problem, but I don't think there is such option....)

So I came to the conclusion that perhaps the simplest and most practical method would be to generate a NPC through the player itself. In this case, with a key.
Example: If I'm playing with Ryu, I press "F1" on my keyboard and pum... i have Ken as NPC. No mystery.
And if the stage changes... I press the key again. Easy, fast... (and I don't need to edit stages anymore!)

I know how to add NPC/enemies through the stage files, but I have no idea how to do the same on characters files...
I'm reading openbor manual but I still can't understand exacly how I can do that.
 
So you want to spawn NPC together with player right?

The easiest way is to use SPAWN animation which spawns the NPC when player is spawned

Example:
Code:
anim spawn
	offset	177 162
	delay 8
@script
if(frame==1)
{
    void vSelf = getlocalvar("self"); //Calling entity.
    float fX = getentityproperty(vSelf, "x"); //X position of caller.
    float fY = getentityproperty(vSelf, "a"); //Y position of caller.
    float fZ = getentityproperty(vSelf, "z"); //Z position of caller.
    void img;
    clearspawnentry();
    setspawnentry("name", "Anita");
    img = spawn();
    changeentityproperty(img, "position", fX-100, fY, fZ-1);
    changeentityproperty(img, "parent", vSelf);
    changeentityproperty(img, "map", getentityproperty(vSelf, "map"));
    changeentityproperty(img, "direction", getentityproperty(vSelf, "direction"));
}
@end_script
	frame	data/chars/donovan/spawn01.gif
	frame	data/chars/donovan/spawn02.gif
	frame	data/chars/donovan/spawn03.gif
	frame	data/chars/donovan/spawn04.gif
	frame	data/chars/donovan/spawn05.gif
	delay	30
	frame	data/chars/donovan/spawn06.gif
	delay	5
	frame	data/chars/donovan/spawn07.gif
	frame	data/chars/donovan/spawn08.gif
	frame	data/chars/donovan/spawn09.gif
	frame	data/chars/donovan/spawn10.gif
	frame	data/chars/donovan/spawn11.gif
	frame	data/chars/donovan/spawn12.gif
	frame	data/chars/donovan/spawn13.gif
	delay	8
	frame	data/chars/donovan/spawn14.gif
	frame	data/chars/donovan/spawn15.gif

With this, when Donovan (player) is spawned on field, Anita (NPC) will be spawned right after him
This example uses script but there are non-script way to spawn NPC in SPAWN animation :)

Example: If I'm playing with Ryu, I press "F1" on my keyboard and pum... i have Ken as NPC. No mystery.

If you want to press key to summon NPC, that's doable. There are two ways:
1. No animation change from player i.e just click of a key

2. Animation change from player or special summon animation

NOTE: I haven't found a simpler example for #2
 
Bloodbane said:
So you want to spawn NPC together with player right?

That's correct.

Bloodbane said:
The easiest way is to use SPAWN animation which spawns the NPC when player is spawned

Example:
Code:
anim spawn
	offset	177 162
	delay 8
@script
if(frame==1)
{
    void vSelf = getlocalvar("self"); //Calling entity.
    float fX = getentityproperty(vSelf, "x"); //X position of caller.
    float fY = getentityproperty(vSelf, "a"); //Y position of caller.
    float fZ = getentityproperty(vSelf, "z"); //Z position of caller.
    void img;
    clearspawnentry();
    setspawnentry("name", "Anita");
    img = spawn();
    changeentityproperty(img, "position", fX-100, fY, fZ-1);
    changeentityproperty(img, "parent", vSelf);
    changeentityproperty(img, "map", getentityproperty(vSelf, "map"));
    changeentityproperty(img, "direction", getentityproperty(vSelf, "direction"));
}
@end_script
	frame	data/chars/donovan/spawn01.gif
	frame	data/chars/donovan/spawn02.gif
	frame	data/chars/donovan/spawn03.gif
	frame	data/chars/donovan/spawn04.gif
	frame	data/chars/donovan/spawn05.gif
	delay	30
	frame	data/chars/donovan/spawn06.gif
	delay	5
	frame	data/chars/donovan/spawn07.gif
	frame	data/chars/donovan/spawn08.gif
	frame	data/chars/donovan/spawn09.gif
	frame	data/chars/donovan/spawn10.gif
	frame	data/chars/donovan/spawn11.gif
	frame	data/chars/donovan/spawn12.gif
	frame	data/chars/donovan/spawn13.gif
	delay	8
	frame	data/chars/donovan/spawn14.gif
	frame	data/chars/donovan/spawn15.gif

With this, when Donovan (player) is spawned on field, Anita (NPC) will be spawned right after him

I put that on my char code but I don't see any changes.
I started the game but I don't see the NPC (in my case is "Guy_3")
I changed this line "setspawnentry("name", "Anita");"
for this one
"setspawnentry("name", "Guy_3");"

Do I need to change anything else in the code?
Isn't necessary to add frames line, right? I just put the first part (until the end of the script)

This example uses script but there are non-script way to spawn NPC in SPAWN animation :)

It would be better because I'm not good with scripts  :P

If you want to press key to summon NPC, that's doable. There are two ways:
1. No animation change from player i.e just click of a key

Yes, I believe that is the best option (summon NPC with key) because at some point you may just not want to call any NPCs. In this case, no Key, no NPC. It is different from the first option where the NPC will always appear.

But for now I'd like to do the first choice (that code you posted)
 
I put that on my char code but I don't see any changes.
I started the game but I don't see the NPC (in my case is "Guy_3")
I changed this line "setspawnentry("name", "Anita");"
for this one
"setspawnentry("name", "Guy_3");"

Do I need to change anything else in the code?

The first requirement in summoning or spawning anything is the entity must be loaded before. If Guy_3 has been loaded, the script should spawn him fine

Isn't necessary to add frames line, right? I just put the first part (until the end of the script)

Yes, but just use some to suit the script. Look at this:

Code:
@script
if(frame==1)
{
...

This part means the spawning will be run on 2nd frame. That means the animation must have at least 2 frames to ensure the script will run

Yes, I believe that is the best option (summon NPC with key) because at some point you may just not want to call any NPCs

Hmmm... that one require script. But since you prefer non-script solution, for now I'll give you non-script solution

Oh yes, the first example I've shown you before is how to summon NPC which follows player. If you don't need the NPC to follow player, you can just use this in animation:

Code:
spawnframe 1 0 0 0 0
custentity Guy_3

This will spawn Guy_3 at second frame of animation right on player's position
 
Bloodbane said:
I put that on my char code but I don't see any changes.
I started the game but I don't see the NPC (in my case is "Guy_3")
I changed this line "setspawnentry("name", "Anita");"
for this one
"setspawnentry("name", "Guy_3");"

Do I need to change anything else in the code?

The first requirement in summoning or spawning anything is the entity must be loaded before. If Guy_3 has been loaded, the script should spawn him fine

Isn't necessary to add frames line, right? I just put the first part (until the end of the script)

Yes, but just use some to suit the script. Look at this:

Code:
@script
if(frame==1)
{
...

This part means the spawning will be run on 2nd frame. That means the animation must have at least 2 frames to ensure the script will run

Yes, I believe that is the best option (summon NPC with key) because at some point you may just not want to call any NPCs

Hmmm... that one require script. But since you prefer non-script solution, for now I'll give you non-script solution

Oh yes, the first example I've shown you before is how to summon NPC which follows player. If you don't need the NPC to follow player, you can just use this in animation:

Code:
spawnframe 1 0 0 0 0
custentity Guy_3

This will spawn Guy_3 at second frame of animation right on player's position

Finally it worked!
The first option (script) I forgot to add "load guy_3" before
and the second option (non script)  also worked

The only problem is that "anim spawn" is not working
So to test "Guy_3" I had to add on "anim idle" but the problem is that the NPC disappears after a few seconds (keep "resetting" and he still creates several "Guy_3")
Well... maybe that's the reason why I need to use NPC spawn on "anim spawn", because I just want the NPC to be created only once...

Any idea why "anim spawn" is not working?

 
That's strange cause SPAWN animation is usually played by player.
Are your players using weapon model?
Have you checked player's text to see if there's another SPAWN animation?

So to test "Guy_3" I had to add on "anim idle" but the problem is that the NPC disappears after a few seconds (keep "resetting" and he still creates several "Guy_3")

That's strange...
 
Bloodbane said:
Have you checked player's text to see if there's another SPAWN animation?

omg, i'm stupid
Yes, that was the problem
2 anim SPAWN on the file
Now is ok, its working  ;D

but...

Bloodbane said:
So to test "Guy_3" I had to add on "anim idle" but the problem is that the NPC disappears after a few seconds (keep "resetting" and he still creates several "Guy_3")

That's strange...

This problem still persists... Guy keeps reseting (after 2 seconds)
He appears and disappers after few seconds...
Its strange because anim respawn should run only once, right?
If you want I can record video to show you what is happening, but the resume about is happening is like I described above, the NPC keeps popping up and reappearing...
God dammit... this is the only problem now.

EDIT: Oh, is important to say that he is not creating multiple "guys" as before. It's just one (but it's resetting)
 
If you want I can record video to show you what is happening, but the resume about is happening is like I described above, the NPC keeps popping up and reappearing...

Yes, I'd like to see video of this

But you also should post anim SPAWN and RESPAWN here too for me to check
 
Bloodbane said:
If you want I can record video to show you what is happening, but the resume about is happening is like I described above, the NPC keeps popping up and reappearing...

Yes, I'd like to see video of this

But you also should post anim SPAWN and RESPAWN here too for me to check

Mod edit: please don't post any content from that game here.

I'm using the same code you posted

Code:
anim	spawn
	loop	0
	offset	238 177
	delay	3
@script
if(frame==1)
{
    void vSelf = getlocalvar("self"); //Calling entity.
    float fX = getentityproperty(vSelf, "x"); //X position of caller.
    float fY = getentityproperty(vSelf, "a"); //Y position of caller.
    float fZ = getentityproperty(vSelf, "z"); //Z position of caller.
    void img;
    clearspawnentry();
    setspawnentry("name", "Guy_3");
    img = spawn();
    changeentityproperty(img, "position", fX-100, fY, fZ-1);
    changeentityproperty(img, "parent", vSelf);
    changeentityproperty(img, "map", getentityproperty(vSelf, "map"));
    changeentityproperty(img, "direction", getentityproperty(vSelf, "direction"));
}
@end_script
	@cmd	setLevel
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
        frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif
	frame	data/chars/players/ryu/idle01.gif

Maybe should I change some value? I'm not sure which one.
I think it's clear that the NPC keeps "teleporting" to the starting point. But why? I don't understand.

EDIT: Ah, there is no respawn anim on ryu.txt
 
It looks like you forgot to give Guy a proper range in his idle. When an NPC has follow subtype and has a parent entity, the NPC is always checking the distance from its parent. If that distance exceeds the NPC'S idle animation range setting, the NPC instantly warps back to parent's location. It will play the RESPAWN animation if it has one.

IOW, if the NPC idle animation has a range 10 300, the NPC will try to stay within 10 horizontal pixels of the parent if it isn't busy doing something else (like chasing a hostile entity). The second it gets 301 or more pixels away, it warps to the parent instantly no matter what it was doing.

DC
 
Damon Caskey said:
It looks like you forgot to give Guy a proper range in his idle. When an NPC has follow subtype and has a parent entity, the NPC is always checking the distance from its parent. If that distance exceeds the NPC'S idle animation range setting, the NPC instantly warps back to parent's location. It will play the RESPAWN animation if it has one.

IOW, if the NPC idle animation has a range 10 300, the NPC will try to stay within 10 horizontal pixels of the parent if it isn't busy doing something else (like chasing a hostile entity). The second it gets 301 or more pixels away, it warps to the parent instantly no matter what it was doing.

DC

Holy shit. It worked!
Now is working fine, thx  ;D

One question, if I want to add more than one NPC, is necessary to copy the entire code? Or maybe I can just add one line? Like this:

clearspawnentry();
    setspawnentry("name", "Guy_3");
    setspawnentry("name", "Ken_3");
    setspawnentry("name", "Haggar_3");
    setspawnentry("name", "Guile_3");
    img = spawn();

(I will do some tests here to see)

EDIT: Important say that anim respawn is necessary. Because if don't add this anim, the char will play "spawn" animation after die... and this will create another NPC.
So "anim respawn" is necessary if you want play "spawn" animation just once. If don't, will create a NPC copy.
 
Try doing it like this:

Code:
clearspawnentry();
    setspawnentry("name", "Guy_3");
    img = spawn();

clearspawnentry();
    setspawnentry("name", "Ken_3");
    img = spawn();

clearspawnentry();
    setspawnentry("name", "Haggar_3");
    img = spawn();

clearspawnentry();
    setspawnentry("name", "Guile_3");
    img = spawn();

spawn() is the function doing the spawning (doh) so if you want to spawn more NPCs, you'd need to declare more of that function

One more thing, this line is for setting spawned NPC to follow a parent which is the spawner
Code:
    changeentityproperty(img, "parent", vSelf);

If you don't need the NPC to follow anyone, remove that line :)
 
Bloodbane said:
Try doing it like this:

Code:
clearspawnentry();
    setspawnentry("name", "Guy_3");
    img = spawn();

clearspawnentry();
    setspawnentry("name", "Ken_3");
    img = spawn();

clearspawnentry();
    setspawnentry("name", "Haggar_3");
    img = spawn();

clearspawnentry();
    setspawnentry("name", "Guile_3");
    img = spawn();

spawn() is the function doing the spawning (doh) so if you want to spawn more NPCs, you'd need to declare more of that function

One more thing, this line is for setting spawned NPC to follow a parent which is the spawner
Code:
    changeentityproperty(img, "parent", vSelf);

If you don't need the NPC to follow anyone, remove that line :)

Nice, it worked.  ;D
Tell me something.... can I do something like this?
If player got Guy (to play), dont load "Guy_3" (npc)
(That would be interesting to avoid copies, i mean, player and NPC using the same character)

So let's think that the players chose Ryu and Ken. And Ryu and Ken are scheduled to come as NPCs. But instead of Ryu and Ken, others will come (because the code checks if they already exist as players)

If it is not possible, no problem. It's just a detail I remembered trying to do to avoid copies haha

 
Bloodbane said:
If player got Guy (to play), dont load "Guy_3" (npc)
(That would be interesting to avoid copies, i mean, player and NPC using the same character)

That's possible but the script would be longer and more complex

No problem  ;D

And about using one key (like F1, F2, F3) to call NPCs, is something possible?
Oh, I forgot to say that I put NPC code on "anim special"
Yes, is something good because on "anim spawn" NPCs will always appear.... but on "anim special"  it remains as an option only.
The only problem is that doing this, the char ends up losing the special attack (of course, duh). That's why the idea of using a different key like F1 would still be interesting.
 
Well you can still use FREESPECIALs instead of SPECIAL and declare something like this to play each:
Code:
com A2 freespecial2
com A3 freespecial3
com A4 freespecial4

That means press attack2 to perform FREESPECIAL2, attack3 for FREESPECIAL3 and attack4 for FREESPECIAL4
Then in control configuration, set F1 for attack2, F2 for attack3 and F3 for attack4

HTH
 
Bloodbane said:
Well you can still use FREESPECIALs instead of SPECIAL and declare something like this to play each:
Code:
com A2 freespecial2
com A3 freespecial3
com A4 freespecial4

That means press attack2 to perform FREESPECIAL2, attack3 for FREESPECIAL3 and attack4 for FREESPECIAL4
Then in control configuration, set F1 for attack2, F2 for attack3 and F3 for attack4

HTH

Ow, that's a good option. Thanks  ;D
 
Hi, I put this script (Cody player) in three games: Super Final Fight Gold, Final Fight and Cadillacs (in this case as third npc Mustapha), Final Fight LNS Ultimate.
This system works only with Super Final Fight Gold while with other two games no. Why?

anim spawn
loop 0
offset 238 177
delay 3
        @script
        if(frame==1) 
        {
        void vSelf = getlocalvar("self"); //Calling entity.
        float fX = getentityproperty(vSelf, "x"); //X position of caller.
        float fY = getentityproperty(vSelf, "a"); //Y position of caller.
        float fZ = getentityproperty(vSelf, "z"); //Z position of caller.
        void img;
        clearspawnentry();
        setspawnentry("name", "guy_(A.I.)");
        img = spawn();
        clearspawnentry();
        setspawnentry("name", "haggar_(A.I.)");
        img = spawn();
        clearspawnentry();
        setspawnentry("name", "carlos_(A.I.)");
        img = spawn();
        changeentityproperty(img, "position", fX-100, fY, fZ-1);
        changeentityproperty(img, "parent", vSelf);   
        changeentityproperty(img, "map", getentityproperty(vSelf, "map"));
        changeentityproperty(img, "direction", getentityproperty(vSelf, "direction"));
        }
        @end_script
        @cmd setLevel
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
frame data/chars/players/cody/idle01.gif
 
Back
Top Bottom