Advertisement
Guest User

DeathBody base code

a guest
Jul 3rd, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.77 KB | None | 0 0
  1. /*
  2.     DeathBody ScriptBase (Carry,Creation,Destroy)
  3.     You can use this script where you want.
  4.    
  5.     © Copyright Jumbo(iJumbo) 2013
  6.     Thanks Kalcor for mapandreas (http://forum.sa-mp.com/showthread.php?t=120013)
  7. */
  8. #include                                        <a_samp>
  9. #include                                        <mapandreas>
  10. #define                                         FILTERSCRIPT
  11. #define                                         MAX_DEATH_BODY                          100 //Max death bodyes can script create
  12. #define                                         DEATH_BODY_OFFSET                       0.3 //The offset of the body from the Z ground from mapandreas
  13. #define                                         DEATH_BODY_MAX_ERROR                    "DeathBodySYSTEM-WARNING: Max death body reached."
  14. #define                                         DEATH_BODY_NO_BODY                      "You don't have any death body in your hands"
  15. #define                                         DEATH_BODY_NO_NEAR                      "There is no death body near you"
  16. #define                                         DEATH_BODY_FIND_RANGE                   2.0 //The range for find a deathbody (with /pickupbody)
  17. #define                                         DEATH_BODY_CARRY_X                      0.060999 //carry offset X
  18. #define                                         DEATH_BODY_CARRY_Y                      0.028999 //carry offset Y
  19. #define                                         DEATH_BODY_CARRY_Z                      -0.393999 //carry offset Z
  20. #define                                         DEATH_BODY_CARRY_RX                     -20.699985 //carry offset RX
  21. #define                                         DEATH_BODY_CARRY_RY                     0.000000 //carry offset RY
  22. #define                                         DEATH_BODY_CARRY_RZ                     -0.60000 //carry offset RZ
  23. #define                                         SLOT_CARRY                              8 //Slot for attached object
  24. forward                                         DeathBodyFunction();
  25.  
  26. /*
  27.  
  28. Function CreateDeathBody(Float:X, Float:Y, Float:Z, Expire_Seconds = 60)
  29.          This function create a death body in the x y z position
  30.          you can also add a expire time (default 60 seconds)
  31.  
  32.  
  33. Function DeleteDeathBody(DeathBody_ID)
  34.          This function delete a death body by giving a deathbody ID
  35.  
  36. Function DeleteAllDeathBody()
  37.          This function delete all existing death body
  38.  
  39. Function FindFreeDeathBody()
  40.          This function find a free death body id from the MAX_DEATH_BODY
  41.  
  42. Function FindNearDeathBodyID(playerid,Float:Range)
  43.          This function find a near body you can give the range
  44.  
  45.  
  46. Function PickupDeathBody(playerid)
  47.          This function pickup a body from the ground
  48.  
  49. Function DropDeathBody(playerid)
  50.          This function drop a body to the ground
  51. */
  52.  
  53.  
  54.  
  55. /*DeathBody ------------------------------------------------------------------*/
  56. enum DEATH_BODY {
  57.     DEATH_BODY_OBJ,
  58.     Float:DEATH_BODY_X,
  59.     Float:DEATH_BODY_Y,
  60.     Float:DEATH_BODY_Z,
  61.     DEATH_BODY_EXPIRE_SECONDS,
  62.     bool:DEATH_BODY_CARRY,
  63.     bool:DEATH_BODY_USED
  64. }
  65. new
  66.     DeathBody[MAX_DEATH_BODY][DEATH_BODY],
  67.     DeathBodyTimer,
  68.     PlayerCarry_DeathBody[MAX_PLAYERS]
  69. ;
  70.  
  71.  
  72.  
  73.  
  74. /*INT ------------------------------------------------------------------------*/
  75. public OnFilterScriptInit()
  76. {
  77.     DeathBodyTimer = SetTimer("DeathBodyFunction",1000,1);
  78.     return 1;
  79. }
  80. /*EXIT -----------------------------------------------------------------------*/
  81. public OnFilterScriptExit()
  82. {
  83.     KillTimer(DeathBodyTimer);
  84.     DeleteAllDeathBody();
  85.     return 1;
  86. }
  87.  
  88.  
  89.  
  90.  
  91. /*FUNCTIONS ------------------------------------------------------------------*/
  92. public DeathBodyFunction()
  93. {
  94.     for(new db = 0; db != MAX_DEATH_BODY; db++) {
  95.         for(new i = 0; i != MAX_PLAYERS; i++) {
  96.             if(IsPlayerInRangeOfPoint(i,3.0,DeathBody[db][DEATH_BODY_X],DeathBody[db][DEATH_BODY_Y],DeathBody[db][DEATH_BODY_Z]) && DeathBody[db][DEATH_BODY_CARRY] == false && DeathBody[i][DEATH_BODY_USED] == true) {
  97.                 if(IsValidObject(DeathBody[db][DEATH_BODY_OBJ])) {
  98.                     DestroyObject(DeathBody[db][DEATH_BODY_OBJ]);
  99.                     DeathBody[db][DEATH_BODY_OBJ] = CreateObject(3092, DeathBody[db][DEATH_BODY_X],DeathBody[db][DEATH_BODY_Y],DeathBody[db][DEATH_BODY_Z] + DEATH_BODY_OFFSET, 90.0, 90.0, 90.0);
  100.                 }
  101.             }
  102.         }
  103.         if(DeathBody[db][DEATH_BODY_USED] ==  true && DeathBody[db][DEATH_BODY_CARRY] == false) {
  104.             DeathBody[db][DEATH_BODY_EXPIRE_SECONDS] = DeathBody[db][DEATH_BODY_EXPIRE_SECONDS] - 1;
  105.             if(DeathBody[db][DEATH_BODY_EXPIRE_SECONDS] <= 0) {
  106.                 DeleteDeathBody(db);
  107.             }
  108.         }
  109.     }
  110. }
  111. public OnPlayerDeath(playerid, killerid, reason)
  112. {
  113.     new Float:POS[3];
  114.     GetPlayerPos(playerid,POS[0],POS[1],POS[2]);
  115.     CreateDeathBody(POS[0],POS[1],POS[2]);
  116.     DropDeathBody(playerid);
  117.     return 1;
  118. }
  119.  
  120. public OnPlayerDisconnect(playerid, reason)
  121. {
  122.     DropDeathBody(playerid);
  123.     return 1;
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. /*STOCK ----------------------------------------------------------------------*/
  133.  
  134. stock CreateDeathBody(Float:X, Float:Y, Float:Z, Expire_Seconds = 60)
  135. {
  136.     new DeathBodyID = FindFreeDeathBody();
  137.     if(DeathBodyID != -1) {
  138.         MapAndreas_FindZ_For2DCoord(X,Y,Z);
  139.         DeathBody[DeathBodyID][DEATH_BODY_USED] = true;
  140.         DeathBody[DeathBodyID][DEATH_BODY_EXPIRE_SECONDS] = Expire_Seconds;
  141.         DeathBody[DeathBodyID][DEATH_BODY_X] = X;
  142.         DeathBody[DeathBodyID][DEATH_BODY_Y] = Y;
  143.         DeathBody[DeathBodyID][DEATH_BODY_Z] = Z;
  144.         DeathBody[DeathBodyID][DEATH_BODY_OBJ] = CreateObject(3092, X, Y, Z + DEATH_BODY_OFFSET, 90.0, 90.0, 90.0);
  145.     } else print(DEATH_BODY_MAX_ERROR);
  146. }
  147. stock DeleteDeathBody(DeathBody_ID)
  148. {
  149.     if(DeathBody[DeathBody_ID][DEATH_BODY_USED] ==  true) {
  150.         DeathBody[DeathBody_ID][DEATH_BODY_USED] = false;
  151.         DestroyObject(DeathBody[DeathBody_ID][DEATH_BODY_OBJ]);
  152.     }
  153. }
  154. stock DeleteAllDeathBody()
  155. {
  156.     for(new i = 0; i != MAX_DEATH_BODY; i++) {
  157.         if(DeathBody[i][DEATH_BODY_USED] ==  true) {
  158.             DeathBody[i][DEATH_BODY_USED] = false;
  159.             DestroyObject(DeathBody[i][DEATH_BODY_OBJ]);
  160.         }
  161.     }
  162. }
  163. stock FindFreeDeathBody()
  164. {
  165.     for(new i = 0; i != MAX_DEATH_BODY; i++) {
  166.         if(DeathBody[i][DEATH_BODY_USED] == false) {
  167.             return i;
  168.         }
  169.     }
  170.     return -1;
  171. }
  172. stock FindNearDeathBodyID(playerid,Float:Range)
  173. {
  174.     for(new i = 0; i != MAX_DEATH_BODY; i++) {
  175.         if(IsPlayerInRangeOfPoint(playerid,Range,DeathBody[i][DEATH_BODY_X],DeathBody[i][DEATH_BODY_Y],DeathBody[i][DEATH_BODY_Z]) && DeathBody[i][DEATH_BODY_CARRY] == false && DeathBody[i][DEATH_BODY_USED] == true) {
  176.             return i;
  177.         }
  178.     }
  179.     return -1;
  180. }
  181. stock PickupDeathBody(playerid)
  182. {
  183.     new DeathBodyID = FindNearDeathBodyID(playerid,DEATH_BODY_FIND_RANGE);
  184.     if(DeathBodyID != -1) {
  185.         PlayerCarry_DeathBody[playerid] = DeathBodyID;
  186.         //
  187.         DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_CARRY] = true;
  188.         DestroyObject(DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_OBJ]);
  189.         //
  190.         SetPlayerAttachedObject(playerid,SLOT_CARRY,3092,6,DEATH_BODY_CARRY_X,DEATH_BODY_CARRY_Y,DEATH_BODY_CARRY_Z,DEATH_BODY_CARRY_RX,DEATH_BODY_CARRY_RY,DEATH_BODY_CARRY_RZ);
  191.         SetPlayerSpecialAction(playerid,SPECIAL_ACTION_CARRY);
  192.     } else SendClientMessage(playerid,-1,DEATH_BODY_NO_NEAR);
  193. }
  194. stock DropDeathBody(playerid)
  195. {
  196.     if(PlayerCarry_DeathBody[playerid] != -1) {
  197.         new Float:POS[3];
  198.         GetPlayerPos(playerid,POS[0],POS[1],POS[2]);
  199.         //
  200.         DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_CARRY] = false;
  201.         MapAndreas_FindZ_For2DCoord(POS[0],POS[1],POS[2]);
  202.         DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_X] = POS[0];
  203.         DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_Y] = POS[1];
  204.         DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_Z] = POS[2];
  205.         DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_OBJ] = CreateObject(3092, DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_X],DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_Y],DeathBody[PlayerCarry_DeathBody[playerid]][DEATH_BODY_Z]  + DEATH_BODY_OFFSET, 90.0, 90.0, 90.0);
  206.         //
  207.         RemovePlayerAttachedObject(playerid,SLOT_CARRY);
  208.         SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
  209.         //
  210.         //
  211.         PlayerCarry_DeathBody[playerid] = -1;
  212.     } else SendClientMessage(playerid,-1,DEATH_BODY_NO_BODY);
  213. }
  214. /*COMMANDS -------------------------------------------------------------------*/
  215. public OnPlayerCommandText(playerid, cmdtext[])
  216. {
  217.     /*
  218.         Create a normal death body (60 sec expire)
  219.     */
  220.     if(strcmp(cmdtext,"/TestDeathBody",true) == 0)
  221.     {
  222.         new Float:POS[3];
  223.         GetPlayerPos(playerid,POS[0],POS[1],POS[2]);
  224.         CreateDeathBody(POS[0],POS[1],POS[2]);
  225.         return 1;
  226.     }
  227.     /*
  228.         Create a timed death body (5 sec expire)
  229.     */
  230.     if(strcmp(cmdtext,"/TestDeathBody5",true) == 0)
  231.     {
  232.         new Float:POS[3];
  233.         GetPlayerPos(playerid,POS[0],POS[1],POS[2]);
  234.         CreateDeathBody(POS[0],POS[1],POS[2],5);//Check CreateDeathBody function
  235.         return 1;
  236.     }
  237.     /*
  238.         Pickup the death body from the ground
  239.     */
  240.     if(strcmp(cmdtext,"/pickupbody",true) == 0)
  241.     {
  242.         PickupDeathBody(playerid);
  243.         return 1;
  244.     }
  245.     /*
  246.         Drop the death body in the ground and the timing for exipre will start again
  247.     */
  248.     if(strcmp(cmdtext,"/dropbody",true) == 0)
  249.     {
  250.         DropDeathBody(playerid);
  251.         return 1;
  252.     }
  253.     return 0;
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement