stick man sword

Non-platform specific questions.

Re: stick man sword

Postby praaab » Tue Oct 11, 2011 7:09 pm

well when i set the variable: hit and try to press add imediate action then it will say error incorrect function usage: hit. Im not understanding why its an incorrect fuction
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 8:24 pm

Well, is hit a variable or a function? I can't do much without seeing your game. But you might try changing the variable name to something else.
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 » Tue Oct 11, 2011 8:31 pm

Well wil hp-=1 work?
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 8:58 pm

Oh, I get what you are doing. The hit(); should be replaced with your code. So, the hp-=1 bit. I thought you were talking about the attack variable that you need when using repeat collision.
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 » Wed Oct 12, 2011 12:58 am

No, let me repeat myself more clearly. When the enemy tries to hit me, i want to be able to bloc but right now im making the shield crappy and the blocking only works 50% of the time but u can block wenever u want it will just be half chance of getting hurt
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Wed Oct 12, 2011 1:11 am

I know, and the explanations I have given are doing just that. The only problem is that if your game is going 30fps, and your enemies attack animation lasts for longer than 1/30th of a second, then if you set the collision event to repeat, then the enemy will pretty much be guaranteed to hit the player. For instance, if the attack only lasted one second, and your game runs at 30fps, then they have 30 attempts at hitting the player with a 50-50 chance. That means the chances of not getting hit are 1/1,073,741,824. I'm pretty sure that isn't what you meant by 50% chance of blocking. Therefore you need to limit the number of attempts to 1. You can do this by adding a variable that holds how many attempts are allowed, and whether the attempt succeeded or not, lower it.

So when the enemy attacks, set the variable to 1. When it collides with the player, check if it is greater than zero, and if so, try to hit the player. Regardless of the actual attack's result, lower the variable by 1 (normally to zero).
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 » Wed Oct 12, 2011 1:46 am

Alright well im reading a book about c++ and im very new to it and so im trying learn it and. Im not understanding how u would implement this piece of code in and how would i know if my game is running at 30fps
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Wed Oct 12, 2011 3:23 am

If you don't know what fps your game is running, chances are high it is at 30 frames per second. You can change it by going to [Config] -> [Game Properties], and changing the frame rate.

Anyway, here's generally how you wold use it. Create an actor variable named attacking. Note though, if the player doesn't have an attacking, then you'll need to do it slightly differently where the variable is set to 1 on the collision.

enemy -> whatever event that causes it to attack (where the ChangeAnimation to the attack animation is) -> Script Editor
Code: Select all
// presumably there are is at least a ChangeAnimation event here
attacking=1;


enemy -> Collision with player (repeat enabled) -> Script Editor
Code: Select all
if(attacking==1 && (collide.animpos==7 || collide.animpos==8) && ((int)rand(2)==0))
{
    hp-=1;
    // and other code
}
attacking=0;
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 » Wed Oct 12, 2011 8:46 pm

this is becoming very frustrating, when i try to click ok after i right the code down i have two errors: 1: on line
1: Illegal structure operation
2: syntax error associated near '&&'
im so confused.
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Wed Oct 12, 2011 9:03 pm

Sounds like you didn't upload your variables. Clearly this isn't working out, so can you upload your enemy and player animations, and I'll a ged with the code?
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 » Wed Oct 12, 2011 9:29 pm

well the problem is that i cant upload my game because it's over 2MB
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: stick man sword

Postby skydereign » Wed Oct 12, 2011 9:41 pm

Can you upload it to a file hosting site? If so, you can pm me the link. Though all I need for the example are those images.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest