Advertisement
Guest User

Simple death system by cs_waller

a guest
Aug 29th, 2016
1,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.34 KB | None | 0 0
  1. // Simple Death and Corpse System by Cs_Waller for the http://forum.sa-mp.com/ community.
  2. //Use the script however you like, just please, don't remove the credits on the top. I can't stop you, it's just a request
  3. #define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <a_actor>
  7. //Corpse and death system
  8. new aspam[MAX_PLAYERS]; //prevents player from spamming /acceptdeath and bugging the hell out of the script.
  9. new dead[MAX_PLAYERS]; //Injured state of a player once he gets downed, pre /acceptdeath phase.
  10. new respawn[MAX_PLAYERS]; //Prevents people from speaking while being in the afterlife
  11. new timer69[MAX_PLAYERS]; //Countdown until a player leaves the afterlife stage and returns back to normal.
  12. new timer420[MAX_PLAYERS]; //Countdown to prevent a player from staying downed forever, forced afterlife stage.
  13. new Float:X, Float:Y, Float:Z, Float:A; //Storing the coordinates and angle when a player dies.
  14. new pskin; //The skin of the downed player is stored here.
  15. new interior; //The interior of the downed player is stored here.
  16. new Text3D:LabelID[MAX_PLAYERS]; //3d text label with the name of the player who died
  17. new actors[MAX_PLAYERS]; //actor spawned in the same position of the player who died.
  18. //Afterlife random heights to avoid many people in one place
  19. new Float:height[][] = {
  20. {0.0, 0.0, 42069.0},
  21. {0.0, 0.0, 6969.0},
  22. {0.0, 0.0, 4269.0},
  23. {0.0, 0.0, 1337.0},
  24. {0.0, 0.0, 69123.0},
  25. {0.0, 0.0, 42420.0},
  26. {0.0, 0.0, 69420.0},
  27. {0.0, 0.0, 66699.0},
  28. {0.0, 0.0, 42690.0},
  29. {0.0, 0.0, 1234.0},
  30. {0.0, 0.0, 5678.0},
  31. {0.0, 0.0, 6699.0},
  32. {0.0, 0.0, 4242.0},
  33. {0.0, 0.0, 42042.0},
  34. {0.0, 0.0, 42420.0}
  35. };
  36. //colors
  37. #define COLOR_BLUE 0xF0F8FFFF
  38. #define COLOR_RED 0xAA3333AA
  39. #define COLOR_GREY 0xAFAFAFAA
  40. #define COLOR_GREEN 0x33AA33AA
  41. #define COLOR_RED 0xAA3333AA
  42. #define COLOR_YELLOW 0xFFFF00AA
  43. #define COLOR_WHITE 0xFFFFFFAA
  44. #define COLOR_ORANGE 0xFF9900AA
  45. #define COLOR_SPAWN 0xFF8C55FF
  46. #define COLOR_LIGHTBLUE 0x6DC5F3FF
  47. #define COLOR_ADMIN 0xFF0000FF
  48. #define COLOR_SAY 0x2986CEFF
  49. #define COLOR_SYSGREY 0xC6BEBDFF
  50. #define COLOR_BLACK 0x000000FF
  51. #define COLOR_JOIN 0x74E80099
  52. #define COLOR_WARN 0xBE615099
  53. #define COLOR_RACE 0x00BBBB99
  54. #define COLOR_KRED 0xFF0000FF
  55. //End
  56. #if defined FILTERSCRIPT
  57.  
  58. public OnFilterScriptInit()
  59. {
  60. print("\n----------------------------------------------------------");
  61. print(" Simple Death and Corpse System has been loaded successfuly");
  62. print("----------------------------------------------------------\n");
  63. return 1;
  64. }
  65.  
  66. public OnFilterScriptExit()
  67. {
  68. print("Simple death and Corpse System has been unloaded successfuly");
  69. return 1;
  70. }
  71.  
  72. #endif
  73.  
  74. public OnPlayerConnect(playerid)
  75. {
  76. aspam[playerid] = 0; //Once a player connects, this is automatically set to 0 in case of any bugs.
  77. KillTimer(timer69[playerid]); //The timer for the afterlife phase is killed just to make sure.
  78. KillTimer(timer420[playerid]); //The timer for the auto death is killed just to makeke sure
  79. dead[playerid] = 0; //The player just connected to the server, no way for it to be anything else than 0.
  80. respawn[playerid] = 0; //Same like above.
  81. return 1;
  82. }
  83.  
  84. public OnPlayerDisconnect(playerid, reason)
  85. {
  86. aspam[playerid] = 0; //To prevent bugs this is set to 0 if the player leaves while being in the afterlife.
  87. KillTimer(timer69[playerid]); //The timer is killed so the filterscript won't continue using the timer if a player disconnects.
  88. KillTimer(timer420[playerid]); //Same as above.
  89. dead[playerid] = 0; //In case a player gets downed and quits the game, this is set to 0.
  90. respawn[playerid] = 0; //Same as above.
  91. return 1;
  92. }
  93.  
  94. public OnPlayerSpawn(playerid)
  95. {
  96. respawn[playerid] = 0; //After player spawns, be it from death or after joining the game, it's set to 0 so he can chat.
  97. aspam[playerid] = 0; //Turns off after a player spawns from the afterlife or joins the game, allows them to speak.
  98. KillTimer(timer69[playerid]); //Kills the timer as the player is no longer in the afterlife (or never was).
  99. if(dead[playerid] == 1) //Checks if the player is downed, if yes the script bellow starts.
  100. {
  101. dead[playerid] = 1; //Set to 1 just to make sure.
  102. SetPlayerInterior(playerid, interior); //Sets the interior where the player got downed.
  103. SetPlayerSkin(playerid, pskin); //Sets the same skin the player had from when he was downed.
  104. SetPlayerPos(playerid, X, Y, Z); //Sets the saved coordinates from when the player died.
  105. SetPlayerFacingAngle(playerid, A); //Sets the angle the player faced when he died.
  106. TogglePlayerControllable(playerid, 0); //Freezes the player so he can't use anything.
  107. ApplyAnimation(playerid,"PARACHUTE","FALL_skyDive_DIE", 4.0, 0, 0, 0, 1, 0); //Applies a downed animation for more realism.
  108. }
  109. return 1;
  110. }
  111.  
  112. public OnPlayerDeath(playerid, killerid, reason)
  113. {
  114. dead[playerid] = 1; //Sets to 1 and makes the player enter the downed phase.
  115. timer420[playerid] = SetTimerEx("autodeath",60000,false,"i",playerid); //1 minute timer starts after the player dying to avoid any bugs, forced afterlife.
  116. GetPlayerSkin(pskin); //Saves the player's skin for the corpse actor and the player themself.
  117. GetPlayerInterior(interior); //Saves the player's interior in case he died in one
  118. GetPlayerFacingAngle(playerid, A);//Saves the player's angle so the actor could be used to it's full potential.
  119. GetPlayerPos(playerid, X, Y, Z); //Stores the player's coordinates to be used later when he spawns.
  120. SendClientMessage(playerid, COLOR_ORANGE, "You have been downed, accept your fate like a man."); //Message.
  121. SendClientMessage(playerid, COLOR_WHITE, "To accept death, type /acceptdeath in the chat."); //Message N2.
  122. return 1;
  123. }
  124.  
  125. public OnVehicleSpawn(vehicleid)
  126. {
  127. return 1;
  128. }
  129.  
  130. public OnVehicleDeath(vehicleid, killerid)
  131. {
  132. return 1;
  133. }
  134.  
  135. public OnPlayerText(playerid, text[])
  136. {
  137.  
  138. if(respawn[playerid] != 0) //If the player is waiting for the respawn and tries chatting, the message below is shown.
  139. {
  140. SendClientMessage(playerid, COLOR_SPAWN, "You are in the afterlife, you shall not speak unless spoken to!"); //Message
  141. return 0;
  142. }
  143. return 1;
  144. }
  145. //forwards
  146.  
  147. forward autodeath(playerid); //Forwards the auto death script if a player refuses to accept their death.
  148. public autodeath(playerid) //The script is called if the player stays in the downed phase for over a minute.
  149. {
  150. switch (random(5)) //Points out how many random cases we have.
  151. {
  152. case 0: //The first case is picked randomly and the player in question gets the message below.
  153. {
  154. SendClientMessage(playerid, COLOR_RED, "Everything has it's end.");
  155. }
  156. case 1: //The second case is picked randomly and the player in question gets the message below.
  157. {
  158. SendClientMessage(playerid, COLOR_RED, "You have died and are to be send in the outer world");
  159. }
  160. case 2: //The third case is picked randomly and the player in question gets the message below.
  161. {
  162. SendClientMessage(playerid, COLOR_RED, "Your time has come.");
  163. }
  164. case 3: //The fourth case is picked randomly and the player in question gets the message below.
  165. {
  166. SendClientMessage(playerid, COLOR_RED, "You have been forced into the afterlife phase as your body bled out.");
  167. }
  168. case 4: //The fifth case is picked randomly and the player in question gets the message below.
  169. {
  170. SendClientMessage(playerid, COLOR_RED, "Your soul has left your body.");
  171. }
  172. }
  173. new rand = random(15);
  174. new skinning; //Stores the skin of the player before using the command.
  175. new name5[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME]; //Stores the name of the player.
  176. new Float:XD, Float:YD, Float:ZD, Float:Rotation; //X Y Z coordinates for the label and angel for the actor.
  177. GetPlayerPos(playerid, Float:XD, Float:YD, Float:ZD); //Stores the X Y Z coordinates and the angle for the actor.
  178. GetPlayerName(playerid, name5, sizeof(name5)); //Gets the name of the player.
  179. format(string, sizeof(string), "Corpse of %s.", name5); //String used for the 3Dtext on the corpse.
  180. LabelID[playerid] = Create3DTextLabel(string, COLOR_ORANGE,Float:XD, Float:YD, Float:ZD-0.5 , 10, 0, 0); //3D text showing the name of the player who died.
  181. aspam[playerid] = 1; //Activates the anti spam feature.
  182. respawn[playerid] = 1; //Actvates the anti talking feature.
  183. dead[playerid] = 0; //Removes the player from the downed state as he's no longer alive.
  184. SendClientMessage(playerid, COLOR_BLUE, "Your soul has been sucked out of you as you were laying motionlessly for over a minute"); //Message.
  185. SetPlayerHealth(playerid, 10); //Set's the player's health for the duration of the afterlife phase.
  186. SetPlayerPos(playerid,height[rand][0],height[rand][1],height[rand][2]); //Because 1337 is too mainstream ;p
  187. TogglePlayerControllable(playerid, 0); //Freezes the player as he's in the air.
  188. ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 1, 0, 1); //Applies the downed animation as the player is in the afterlife phase.
  189. timer69[playerid] = SetTimerEx("respawntimer", 30000, true, "f", playerid); //30 seconds timer starts.
  190. skinning = GetPlayerSkin(playerid); //Checks for the player's skin so the actor can have the same one.
  191. actors[playerid] = CreateActor(skinning, Float:X, Float:Y, Float:Z, Float:Rotation); //Spawning the actor itself.
  192. ApplyActorAnimation(actors[playerid], "WUZI", "CS_Dead_Guy", 4.1, 1, 0, 0, 1, 0); //Applying the animation to the actor.
  193. KillTimer(timer420[playerid]); //Kills the timer as the player accepted death
  194. return 1;
  195. }
  196. forward respawntimer(playerid); //Forwards the script below.
  197. public respawntimer(playerid) //The script is called once a player leaves the afterlife phase, deletes the 3D text labels, the corpse and respawns the player.
  198. {
  199. Delete3DTextLabel(LabelID[playerid]); //The 3D text is removed from the server once the player gets out of the afterlife phase.
  200. DestroyActor(actors[playerid]); //The corpse(actor) is removed from the server once the player gets out of the afterlife phase.
  201. respawn[playerid] = 0; //Allows the player to speak as he's no longer in the afterlife phase.
  202. SpawnPlayer(playerid); //Spawns the player. (Note: If changed to SetPlayerHealth(playerid, 0); the FS bugs out and the player is stuck in an endless cycle!)
  203. SetPlayerHealth(playerid, 100); //Spawns the player with his normal health as it was 10 in the afterlife phase.
  204. SendClientMessage(playerid, COLOR_RED, "Your soul has entered your body and you have been sent back on earth, enjoy your time here"); //Message to tell the player he's out of the afterlife phase.
  205. return 1;
  206. }
  207. public OnPlayerCommandText(playerid, cmdtext[])
  208. {
  209. if (strcmp("/kill", cmdtext, true, 10) == 0) //Used it to test the script, remove it if needed.
  210. {
  211. SetPlayerHealth(playerid, 0);
  212. return 1;
  213. }
  214. if (strcmp("/acceptdeath", cmdtext, true, 10) == 0) //The command itself.
  215. {
  216. if(dead[playerid] == 1) //Checks if the player is in downed state, prevents people from using the command if they are not downed.
  217. {
  218. new rand = random(15);
  219. new skinning; //Stores the skin of the player before using the command.
  220. new name5[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME]; //Stores the name of the player.
  221. new Float:XD, Float:YD, Float:ZD, Float:Rotation; //X Y Z coordinates for the label and angel for the actor.
  222. GetPlayerPos(playerid, Float:XD, Float:YD, Float:ZD); //Stores the X Y Z coordinates and the angle for the actor.
  223. GetPlayerName(playerid, name5, sizeof(name5)); //Gets the name of the player.
  224. format(string, sizeof(string), "Corpse of %s.", name5); //String used for the 3Dtext on the corpse.
  225. LabelID[playerid] = Create3DTextLabel(string, COLOR_ORANGE,Float:XD, Float:YD, Float:ZD-0.5 , 10, 0, 0); //3D text showing the name of the player who died.
  226. aspam[playerid] = 1; //Activates the anti spam feature.
  227. respawn[playerid] = 1; //Actvates the anti talking feature.
  228. dead[playerid] = 0; //Removes the player from the downed state as he's no longer alive.
  229. SendClientMessage(playerid, COLOR_BLUE, "You have accepted your death, now you shall wait 30 seconds as your soul comes back to your body"); //Message.
  230. SetPlayerHealth(playerid, 10); //Set's the player's health for the duration of the afterlife phase.
  231. SetPlayerPos(playerid,height[rand][0],height[rand][1],height[rand][2]); //Because 1337 is too mainstream ;p
  232. TogglePlayerControllable(playerid, 0); //Freezes the player as he's in the air.
  233. ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 1, 0, 1); //Applies the downed animation as the player is in the afterlife phase.
  234. timer69[playerid] = SetTimerEx("respawntimer", 30000, true, "f", playerid); //30 seconds timer starts.
  235. skinning = GetPlayerSkin(playerid); //Checks for the player's skin so the actor can have the same one.
  236. actors[playerid] = CreateActor(skinning, Float:X, Float:Y, Float:Z, Float:Rotation); //Spawning the actor itself.
  237. ApplyActorAnimation(actors[playerid], "WUZI", "CS_Dead_Guy", 4.1, 1, 0, 0, 1, 0); //Applying the animation to the actor.
  238. KillTimer(timer420[playerid]); //Kills the timer as the player accepted death
  239. return 1;
  240. }
  241. if(aspam[playerid] == 1) //If the player has already accepted death, he can't use the command again.
  242. {
  243. SendClientMessage(playerid, COLOR_WHITE, "Don't spam this, you have already accepted it!"); //Message.
  244. return 1;
  245. }
  246. else if(dead[playerid] == 0) //If the player is not downed, he can not use the command to accept death.
  247. {
  248. SendClientMessage(playerid, COLOR_RED, "You are not dead, don't try using this sacred command!"); //Message
  249. return 1;
  250. }
  251. }
  252. return 0;
  253. }
  254.  
  255. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  256. {
  257. return 1;
  258. }
  259.  
  260. public OnPlayerExitVehicle(playerid, vehicleid)
  261. {
  262. return 1;
  263. }
  264.  
  265. public OnPlayerStateChange(playerid, newstate, oldstate)
  266. {
  267. return 1;
  268. }
  269.  
  270. public OnPlayerEnterCheckpoint(playerid)
  271. {
  272. return 1;
  273. }
  274.  
  275. public OnPlayerLeaveCheckpoint(playerid)
  276. {
  277. return 1;
  278. }
  279.  
  280. public OnPlayerEnterRaceCheckpoint(playerid)
  281. {
  282. return 1;
  283. }
  284.  
  285. public OnPlayerLeaveRaceCheckpoint(playerid)
  286. {
  287. return 1;
  288. }
  289.  
  290. public OnRconCommand(cmd[])
  291. {
  292. return 1;
  293. }
  294.  
  295. public OnPlayerRequestSpawn(playerid)
  296. {
  297. return 1;
  298. }
  299.  
  300. public OnObjectMoved(objectid)
  301. {
  302. return 1;
  303. }
  304.  
  305. public OnPlayerObjectMoved(playerid, objectid)
  306. {
  307. return 1;
  308. }
  309.  
  310. public OnPlayerPickUpPickup(playerid, pickupid)
  311. {
  312. return 1;
  313. }
  314.  
  315. public OnVehicleMod(playerid, vehicleid, componentid)
  316. {
  317. return 1;
  318. }
  319.  
  320. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  321. {
  322. return 1;
  323. }
  324.  
  325. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  326. {
  327. return 1;
  328. }
  329.  
  330. public OnPlayerSelectedMenuRow(playerid, row)
  331. {
  332. return 1;
  333. }
  334.  
  335. public OnPlayerExitedMenu(playerid)
  336. {
  337. return 1;
  338. }
  339.  
  340. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  341. {
  342. return 1;
  343. }
  344.  
  345. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  346. {
  347. return 1;
  348. }
  349.  
  350. public OnRconLoginAttempt(ip[], password[], success)
  351. {
  352. return 1;
  353. }
  354.  
  355. public OnPlayerUpdate(playerid)
  356. {
  357. return 1;
  358. }
  359.  
  360. public OnPlayerStreamIn(playerid, forplayerid)
  361. {
  362. return 1;
  363. }
  364.  
  365. public OnPlayerStreamOut(playerid, forplayerid)
  366. {
  367. return 1;
  368. }
  369.  
  370. public OnVehicleStreamIn(vehicleid, forplayerid)
  371. {
  372. return 1;
  373. }
  374.  
  375. public OnVehicleStreamOut(vehicleid, forplayerid)
  376. {
  377. return 1;
  378. }
  379.  
  380. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  381. {
  382. return 1;
  383. }
  384.  
  385. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  386. {
  387. return 1;
  388. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement