Entity Event level scripting works but not when placed into a '.c' file

What I'm trying to do:

When a player or enemy animation plays, it will cause an item to drop (ex: player dies and drops money).

The following code works fine at the Entity Event level (ie: when I stick it into the <char>.txt file):
Code credit goes to:
//spawn01 (Generic spawner)
//Damon Vaughn Caskey

@script
if(frame == 1){
void self = getlocalvar("self"); //Get calling entity.
void vSpawn; //Spawn object.
int iDirection = getentityproperty(self, "direction");
int fX = 0;
int fY = 0;
int fZ = 0;

clearspawnentry(); //Clear current spawn entry.
setspawnentry("name", "Money"); //Acquire spawn entity by name.

if (iDirection == 0){ //Is entity facing left?
fX = -fX; //Reverse X direction to match facing.
}

fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.

vSpawn = spawn(); //Spawn in entity.

changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
//return vSpawn; //only works if I comment this out, I assume this isn't a function so there is nothing to return.

}
@end_script

Conversely, if I try to simply use the spawn.h file (taken from Street Fighter 86) and apply the following:

spawn.h (which contains, among other functions):

void spawn01(void vName, float fX, float fY, float fZ)
{
//spawn01 (Generic spawner)
//Damon Vaughn Caskey
//07/06/2007
//
//Spawns entity next to caller.
//
//vName: Model name of entity to be spawned in.
//fX: X location adjustment.
//fY: Y location adjustment.
//fZ: Z location adjustment.

void self = getlocalvar("self"); //Get calling entity.
void vSpawn; //Spawn object.
int iDirection = getentityproperty(self, "direction");

clearspawnentry(); //Clear current spawn entry.
setspawnentry("name", vName); //Acquire spawn entity by name.

if (iDirection == 0){ //Is entity facing left?
fX = -fX; //Reverse X direction to match facing.
}

fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.

vSpawn = spawn(); //Spawn in entity.

changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
changeentityproperty(vSpawn, "direction", iDirection); //Set direction.

return vSpawn; //Return spawn.
}

I create a spawn.c (which contains):

#import "data/scripts/library/spawn.h"

I then add the following to my <char>.txt file header:

animationscript data/scripts/spawn.c

and I make the call under one of my animations:

anim freespecial2
...
@cmd spawn01 "Money" 0 0 0
...

But it doesn't work - as in the "Money" item does not appear. Whereas if I imbed the code into the char.txt, it works fine.

Can someone enlighten me please?

Thank you
 
@Bloodbane thanks for the hint - that is exactly where the problem was.

This works:
anim freespecial2
loop 0
delay 120

offset 30 93
bbox.position.x 10
bbox.position.y 0
bbox.size.x 37
bbox.size.y 92

frame data/chars/hero/taunt00.png
frame data/chars/hero/taunt01.png

@cmd spawn01 "Money" 0 0 0 #Spawn must happen before the last frame.

frame data/chars/hero/taunt02.png

This is the mistake:
anim freespecial2
loop 0
delay 120

offset 30 93
bbox.position.x 10
bbox.position.y 0
bbox.size.x 37
bbox.size.y 92

frame data/chars/hero/taunt00.png
frame data/chars/hero/taunt01.png

frame data/chars/hero/taunt02.png

@cmd spawn01 "Money" 0 0 0 # this won't work and produces no errors in the OpenBOR.log
 
Back
Top Bottom