Advertisement
Guest User

GrappleHook Filterscript for SA-MP by RyDeR`

a guest
Jul 3rd, 2011
3,952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.75 KB | None | 0 0
  1. /*
  2.     Name:       Grapple Hook Filterscript v0.1
  3.     Author:     RyDeR`
  4. */
  5.  
  6. #include <a_samp>
  7.  
  8. #if !defined MAX_GRAPPLE_DISTANCE
  9.     #define MAX_GRAPPLE_DISTANCE \
  10.         (150.0)
  11. #endif
  12.  
  13. #if !defined GRAPPLE_CROSS_INTERVAL
  14.     #define GRAPPLE_CROSS_INTERVAL \
  15.         (0.25)
  16. #endif
  17.  
  18. #if !defined PLAYER_MOVE_SPEED
  19.     #define PLAYER_MOVE_SPEED \
  20.         (20.0)
  21. #endif
  22.  
  23. native MapAndreas_Init(mode);
  24. native MapAndreas_FindZ_For2DCoord(Float: x, Float: y, &Float: z);
  25.  
  26. public OnFilterScriptInit()
  27. {
  28.     MapAndreas_Init(2);
  29.    
  30.     print(" \n » GrappleHook [v0.1] (by RyDeR`) has been loaded. \n ");
  31.     return 1;
  32. }
  33.  
  34. public OnFilterScriptExit()
  35. {
  36.     print(" \n » GrappleHook [v0.1] (by RyDeR`) has been unloaded. \n ");
  37.     return 1;
  38. }
  39.  
  40. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  41. {
  42.     #define KEY_AIMFIRE (132)
  43.    
  44.     if(newkeys & KEY_AIMFIRE == KEY_AIMFIRE && oldkeys & KEY_AIMFIRE != KEY_AIMFIRE)
  45.     {
  46.         if(GetPVarInt(playerid, "pv_GrappleEnabled") && !GetPVarInt(playerid, "pv_IsMoving"))
  47.         {
  48.             if(GetPlayerWeapon(playerid) == 23 && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  49.             {
  50.                 static
  51.                     Float: camVect_Z,
  52.                     Float: mapPos_Z,
  53.                     Float: pAngle,
  54.                     Float: camPos[3],
  55.                     Float: tmpPos[4]
  56.                 ;
  57.                 GetPlayerCameraFrontVector(playerid, camVect_Z, camVect_Z, camVect_Z);
  58.                 GetPlayerCameraPos(playerid, camPos[0], camPos[1], camPos[2]);
  59.                 GetPlayerFacingAngle(playerid, pAngle);
  60.                
  61.                 camVect_Z += 0.08;
  62.                
  63.                 for(new Float: i; i < MAX_GRAPPLE_DISTANCE; i += GRAPPLE_CROSS_INTERVAL)
  64.                 {
  65.                     camPos[0] += i * floatsin(-pAngle, degrees);
  66.                     camPos[1] += i * floatcos(-pAngle, degrees);
  67.                     camPos[2] += i * camVect_Z;
  68.                    
  69.                     MapAndreas_FindZ_For2DCoord(camPos[0], camPos[1], mapPos_Z);
  70.                    
  71.                     if(tmpPos[3] < camPos[2] < mapPos_Z || camPos[2] < mapPos_Z < tmpPos[2])
  72.                     {
  73.                         static
  74.                             Float: pPos[3],
  75.                             Float: totDist
  76.                         ;
  77.                         GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
  78.                        
  79.                         camPos[0] = ((camPos[0] + tmpPos[0]) / 2.0) - pPos[0];
  80.                         camPos[1] = ((camPos[1] + tmpPos[1]) / 2.0) - pPos[1];
  81.                         camPos[2] = ((camPos[2] + tmpPos[2]) / 2.0) - pPos[2];
  82.                        
  83.                         totDist = floatpower((camPos[0] * camPos[0]) + (camPos[1] * camPos[1]) + (camPos[2] * camPos[2]), 0.5);
  84.                        
  85.                         SetPVarInt(playerid, "pv_MoveTimer",
  86.                             SetTimerEx("MovePlayer", 50, true, "iffffff", playerid, camPos[0] + pPos[0], camPos[1] + pPos[1], camPos[2] + pPos[2], ((camPos[0] * PLAYER_MOVE_SPEED) / totDist) / 46.0, ((camPos[1] * PLAYER_MOVE_SPEED) / totDist) / 46.0, 0.02132 + ((camPos[2] * PLAYER_MOVE_SPEED) / totDist) / 46.0)
  87.                         );
  88.                         SetPVarFloat(playerid, "pv_OldDist", 0x7F800000);
  89.                         break;
  90.                     }
  91.                     tmpPos[0] = camPos[0];
  92.                     tmpPos[1] = camPos[1];
  93.                     tmpPos[2] = camPos[2];
  94.                     tmpPos[3] = mapPos_Z;
  95.                    
  96.                     camPos[0] -= i * floatsin(-pAngle, degrees);
  97.                     camPos[1] -= i * floatcos(-pAngle, degrees);
  98.                     camPos[2] -= i * camVect_Z;
  99.                 }
  100.             }
  101.         }
  102.     }
  103.     return 1;
  104. }
  105.  
  106. forward MovePlayer(playerid, Float: move_X, Float: move_Y, Float: move_Z, Float: speed_X, Float: speed_Y, Float: speed_Z); public MovePlayer(playerid, Float: move_X, Float: move_Y, Float: move_Z, Float: speed_X, Float: speed_Y, Float: speed_Z)
  107. {
  108.     static
  109.         Float: pPos[3]
  110.     ;
  111.     if(GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]))
  112.     {
  113.         static
  114.             Float: distLeft
  115.         ;
  116.         pPos[0] -= move_X;
  117.         pPos[1] -= move_Y;
  118.         pPos[2] -= move_Z;
  119.        
  120.         distLeft = floatpower((pPos[0] * pPos[0]) + (pPos[1] * pPos[1]) + (pPos[2] * pPos[2]), 0.5);
  121.        
  122.         if(GetPVarFloat(playerid, "pv_OldDist") < distLeft)
  123.         {
  124.             SetPlayerVelocity(playerid, 0.0, 0.0, 0.0);
  125.             KillTimer(GetPVarInt(playerid, "pv_MoveTimer"));
  126.            
  127.             SetPVarInt(playerid, "pv_IsMoving", false);
  128.         }
  129.         else
  130.         {
  131.             static
  132.                 Float: mapPos_Z
  133.             ;
  134.             pPos[0] += move_X;
  135.             pPos[1] += move_Y;
  136.             pPos[2] += move_Z;
  137.            
  138.             MapAndreas_FindZ_For2DCoord(pPos[0], pPos[1], mapPos_Z);   
  139.            
  140.             SetPlayerVelocity(playerid, speed_X, speed_Y, floatabs(pPos[2] - mapPos_Z) < 1.1 ? speed_Z + 0.05 : speed_Z);
  141.             SetPVarFloat(playerid, "pv_OldDist", distLeft);
  142.            
  143.             ApplyAnimation(playerid, "SHOP", "SHP_Duck_Aim", 4.0, 0, 0, 0, 0, 0);
  144.             SetPVarInt(playerid, "pv_IsMoving", true);
  145.         }
  146.     }
  147.     return ;
  148. }
  149.  
  150. public OnPlayerCommandText(playerid, cmdtext[])
  151. {
  152.     if(!strcmp(cmdtext, "/grapple", true))
  153.     {
  154.         SetPVarInt(playerid, "pv_GrappleEnabled", !GetPVarInt(playerid, "pv_GrappleEnabled"));
  155.        
  156.         switch(GetPVarInt(playerid, "pv_GrappleEnabled"))
  157.         {
  158.             case false:
  159.             {
  160.                 SendClientMessage(playerid, -1, "» Grapple Hooking has been disabled.");
  161.                 SetPlayerAmmo(playerid, 23, 0);
  162.             }
  163.             case true:
  164.             {
  165.                 SendClientMessage(playerid, -1, "» Grapple Hooking has been enabled.");
  166.                 GivePlayerWeapon(playerid, 23, 0x7F800000);
  167.             }
  168.         }
  169.         return 1;
  170.     }
  171.     return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement