Solved Play an animation when Player get an Item

Question that is answered or resolved.

Crimsondeath

Active member
There is a way for the player do an animation or freespecial when he pick up an specific item (a point item maybe)? Is all that I need for finish my Openbor project.

I speak spanish as a native languaje but there's no spanish comunity for asking help :(

Thanks anyway.
 
Solution
you can use didhitscript on item.txt
example:
use in item.txt
hostile player
didhitscript    data/chars/item/hitanim.c

in hitanim.c write:
void main()
{
void self = getlocalvar("self");
  void plr = getentityproperty(self, "opponent");


if (plr != NULL())
{
performattack(plr, openborconstant("ANI_FOLLOW1"));
}
}

save it has hitanim.c
you can change in the script "ANI_FOLLOW1" to 2,3 FREESPECIAL etc...
you can use didhitscript on item.txt
example:
use in item.txt
hostile player
didhitscript    data/chars/item/hitanim.c

in hitanim.c write:
void main()
{
void self = getlocalvar("self");
  void plr = getentityproperty(self, "opponent");


if (plr != NULL())
{
performattack(plr, openborconstant("ANI_FOLLOW1"));
}
}

save it has hitanim.c
you can change in the script "ANI_FOLLOW1" to 2,3 FREESPECIAL etc...
 
Solution
I've got a similar question, i know this topic is old but i wouldn't like to open a new one.

Is there a way to spawn a text entity after picking an item? It could result pretty handy to display text or images if so
 
As posted above, you need to give the item didhitscript with command like didhitscript data/scripts/item.c

To spawn something, you can use this:
item.c
Code:
void main()
{//Script to spawn apples
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int  x = getentityproperty(target, "x");
    int  z = getentityproperty(target, "z");

    spawn01("Apple",x,10,z);
    spawn01("Apple",x-50,10,z);
    spawn01("Apple",x+50,10,z);
    spawn01("Apple",x,10,z-10);
    spawn01("Apple",x,10,z+10);
}

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
	//fY: Y location
      //fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

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

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

When the item is picked up, 5 apples will be spawned near player who picked the item.

That's just an example, you can remove or add spawn lines to control number of spawns. And also you can change name of to be spawned item.
 
Code:
void main()
{//Script to spawn apples
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int  x = getentityproperty(target, "x");
    int  z = getentityproperty(target, "z");

    spawn01("Apple",x,10,z);
    spawn01("Apple",x-50,10,z);
    spawn01("Apple",x+50,10,z);
    spawn01("Apple",x,10,z-10);
    spawn01("Apple",x,10,z+10);
}

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
	//fY: Y location
      //fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

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

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

What values do i need to replace besides "Apple"??
I have never used scripts and it's really intimidating because i really don't know what does all that text represents or means
 
Alright, first of all, you can leave spawn01 function below :)

Second, one spawn01 function spawns one entity. So with 5 spawn01 functions in example above, there are 5 spawns.

As for modifiable values, see this quote:
    spawn01("Apple",x,10,z);
    spawn01("Apple",x-50,10,z);
    spawn01("Apple",x+50,10,z);
    spawn01("Apple",x,10,z-10);
    spawn01("Apple",x,10,z+10);

3rd parameter i.e 10 defines how high entity is spawned from ground IOW it's spawned 10 pixels from gorund.
x and z must be there however you can modify how far entity is spawned from picker. -50 means entity is 50 pixels to the left, +50 to the right.
-10 means entity is 10 pixels behind while +10 to front.

HTH
 
I assumed those were coordinates. What i meant was, what does all this text means? I really don't understand any of it. I may do a lot of questions but i just want to understand what am i dealing with, its specific functions on some lines, what it is or what does it do. Kinda like a breakdown.

I'd like to know what values do i need to replace or add if required, like entity names and so on. I'm sorry for not making myself clear.


Code:
void main()
{//Script to spawn apples
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int  x = getentityproperty(target, "x");
    int  z = getentityproperty(target, "z");







}

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
	//fY: Y location
      //fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

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

	changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.  
}
 
Hmmm.... I believe you should try implementing this didhitscript to one of your item and try getting it :).

You can start with simpler form like this:
item.c
Code:
void main()
{//Script to spawn apples
    void self = getlocalvar("self");
    void target = getlocalvar("damagetaker"); // Get player who picks the item
    int  x = getentityproperty(target, "x");
    int  z = getentityproperty(target, "z");

    spawn01("Apple",x,10,z);
}

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
	//fY: Y location
      //fZ: Z location

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.

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

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

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

Try it and see what happens.
 
What's your situation? please show your item text here and any script it's using.
C:
name    1up
health    0
type    item
shadow    0
icon    data/chars/misc/cakeicon.gif



animationscript data/chars/item/hitanim.c

anim idle
    loop    0
    delay    1000
    offset    11 18
    bbox    0 0 22 18
    frame    data/chars/misc/cake.gif

C:
void main()
{
void self = getlocalvar("self");
  void plr = getentityproperty(self, "opponent");


if (plr != NULL())
{
performattack(plr, openborconstant("ANI_FOLLOW1"));
}
}

C:
anim    follow1
    sound    data/sounds/haggar_special.wav
    offset    89 107
    delay    10
    frame    data/chars/players/haggar/sp10.gif
    offset    89 116
    delay    800
    frame    data/chars/players/haggar/sp11.gif

I tried also with didhitscript but nothing.
 
I've tried this myself and it works.
My settings are this:
Code:
name        Itack
health       1
type        item
gfxshadow       1
didhitscript    data/scripts/didhit/itAttack.c


anim    idle
    delay    10
    offset    9 13
    bbox    0 0 17 13
    frame    data/chars/misc/items/gold.png

It's just an item with random name and sprite BTW. I'm using didhitscript there which is the important part.

itAttack.c
C:
void main(){
    void target = getlocalvar("damagetaker"); // Get player who picks the item

    if(target){
      performattack(target, openborconstant("ANI_FOLLOW1"));
    }
}

Try using didhitscript like my example above.
 
I've tried this myself and it works.
My settings are this:
Code:
name        Itack
health       1
type        item
gfxshadow       1
didhitscript    data/scripts/didhit/itAttack.c


anim    idle
    delay    10
    offset    9 13
    bbox    0 0 17 13
    frame    data/chars/misc/items/gold.png

It's just an item with random name and sprite BTW. I'm using didhitscript there which is the important part.

itAttack.c
C:
void main(){
    void target = getlocalvar("damagetaker"); // Get player who picks the item

    if(target){
      performattack(target, openborconstant("ANI_FOLLOW1"));
    }
}

Try using didhitscript like my example above.
Thank you very much. It works :)
 
Back
Top Bottom