SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/03/2018, 08:24 PM   #1
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Question Walk/Run style system

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:
Code:
 
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!

Last edited by Maxandmov; 20/03/2018 at 08:24 PM. Reason: Forgot some things
Maxandmov is offline   Reply With Quote
Old 20/03/2018, 08:28 PM   #2
PowerMwK
Big Clucker
 
PowerMwK's Avatar
 
Join Date: Sep 2016
Location: Brazil - Ba
Posts: 143
Reputation: 4
Default Re: Walk/Run style system

PHP Code:
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
        
}

__________________
Você acha que é melhor que todos, mas sinto em lhe informar. Você depende da opinião dos outros para construir sua identidade.
PowerMwK is online now   Reply With Quote
Old 20/03/2018, 08:33 PM   #3
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Default Re: Walk/Run style system

Quote:
Originally Posted by PowerMwK View Post
PHP Code:
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?
Maxandmov is offline   Reply With Quote
Old 20/03/2018, 08:35 PM   #4
PowerMwK
Big Clucker
 
PowerMwK's Avatar
 
Join Date: Sep 2016
Location: Brazil - Ba
Posts: 143
Reputation: 4
Default Re: Walk/Run style system

http://wiki.sa-mp.com/wiki/GetPlayerAnimationIndex

http://wiki.sa-mp.com/wiki/GetAnimationName
__________________
Você acha que é melhor que todos, mas sinto em lhe informar. Você depende da opinião dos outros para construir sua identidade.
PowerMwK is online now   Reply With Quote
Old 20/03/2018, 08:40 PM   #5
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Default Re: Walk/Run style system

@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?
Maxandmov is offline   Reply With Quote
Old 21/03/2018, 08:31 PM   #6
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Default Re: Walk/Run style system

BUMP.
Any useful hints there, please? I'm in a pickle.
Maxandmov is offline   Reply With Quote
Old 21/03/2018, 08:36 PM   #7
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Posts: 1,686
Reputation: 168
Default Re: Walk/Run style system

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.
__________________
Ritzy2K is offline   Reply With Quote
Old 22/03/2018, 06:07 AM   #8
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Default Re: Walk/Run style system

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:

Code:
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. :/
Maxandmov is offline   Reply With Quote
Old 23/03/2018, 06:17 AM   #9
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Default Re: Walk/Run style system

Bump again.
Still nobody who can lend me a hand?
Maxandmov is offline   Reply With Quote
Old 24/03/2018, 04:46 PM   #10
Maxandmov
Big Clucker
 
Maxandmov's Avatar
 
Join Date: Feb 2011
Location: Moscow, Russia.
Posts: 153
Reputation: 11
Default Re: Walk/Run style system

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Player Walk Style mahardika Tutorials 17 30/05/2015 10:52 AM
GM Walk Style **Help**[+Rep] [E]ViL [D]RaGoN™ Scripting Help 3 18/12/2012 12:39 PM
Walk Style McCurdy Scripting Help 5 23/07/2012 09:30 AM
Walk style problem N0FeaR Scripting Help 2 15/05/2012 06:26 PM
changing walk and run style marwan Help Archive 1 12/06/2011 11:06 AM


All times are GMT. The time now is 11:17 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.