Guest User

[FS]Seatbelt and Helmet System by EzeeCube (good for RP serv

a guest
Oct 23rd, 2018
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. //this filterscript is made by EzeeCube, I don't care for credits if you need any help add me on skype peroplazar.
  2. //you are free to give me some reputation in samp forum xD
  3.  
  4. #include <a_samp>
  5. #include <foreach>
  6.  
  7. #define MODEL_ERROR 0
  8. #define MODEL_CAR 1
  9. #define MODEL_BIKE 2
  10. #define MODEL_MBIKE 3
  11. #define MODEL_BOAT 4
  12. #define MODEL_PLANE 5
  13.  
  14. #define ATTACH_PLAYER_SEATBELT 19314
  15. #define ATTACH_PLAYER_HELMET1 18978
  16. #define ATTACH_PLAYER_HELMET2 19102
  17.  
  18. #define COLOR_PURPLE 0xC2A2DAAA
  19.  
  20. new VehicleSafety[MAX_PLAYERS];
  21.  
  22. forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
  23.  
  24. stock GetName(playerid)
  25. {
  26. new name[24]; GetPlayerName(playerid, name, 24); return name;
  27. }
  28.  
  29. stock IsVehicleModel(modelid)//0 - error, 1 - car, 2 - bike, 3 - boat, 4 - plane/heli
  30. {
  31. //hidroplane
  32. switch(modelid)
  33. {
  34. case 0: return MODEL_ERROR;
  35. case 481,509,510: return MODEL_BIKE;
  36. case 448,461,462,463,468,471,521,522,523,581,586: return MODEL_MBIKE;
  37. case 430,446,452,453,454,472,473,484,493,595: return MODEL_BOAT;
  38. case 417,425,447,460,469,476,487,488,497,511,512,513,519,520,548,553,563,577,592,593: return MODEL_PLANE;
  39. default: return MODEL_CAR;
  40. }
  41. return 0;
  42. }
  43.  
  44. public OnPlayerStateChange(playerid, newstate, oldstate)
  45. {
  46. if(newstate == PLAYER_STATE_ONFOOT)
  47. {
  48. if(VehicleSafety[playerid] != 0)
  49. {
  50. new string[128];
  51. if(VehicleSafety[playerid] == 1) format(string, sizeof(string), "* %s reaches for their seatbelt, and unbuckles it.", GetName(playerid)), RemovePlayerAttachedObject(playerid,9);
  52. else if(VehicleSafety[playerid] == 2) format(string, sizeof(string), "* %s reaches for their helmet, and takes it off.", GetName(playerid)), RemovePlayerAttachedObject(playerid,9);
  53. ProxDetector(30.0, playerid, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
  54. VehicleSafety[playerid] = 0;
  55. RemovePlayerAttachedObject(playerid,9);
  56. }
  57. }
  58. return 1;
  59. }
  60. public OnPlayerExitVehicle(playerid, vehicleid)
  61. {
  62. if(VehicleSafety[playerid] != 0)
  63. {
  64. new string[128];
  65. if(VehicleSafety[playerid] == 1) format(string, sizeof(string), "* %s reaches for their seatbelt, and unbuckles it.", GetName(playerid)), RemovePlayerAttachedObject(playerid,9);
  66. else if(VehicleSafety[playerid] == 2) format(string, sizeof(string), "* %s reaches for their helmet, and takes it off.", GetName(playerid)), RemovePlayerAttachedObject(playerid,9);
  67. ProxDetector(30.0, playerid, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
  68. VehicleSafety[playerid] = 0;
  69. RemovePlayerAttachedObject(playerid,9);
  70. }
  71. return 1;
  72. }
  73. public OnVehicleDamageStatusUpdate(vehicleid, playerid)
  74. {
  75. new Float: v_HP;
  76. GetVehicleHealth(vehicleid, v_HP);
  77.  
  78. new Float: p_HP;
  79. GetPlayerHealth(playerid, p_HP);
  80.  
  81. if(VehicleSafety[playerid] == 1) SetPlayerHealth(playerid, p_HP - 1);
  82. else SetPlayerHealth(playerid, p_HP - 10);
  83. return 1;
  84. }
  85. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  86. {
  87. new string[128];
  88. if(newkeys & KEY_YES)
  89. {
  90. if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT)
  91. {
  92. new vehid = GetPlayerVehicleID(playerid);
  93. new model = GetVehicleModel(vehid);
  94. new vehicletype = IsVehicleModel(model);
  95. if(IsVehicleModel(model) == MODEL_CAR || vehicletype == MODEL_BIKE || vehicletype == MODEL_MBIKE)
  96. {
  97. if(VehicleSafety[playerid] == 0)
  98. {
  99. if(vehicletype == MODEL_BIKE) SetPlayerAttachedObject(playerid,9,ATTACH_PLAYER_HELMET2,2,0.15,0.00,0.00,0.0,0.0,0.0,1.14,1.10,1.11), format(string, sizeof(string), "* %s reaches for their helmet, and takes it on.", GetName(playerid)), VehicleSafety[playerid] = 2;
  100. else if(vehicletype == MODEL_MBIKE) SetPlayerAttachedObject(playerid,9,ATTACH_PLAYER_HELMET1,2,0.06,0.02,0.00,0.0,89.0,89.0,1.10,0.89,1.00), format(string, sizeof(string), "* %s reaches for their helmet, and takes it on.", GetName(playerid)), VehicleSafety[playerid] = 2;
  101. else if(vehicletype == MODEL_CAR) SetPlayerAttachedObject(playerid,9,ATTACH_PLAYER_SEATBELT,1,0.07,0.21,-0.00,-21.0,-54.0,183.0,0.39,0.40,0.31), format(string, sizeof(string), "* %s reaches for their seatbelt, and buckles it.", GetName(playerid)), VehicleSafety[playerid] = 1;
  102. }
  103. else if(VehicleSafety[playerid] == 1 || VehicleSafety[playerid] == 2)
  104. {
  105. VehicleSafety[playerid] = 0;
  106. RemovePlayerAttachedObject(playerid,9);
  107. if(vehicletype == MODEL_BIKE) format(string, sizeof(string), "* %s reaches for their helmet, and takes it off.", GetName(playerid));
  108. else if (vehicletype == MODEL_MBIKE) format(string, sizeof(string), "* %s reaches for their helmet, and takes it off.", GetName(playerid));
  109. else if(vehicletype == MODEL_CAR) format(string, sizeof(string), "* %s reaches for their seatbelt, and unbuckles it.", GetName(playerid));
  110. }
  111. ProxDetector(30.0, playerid, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
  112. return 1;
  113. }
  114. }
  115. }
  116. return 1;
  117. }
  118.  
  119. public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
  120. {
  121. if(IsPlayerConnected(playerid))
  122. {
  123. new Float:posx, Float:posy, Float:posz;
  124. new Float:oldposx, Float:oldposy, Float:oldposz;
  125. new Float:tempposx, Float:tempposy, Float:tempposz;
  126. GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  127.  
  128. foreach(new i:Player)
  129. {
  130. if(GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))
  131. {
  132. GetPlayerPos(i, posx, posy, posz);
  133. tempposx = (oldposx -posx);
  134. tempposy = (oldposy -posy);
  135. tempposz = (oldposz -posz);
  136. if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  137. {
  138. SendClientMessage(i, col1, string);
  139. }
  140. else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  141. {
  142. SendClientMessage(i, col2, string);
  143. }
  144. else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  145. {
  146. SendClientMessage(i, col3, string);
  147. }
  148. else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  149. {
  150. SendClientMessage(i, col4, string);
  151. }
  152. else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  153. {
  154. SendClientMessage(i, col5, string);
  155. }
  156. }
  157. }
  158. }//not connected
  159. return 1;
  160. }
Add Comment
Please, Sign In to add comment