Walk/Run style system
#1

Hi there, fellas!
I've been working on something lately...
...Yeah, seems like SAMP won't just let me go, I guess...

Anyways, back to the topic.
I'm doing this system in OnPlayerUpdate since I need to detect any movement (for running especially) and not just holding a key.

Here's some portion of the code in use:
Код:
 
new keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
//First, walking system
if ((keys & KEY_WALK) && (ud & KEY_UP || ud & KEY_DOWN || lr & KEY_LEFT || lr & KEY_RIGHT) && !(keys & KEY_JUMP) && !(keys & KEY_SPRINT) && !(keys & KEY_AIM) && (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT))
{
     if(runtime[playerid] != 0) { KillTimer(runtime[playerid]); } //I reset the timer for running so I don't have running animation applied.
     walktime[playerid] = SetTimerEx("WalkAnim",200,0,"d",playerid); //And set walktime timer
}
//Then, running system.
if((ud & KEY_UP || ud & KEY_DOWN || lr & KEY_LEFT || lr & KEY_RIGHT) && !(keys & KEY_SPRINT) && !(keys & KEY_WALK) && !(keys & KEY_AIM) && !(keys & KEY_JUMP) && (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT))
{
     if(walktime[playerid] != 0) { KillTimer(walktime[playerid]); } //Just like walking, but vice versa.
     runtime[playerid] = SetTimerEx("RunAnim", 200,0,"d",playerid);
}
And here's some issues and precautions I'd love to consider:
1. I need to make sure it doesn't apply animation when I'm mid air. Am I right to assume ColAndreas will do the trick?
2. Tap sprinting and alike features don't work properly. This includes: Fighting while running or walking, sprinting, jumping (if not fixable as I desire via ColAndreas right at the moment of the jump, if I may). Is there some kind of a timer I can apply properly here to deal with these tap requirements without breaking the animation system?

Thanks for any assistance you can provide!
Reply
#2

PHP код:
if(GetPlayerAnimationIndex(playerid))
    {
        new 
animlib[32];
        new 
animname[32];
        new 
msg[128];
        
GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
        if(!
strcmp(animname"WALK_DRUNK"true)) {
          
// the player is with walk drunk animation
        
}

Reply
#3

Quote:
Originally Posted by PowerMwK
Посмотреть сообщение
PHP код:
if(GetPlayerAnimationIndex(playerid))
    {
        new 
animlib[32];
        new 
animname[32];
        new 
msg[128];
        
GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
        if(!
strcmp(animname"WALK_DRUNK"true)) {
          
// the player is with walk drunk animation
        
}

How does this help me?
Reply
#4

https://sampwiki.blast.hk/wiki/GetPlayerAnimationIndex

https://sampwiki.blast.hk/wiki/GetAnimationName
Reply
#5

@PowerMwK, how do I apply this code in this particular situation to be able to tap sprint, hit and jump properly without this system not messing up the animations?
Reply
#6

BUMP.
Any useful hints there, please? I'm in a pickle.
Reply
#7

If a player is in the middle of air he will be either falling, or skydiving or parachuting. You can make sure to check for specific anim indexes to make sure they aren’t mid air. I’m not too sure about the falling anim index but I have the skydiving and parachuting one in a little include I did a while ago, check my github from signature. My approach can obviously be wrong but I’m still brainstorming to make it as simple as possible.
Reply
#8

Well, mid-air check I've done via ColAndreas, and it might not be as accurate as I wanted, but it's good nevertheless. In case you still need it, I've done it like that:

Код:
CA_IsPlayerOnSurface(playerid, 1.01)
Tolerance is set to 1.01 since 1.00 is exact distance between the player and the floor he's standing on, meaning the ray doesn't detect standing on ground properly.

But what about tap sprinting and fighting? I can't force players to hold RMB to fight and sprint, that's not right. :/
Reply
#9

Bump again.
Still nobody who can lend me a hand?
Reply
#10

Bumpity-bump.
Still looking into that issue. Anyone?
Logic_, give me a hand, lad!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)