Page 1 of 2
stick man sword
Posted:
Wed Oct 05, 2011 9:50 pm
by praaab
ok well ive said this before and ill say it again, i got a guy with a sword and i want were if he uses the sword on another enemy then it would hurt the enemy or kill hi, this guy gave me this code to help me but my friend and i didn't understand one bit of it her it is...
- Code: Select all
if(collide.animindex==0||collide.animindex==1)
{
//0 being the animindex of the attack animation right, 1 left
hp-=1;
//hp is an actor variable
if(hp<=0)DIE;
}
Re: stick man sword
Posted:
Wed Oct 05, 2011 10:42 pm
by foleyjo
I'll try to explain it
From reading it this is in the enemies collision event and is on a collision with the player
- Code: Select all
if(collide.animindex==0||collide.animindex==1)
= The collide actor in this case is the player/sword
if it is on animation 0 or 1 then we do the event (|| means or)
- Code: Select all
hp-=1;
deduct 1 from hp(energy) hp-=1 is the same as hp = hp -1
- Code: Select all
if(hp<=0)DIE;
when the hp gets to 0 the actor will perform whatever function DIE is.
Re: stick man sword
Posted:
Sun Oct 09, 2011 6:23 pm
by praaab
yes but when i plug this code in then the enemy dies right when he collides into me not when i use the anime of attacking
Re: stick man sword
Posted:
Sun Oct 09, 2011 9:21 pm
by skydereign
That means that your attack animations are not animations 0 and 1, or the wrong actor is the event actor, and therefore you need to remove the collide.
Re: stick man sword
Posted:
Mon Oct 10, 2011 12:53 am
by praaab
im so confused right now because i tried it on everything and its still colliding with the player and dying even though im not attacking
Re: stick man sword
Posted:
Mon Oct 10, 2011 1:03 am
by skydereign
What is your animation order for the player? For instance:
stand_right
stand_left
run_right
run_left
attack_right
attack_left
The order I'm talking about is when you go to look at the actor's animations.
Re: stick man sword
Posted:
Mon Oct 10, 2011 1:17 am
by praaab
heres his animations:
stick man standing left
stick man standing right
stick man jumping left
stick man jumping right
stick man attacking left 01
stick man attacking right 01
Re: stick man sword
Posted:
Mon Oct 10, 2011 1:54 am
by skydereign
Yeah, so the attacking animations are when animindex is 4 and 5. That means the code should use (collide.animindex==4 || collide.animindex==5).
Re: stick man sword
Posted:
Mon Oct 10, 2011 2:09 am
by praaab
oh wait sorry i did it wrong the order is this:
stick man moving right 01
stick man moving left 01
stick man standing right
stick man standing left
stick man jumping left
stick man jumping right
stick man attacking right 01
stick man defend right
stick man defend left
stick man attacking left 01
Re: stick man sword
Posted:
Mon Oct 10, 2011 3:37 am
by skydereign
Ok, well same principle. The first animation is animindex==0, and it goes up from there. So, you want 6 and 9, instead of 4 and 5.
Re: stick man sword
Posted:
Mon Oct 10, 2011 8:17 pm
by praaab
its still the same thing, when i collide into the enemy he dies even though im just standing. the code is placed in enemy>collide repeat>script editor and this is the code that i put it in:
- Code: Select all
if(collide.animindex==6||collide.animindex==9)
{
//6 being the animindex of the attack animation right, 9 left
hp-=1;
//hp is an actor variable
if(hp<=0)DIE;
}
Re: stick man sword
Posted:
Mon Oct 10, 2011 9:05 pm
by skydereign
Are you sure that is the only collision event? As that code will only activate when the colliding actor (the player) has the 6th or the 9th animation. You could put an collide.r=0; inside the if statement to see if it is that event that causes the enemy to die. If it is, the player should change color.
Re: stick man sword
Posted:
Mon Oct 10, 2011 10:24 pm
by praaab
wow yea there was an event that was messing it up, thanks a lot heres a point.
Re: stick man sword
Posted:
Mon Oct 10, 2011 10:29 pm
by praaab
i got one more question, theres an animation of stick man defending and i want were he wont get hit, 50% chance of him getting hurt if he got hit by an enemy, how do i do that.
Re: stick man sword
Posted:
Tue Oct 11, 2011 1:09 am
by skydereign
I am going to assume you mean 50% chance of getting hit, and 50% chance of blocking.
- Code: Select all
if((collide.animpos==7 || collide.animpos==8) && ((int)rand(2)==0))
{
hit();
}
The if requires collide.animpos to either be 7 or 8 (both are the defending of the player), and the (int)rand(2) returns a 0 or 1. Of course if you set this collision to repeat, then you'll need to add an attack variable (0 when not attacking, and set to 1 at the beginning of the attack) otherwise 50% chance given 30 times a second, will pretty much guarantee a hit.