stick man sword

Non-platform specific questions.

stick man sword

Postby praaab » Wed Oct 05, 2011 9:50 pm

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;
}
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby foleyjo » Wed Oct 05, 2011 10:42 pm

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.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: stick man sword

Postby praaab » Sun Oct 09, 2011 6:23 pm

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
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Sun Oct 09, 2011 9:21 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stick man sword

Postby praaab » Mon Oct 10, 2011 12:53 am

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
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Mon Oct 10, 2011 1:03 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stick man sword

Postby praaab » Mon Oct 10, 2011 1:17 am

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
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Mon Oct 10, 2011 1:54 am

Yeah, so the attacking animations are when animindex is 4 and 5. That means the code should use (collide.animindex==4 || collide.animindex==5).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stick man sword

Postby praaab » Mon Oct 10, 2011 2:09 am

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
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Mon Oct 10, 2011 3:37 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stick man sword

Postby praaab » Mon Oct 10, 2011 8:17 pm

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;
}
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Mon Oct 10, 2011 9:05 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stick man sword

Postby praaab » Mon Oct 10, 2011 10:24 pm

wow yea there was an event that was messing it up, thanks a lot heres a point.
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby praaab » Mon Oct 10, 2011 10:29 pm

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.
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Tue Oct 11, 2011 1:09 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest