Advertisement
Guest User

walk.inc by willie

a guest
Jan 4th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.26 KB | None | 0 0
  1. /*
  2.  * Walk
  3.  * Author: Willie (Wojciech Drzymała)
  4.  * Version: 1.0
  5.  * Copyright (c) 2016
  6.  *
  7. native TogglePlayerWalking(playerid, bool:toggle);
  8. native IsPlayerWalking(playerid);
  9.  */
  10.  
  11. #if defined _walk_included
  12.     #endinput
  13. #endif
  14. #define _walk_included Oh, Yiss!
  15.  
  16. /*
  17.  * _walk PVar modes:
  18.  * 0 = player is not being forced to walk
  19.  * 1 = player is being forced to walk
  20.  * 2 = player walking animation is turned on
  21.  * 3 = player walking mode is suspended
  22.  * 4 = player is going to the vehicle
  23.  */
  24.  
  25. stock TogglePlayerWalking(playerid, bool:toggle)
  26. {
  27.     if(!IsPlayerConnected(playerid)) return;
  28.     if(toggle)
  29.     {
  30.         if(IsPlayerInAnyVehicle(playerid)) SetPVarInt(playerid, "_walk", 3);
  31.         else SetPVarInt(playerid, "_walk", 1);
  32.     }
  33.     else DeletePVar(playerid, "_walk");
  34. }
  35.  
  36. #if defined IsPlayerWalking
  37.     #undef IsPlayerWalking
  38. #endif
  39. #define IsPlayerWalking(%0) GetPVarInt(%0,"_walk")
  40.  
  41. public OnPlayerUpdate(playerid)
  42. {
  43.     new w = GetPVarInt(playerid, "_walk");
  44.     if(!w) { if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid); else return 1; }
  45.     if(w==1 || w==2)
  46.     {
  47.         if(IsPlayerInAnyVehicle(playerid))
  48.         {
  49.             ClearAnimations(playerid);
  50.             SetPVarInt(playerid, "_walk", 3);
  51.             if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid); else return 1;
  52.         }
  53.  
  54.         new k, ud, lr;
  55.         GetPlayerKeys(playerid, k, ud, lr);
  56.  
  57.         if(k & KEY_SECONDARY_ATTACK)
  58.         {
  59.             new Float:p[3];
  60.             for(new x; x != MAX_VEHICLES; x++)
  61.             {
  62.                 GetVehiclePos(x, p[0], p[1], p[2]);
  63.                 if(IsPlayerInRangeOfPoint(playerid, 5.0, p[0], p[1], p[2]))
  64.                 {
  65.                     SetPVarFloat(playerid, "_walk4MODEx", p[0]);
  66.                     SetPVarFloat(playerid, "_walk4MODEy", p[1]);
  67.                     SetPVarFloat(playerid, "_walk4MODEz", p[2]);
  68.                     SetPVarInt(playerid, "_walk", 4);
  69.                     SetTimerEx("_walkReturn", 5000, 0, "i", playerid);
  70.                     if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid); else return 1;
  71.                 }
  72.             }
  73.         }
  74.  
  75.         if(ud || (lr && !ud))
  76.         {
  77.             if(w==1)
  78.             {
  79.                 ClearAnimations(playerid);
  80.                 ApplyAnimation(playerid, "ped", "null", 1.0, 1, 1, 1, 0, 0);
  81.                 ApplyAnimation(playerid, "ped", "WALK_player", 2.0, 1, 1, 1, 0, 0);
  82.                 SetPVarInt(playerid, "_walk", 2);
  83.             }
  84.         }
  85.         else
  86.         {
  87.             ClearAnimations(playerid);
  88.             SetPVarInt(playerid, "_walk", 1);
  89.             if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid); else return 1;
  90.         }
  91.  
  92.         new Float:fa;
  93.         GetPlayerFacingAngle(playerid, fa);
  94.         if((lr<0)&&(ud!=0)) SetPlayerFacingAngle(playerid, fa+5);
  95.         else if((lr>0)&&(ud!=0)) SetPlayerFacingAngle(playerid, fa-5);
  96.         else if((lr<0)&&(!ud)) SetPlayerFacingAngle(playerid, fa+13);
  97.         else if((lr>0)&&(!ud)) SetPlayerFacingAngle(playerid, fa-13);
  98.     }
  99.     if(w==3)
  100.     {
  101.         if(IsPlayerInAnyVehicle(playerid)) { if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid); else return 1; }
  102.         SetPVarInt(playerid, "_walk", 1);      
  103.     }
  104.     if(w==4)
  105.     {
  106.         if(IsPlayerInAnyVehicle(playerid))
  107.         {
  108.             SetPVarInt(playerid, "_walk", 3);
  109.             if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid); else return 1;
  110.         }
  111.  
  112.         new Float:p[3];
  113.         p[0] = GetPVarFloat(playerid, "_walk4MODEx");
  114.         p[1] = GetPVarFloat(playerid, "_walk4MODEy");
  115.         p[2] = GetPVarFloat(playerid, "_walk4MODEz");
  116.         if(!IsPlayerInRangeOfPoint(playerid, 5.0, p[0], p[1], p[2]))
  117.         {
  118.             SetPVarInt(playerid, "_walk", 1);
  119.             DeletePVar(playerid, "_walk4MODEx");
  120.             DeletePVar(playerid, "_walk4MODEy");
  121.             DeletePVar(playerid, "_walk4MODEz");
  122.         }
  123.     }
  124.  
  125.     if(funcidx("_alt_OnPlayerUpdate") != -1) return CallLocalFunction("_alt_OnPlayerUpdate", "i", playerid);
  126.     else return 1;
  127. }
  128.  
  129. #if defined _ALS_OnPlayerUpdate
  130.     #undef OnPlayerUpdate
  131. #else
  132.     #define _ALS_OnPlayerUpdate
  133. #endif
  134. #define OnPlayerUpdate _alt_OnPlayerUpdate
  135. forward _alt_OnPlayerUpdate(playerid);
  136.  
  137. forward _walkReturn(playerid);
  138. public _walkReturn(playerid)
  139. {
  140.     if(!GetPVarInt(playerid, "_walk")) return;
  141.     if(IsPlayerInAnyVehicle(playerid)) SetPVarInt(playerid, "_walk", 3);
  142.     else SetPVarInt(playerid, "_walk", 1);
  143.     DeletePVar(playerid, "_walk4MODEx");
  144.     DeletePVar(playerid, "_walk4MODEy");
  145.     DeletePVar(playerid, "_walk4MODEz");
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement