GameMaker Studio Coding - Help!
10 years ago
Hello all! I'm working on learning gamemaker studio and would like to chat with anyone who has experience coding in it, most specifically looking for a grapple system, and I'm going to code it from scratch but if anyone had any code that might help I thought I would at least ask before re-inviting the wheel ;D So if you know someone or have some knowledge yourself and are able to help let me know, thanks!
Here is what I'm trying to do:
I'm doing this all in code, and trying to make it so when my player object and enemy object collide they both disappear and a new object with an animated sprite of the two grappling shows up in their place and remains there until the player hits a key to release, in which case the player sprite comes back and the enemy sprite is destroyed (the player loses HP but the struggling kills the enemy, when player collides with enemies enough times the game is over).
I have had someone suggest in passing that I should create a grapple object and give it the ID of both the player and enemy object for tracking. I don't understand that suggestion so if someone could explain that would be awesome, OR if you have your own way to code this particular issue please let me know :D
So far I have it in the players step that if the [player and enemy collide it does a instance_change(obj_grapple,1) and while this makes my player object disappear the enemy keeps walking along as if nothing happened.
Here is what I'm trying to do:
I'm doing this all in code, and trying to make it so when my player object and enemy object collide they both disappear and a new object with an animated sprite of the two grappling shows up in their place and remains there until the player hits a key to release, in which case the player sprite comes back and the enemy sprite is destroyed (the player loses HP but the struggling kills the enemy, when player collides with enemies enough times the game is over).
I have had someone suggest in passing that I should create a grapple object and give it the ID of both the player and enemy object for tracking. I don't understand that suggestion so if someone could explain that would be awesome, OR if you have your own way to code this particular issue please let me know :D
So far I have it in the players step that if the [player and enemy collide it does a instance_change(obj_grapple,1) and while this makes my player object disappear the enemy keeps walking along as if nothing happened.
FA+

As for your problem, I don't know what can be done from reading a single line of code. I'd need to at least see the whole object definitions for both. If you send me the project, I can look over it more closely and try to fix it.
At the start of the grapple, make it invisible and not moving.
Then switch the player to the grapple state, depending on the monster that grappled him.
After that, start testing if the grapple is broken (or the player took his last hit).
If the grapple breaks, reactive the monster and make it visible. Set the player to its normal sprite, and make him invisible enough time to move out of the way. You can also knock the monster back with the grapple is broken as well.
Just spit balling an idea.
-When the enemy does a certain animation (like a lunging bite), the part of the code where it normally checks for player collision to deal damage instead initiates the grapple mode if it detects collision.
-My player and enemy objects work with some fairly simple state machines (ie. enemy state=0 contains its idle behaviors, and if it 'sees' the player it goes to state=1 where it chases them down and goes to state=2 if conditions are right to do an attack. Player states mostly determine what inputs you're able to do and how the player sprite is rendered, etc) so initiating grapple mode is as simple as changing the state variable for both enemy and player.
-In the grapple state, the player is invisible and immobile, and they're also invulnerable to damage. This way I can make sure they can't get grappled by another enemy at the same time, or attacked while grappled. The enemy will deal X damage every Y steps directly, bypassing the player's invulnerability. In this state, they will play an animation containing all the grapple-y goodness with both characters.
-There's a struggle variable set up when grapple initiates, which depletes slowly over time. Pressing any direction buttons adds a certain amount to the variable, and once it passes a set threshold, the player is released (back to normal state), enemy goes back to idle or chase state, and.. yeah.
This kind of system can be expanded in a lot of different ways. You can have multiple grapple states where the player is pulled further into the enemy's embrace if the struggle bar gets too low. You can have animations for the player losing the last of their health and succumbing to the enemy's will. You could give the player a way to willingly submit, and have a different outcome based on that.
The way I handled the code, I think most of the state machine stuff was in the "step" function. I'd write a script that had a little explanation of the state machine at the top followed by the code for it. Something like this:
//*
state = 0 - idle
status = 0 - standing animation
status = 1 - walking around
state = 1 - chase
status = 0 - run in direction of player
*//
if (state==0) //idle
{
if (status==0) //stand
{
}
if (status==1) //walk
{
}
}
else if (state==1) //chase
{
if (status==0) //run at player
{
}
}
Of course, it's going to be more complex than that based on your needs, but I hope that gives you a general idea.