corpse.inc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #include <YSI_Coding\y_hooks>
  2. static enum E_CORPSE_INJURY_DATA
  3. {
  4. E_CORPSE_INJURY_HITS,
  5. E_CORPSE_INJURY_WEAPON,
  6. E_CORPSE_INJURY_BODYPART,
  7. E_CORPSE_INJURY_SECONDS,
  8. }
  9. static CorpseInjuryInfo[MAX_ACTORS][MAX_INJURIES][E_CORPSE_INJURY_DATA];
  10. static Float:LastX[MAX_PLAYERS];
  11. static Float:LastY[MAX_PLAYERS];
  12. static Float:LastZ[MAX_PLAYERS];
  13. static Float:LastA[MAX_PLAYERS];
  14. static DraggingCorpse[MAX_PLAYERS];
  15. static bool:BeingDragged[MAX_ACTORS];
  16. static bool:IsACorpse[MAX_ACTORS];
  17. static Text3D:CorpseTD[MAX_ACTORS];
  18. static bool:ValidCorpseTD[MAX_ACTORS];
  19. hook OnPlayerConnect(playerid)
  20. {
  21. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  22. }
  23. hook OnPlayerDisconnect(playerid, reason)
  24. {
  25. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID)
  26. {
  27. if(IsValidActor(DraggingCorpse[playerid]))
  28. {
  29. Corpse_Drop(DraggingCorpse[playerid]);
  30. }
  31. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  32. }
  33. }
  34. hook OnPlayerWounded(playerid)
  35. {
  36. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID)
  37. {
  38. if(IsValidActor(DraggingCorpse[playerid]))
  39. {
  40. Corpse_Drop(DraggingCorpse[playerid]);
  41. }
  42. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  43. }
  44. }
  45. hook OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  46. {
  47. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID)
  48. {
  49. if(IsValidActor(DraggingCorpse[playerid]))
  50. {
  51. Corpse_Drop(DraggingCorpse[playerid]);
  52. }
  53. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  54. }
  55. }
  56. Corpse_ShowInjuries(playerid, corpseid)
  57. {
  58. new string[112 * MAX_INJURIES];
  59. new weaponName[36];
  60. new count = 0;
  61. for(new i; i < MAX_INJURIES; i++)
  62. {
  63. if(CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_HITS] != 0)
  64. {
  65. count++;
  66. GetWeaponName(CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_WEAPON], weaponName, sizeof(weaponName));
  67. strcat(string, va_return("{b3b3b3}%d hits from a %s to the %s, %ds ago\n", CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_HITS], weaponName,
  68. GetBodypartName(CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_BODYPART]), gettime() - CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_SECONDS]));
  69. }
  70. }
  71. if(count > 0) Dialog_Show(playerid, DIALOG_STYLE_LIST, va_return("Corpse injuries (( ID %d ))", corpseid), string, "Close");
  72. else
  73. {
  74. SendErrorMessage(playerid, "There is no damage to display.");
  75. }
  76. return 1;
  77. }
  78. Corpse_Create(playerid)
  79. {
  80. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID)
  81. {
  82. if(IsValidActor(DraggingCorpse[playerid]))
  83. ApplyActorAnimation(DraggingCorpse[playerid], "CRACK", "CRCKDETH4", 4.1, 0, 1, 1, 1, 0);
  84. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  85. }
  86. new Float:x, Float:y, Float:z, Float:a;
  87. GetPlayerPos(playerid, x, y, z);
  88. GetPlayerFacingAngle(playerid, a);
  89. new corpseid = CreateActor(Player_GetSkin(playerid), x, y, z, a);
  90. ApplyActorAnimation(corpseid, "CRACK", "CRCKDETH4", 4.1, 0, 1, 1, 1, 0);
  91. BeingDragged[corpseid] = false;
  92. IsACorpse[corpseid] = true;
  93. for(new i; i < MAX_INJURIES; i++)
  94. {
  95. CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_HITS] = InjuryInfo[playerid][i][E_INJURY_HITS];
  96. CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_WEAPON] = InjuryInfo[playerid][i][E_INJURY_WEAPON];
  97. CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_BODYPART] = InjuryInfo[playerid][i][E_INJURY_BODYPART];
  98. CorpseInjuryInfo[corpseid][i][E_CORPSE_INJURY_SECONDS] = InjuryInfo[playerid][i][E_INJURY_SECONDS];
  99. }
  100. if(!ValidCorpseTD[corpseid])
  101. {
  102. ValidCorpseTD[corpseid] = true;
  103. CorpseTD[corpseid] = Create3DTextLabel("(( This is a dead body,\n/corpse examine for more information ))", 0xFF6666FF, x, y, z, 20, GetPlayerVirtualWorld(playerid), 1);
  104. }
  105. return corpseid;
  106. }
  107. Corpse_Drop(corpseid)
  108. {
  109. if(ValidCorpseTD[corpseid])
  110. {
  111. new Float:x, Float:y, Float:z;
  112. GetActorPos(corpseid, x, y, z);
  113. Delete3DTextLabel(CorpseTD[corpseid]);
  114. CorpseTD[corpseid] = Create3DTextLabel("(( This is a dead body,\n/corpse examine for more information ))", 0xFF6666FF, x, y, z - 1, 20, GetActorVirtualWorld(corpseid), 1);
  115. }
  116. BeingDragged[corpseid] = false;
  117. ApplyActorAnimation(corpseid, "CRACK", "CRCKDETH4", 4.1, 0, 1, 1, 1, 0);
  118. return 1;
  119. }
  120. timer UpdateCorpse[100](playerid)
  121. {
  122. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID && IsValidActor(DraggingCorpse[playerid]))
  123. {
  124. new corpseid = DraggingCorpse[playerid];
  125. if(IsACorpse[corpseid])
  126. {
  127. new Float:x, Float:y, Float:z, Float:a;
  128. GetPlayerPos(playerid, x, y, z);
  129. GetPlayerFacingAngle(playerid, a);
  130. if(x != LastX[playerid] || y != LastY[playerid] || z != LastZ[playerid] || a != LastA[playerid])
  131. {
  132. if(GetPlayerVirtualWorld(playerid) != GetActorVirtualWorld(corpseid))
  133. {
  134. SetActorVirtualWorld(corpseid, GetPlayerVirtualWorld(playerid));
  135. }
  136. if(ValidCorpseTD[corpseid])
  137. {
  138. Delete3DTextLabel(CorpseTD[corpseid]);
  139. CorpseTD[corpseid] = Create3DTextLabel("(( This is a dead body,\n/corpse examine for more information ))", 0xFF6666FF, x, y, z + 1, 20, GetPlayerVirtualWorld(playerid), 1);
  140. }
  141. LastX[playerid] = x;
  142. LastY[playerid] = y;
  143. LastZ[playerid] = z;
  144. LastA[playerid] = a;
  145. x += (0.2 * floatsin(-a + 180, degrees));
  146. y += (0.2 * floatcos(-a + 180, degrees));
  147. SetActorPos(corpseid, x, y, z + 0.8);
  148. SetActorFacingAngle(corpseid, a);
  149. }
  150. defer UpdateCorpse(playerid);
  151. }
  152. }
  153. }
  154. CMD:corpse(playerid, params[])
  155. {
  156. if(isnull(params)) return SendSyntaxMessage(playerid, "/corpse (options: carry, drop, examine, trunk)");
  157. if(!strcmp(params, "carry", true))
  158. {
  159. if(IsPlayerInAnyVehicle(playerid)) return SendErrorMessage(playerid, "You have to get out of the vehicle first.");
  160. if(IsPlayerWounded(playerid)) return SendErrorMessage(playerid, "You can't do this when you're brutally wounded.");
  161. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID) return SendErrorMessage(playerid, "You're already carrying a dead body.");
  162. new corpseid = GetClosestActor(playerid, 2.0);
  163. if(corpseid == INVALID_ACTOR_ID) return SendErrorMessage(playerid, "You must get closer to that dead body.");
  164. if(!IsACorpse[corpseid]) return SendErrorMessage(playerid, "That's not a corpse.");
  165. if(BeingDragged[corpseid]) return SendErrorMessage(playerid, "You can't carry that dead body.");
  166. DraggingCorpse[playerid] = corpseid;
  167. BeingDragged[corpseid] = true;
  168. defer UpdateCorpse(playerid);
  169. ApplyActorAnimation(corpseid, "PED", "DROWN", 4.1, 0, 1, 1, 1, 0);
  170. }
  171. else if(!strcmp(params, "drop", true))
  172. {
  173. if(DraggingCorpse[playerid] == INVALID_ACTOR_ID)
  174. return SendErrorMessage(playerid, "You're not carrying a dead body.");
  175. if(IsValidActor(DraggingCorpse[playerid]))
  176. {
  177. Corpse_Drop(DraggingCorpse[playerid]);
  178. }
  179. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  180. }
  181. else if(!strcmp(params, "examine", true))
  182. {
  183. new corpseid = GetClosestActor(playerid, 2.0);
  184. if(corpseid == INVALID_ACTOR_ID) return SendErrorMessage(playerid, "You must get closer to that dead body.");
  185. if(!IsACorpse[corpseid]) return SendErrorMessage(playerid, "That's not a corpse.");
  186. Corpse_ShowInjuries(playerid, corpseid);
  187. }
  188. else if(!strcmp(params, "trunk", true, 5))
  189. {
  190. new option[6];
  191. if(sscanf(params, "{s[6]}s[128]", option)) return SendSyntaxMessage(playerid, "/corpse trunk (options: place, get)");
  192. if(!strcmp(option, "place", true))
  193. {
  194. if(DraggingCorpse[playerid] == INVALID_ACTOR_ID || !IsValidActor(DraggingCorpse[playerid]))
  195. return SendErrorMessage(playerid, "You're not carrying a dead body.");
  196. new vehicleid = GetClosestVehicle(playerid, 2.0);
  197. if(vehicleid == INVALID_VEHICLE_ID) return SendErrorMessage(playerid, "You must get closer to that vehicle.");
  198. new corpseid = DraggingCorpse[playerid];
  199. if(ValidCorpseTD[corpseid])
  200. {
  201. Delete3DTextLabel(CorpseTD[corpseid]);
  202. ValidCorpseTD[corpseid] = false;
  203. }
  204. DestroyActor(corpseid);
  205. DraggingCorpse[playerid] = INVALID_ACTOR_ID;
  206. // To be continued
  207. }
  208. else if(!strcmp(option, "get", true))
  209. {
  210. if(IsPlayerWounded(playerid)) return SendErrorMessage(playerid, "You can't do this when you're brutally wounded.");
  211. if(DraggingCorpse[playerid] != INVALID_ACTOR_ID) return SendErrorMessage(playerid, "You're already carrying a dead body.");
  212. new vehicleid = GetClosestVehicle(playerid, 2.0);
  213. if(vehicleid == INVALID_VEHICLE_ID) return SendErrorMessage(playerid, "You must get closer to that vehicle.");
  214. // To be continued
  215. }
  216. else SendSyntaxMessage(playerid, "/corpse trunk (options: place, get)");
  217. }
  218. else SendSyntaxMessage(playerid, "/corpse (options: carry, drop, examine, trunk)");
  219. return 1;
  220. }