Advertisement
Guest User

Castle

a guest
Dec 29th, 2009
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.22 KB | None | 0 0
  1. /*
  2. Seat Belt V1.0
  3. =>Created by Castle<=
  4. Thanks to Harry Gail for the Collision Function
  5. */
  6. #include <a_samp>
  7.  
  8. #define COLOR_GREY 0xB4B5B7FF
  9. #define COLOR_PURPLE 0xC2A2DAAA
  10. #define COLOR_LIGHTRED 0xFF6347AA
  11. #define INVALID_COLLISION_TIMER_ID -1
  12. #define COLLISION_TIMER_INTERVAL 100
  13. #define HPLOSS 3//the amount the player looses health for a collision
  14.  
  15. forward Sex(playerid);
  16. forward MotorBike(vehicleid);
  17. forward PlayerActionMessage(playerid,Float:radius,message[]);
  18. forward PlayerCollisionChecker(playerid, vehicleid, Float:previous_hp);
  19. forward OnPlayerCollide(playerid, vehicleid, Float:vehicle_health_loss);
  20. forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
  21.  
  22. new playerCollisionTimerId[MAX_PLAYERS];
  23. new Float:prevVehicleHealth[MAX_PLAYERS];
  24. new SeatBelt[MAX_PLAYERS];
  25. new BigEar[MAX_PLAYERS];
  26.  
  27. public OnFilterScriptInit()
  28. {
  29. print("__________________________________________________________________");
  30. print("| |");
  31. print("| Seat Belt V1.0 |");
  32. print("| =>Created by Castle<= |");
  33. print("| |");
  34. print("|________________________________________________________________|");
  35. return 1;
  36. }
  37.  
  38. public OnFilterScriptExit()
  39. {
  40. return 1;
  41. }
  42.  
  43. public OnPlayerConnect(playerid)
  44. {
  45. if(playerCollisionTimerId[playerid] != INVALID_COLLISION_TIMER_ID)//ensures the timers are killed properly
  46. {
  47. KillTimer(playerCollisionTimerId[playerid]);
  48. playerCollisionTimerId[playerid] = INVALID_COLLISION_TIMER_ID;
  49. }
  50. return 1;
  51. }
  52.  
  53. public OnPlayerCommandText(playerid, cmdtext[])
  54. {
  55. if(!strcmp(cmdtext,"/seatbelt",true,9)||!strcmp(cmdtext,"/sb",true,3))
  56. {
  57. if(MotorBike(GetPlayerVehicleID(playerid))){ return SendClientMessage(playerid,COLOR_GREY,"Bikes don't have seat belts you dummy!"); }
  58. else if(SeatBelt[playerid]!=1)
  59. {
  60. SeatBelt[playerid]=1;
  61. if(Sex(GetPlayerSkin(playerid))){ return PlayerActionMessage(playerid,30.0,"buckled his seat belt"); }
  62. else{ return PlayerActionMessage(playerid,30.0,"buckled her seat belt"); }
  63. }
  64. else if(SeatBelt[playerid]!=0)
  65. {
  66. SeatBelt[playerid]=0;
  67. if(Sex(GetPlayerSkin(playerid))){ return PlayerActionMessage(playerid,30.0,"unbuckled his seat belt"); }
  68. else{ return PlayerActionMessage(playerid,30.0,"unbuckled her seat belt"); }
  69. }
  70. }
  71. /* if(!strcmp(cmdtext,"/car",true,4)){ new Float:cX, Float:cY, Float:cZ, Float:cA; GetPlayerPos(playerid,Float:cX,Float:cY,Float:cZ); GetPlayerFacingAngle(playerid,Float:cA); new car=CreateVehicle(496,Float:cX,Float:cY,Float:cZ,Float:cA,1,1,999999); return PutPlayerInVehicle(playerid,car,0); }
  72. if(!strcmp(cmdtext,"/bike",true,5)){ new Float:bX, Float:bY, Float:bZ, Float:bA; GetPlayerPos(playerid,Float:bX,Float:bY,Float:bZ); GetPlayerFacingAngle(playerid,Float:bA); new bike=CreateVehicle(581,Float:bX,Float:bY,Float:bZ,Float:bA,1,1,999999); return PutPlayerInVehicle(playerid,bike,0); }
  73. if(!strcmp(cmdtext, "/hp", true,3))
  74. {
  75. new Float:H;
  76. GetPlayerHealth(playerid, H);
  77. new hpMSG[128];
  78. format(hpMSG, sizeof(hpMSG), "Your HP: %.1f", H);
  79. SendClientMessage(playerid, COLOR_GREY, hpMSG);
  80. return 1;
  81. }*/
  82. return 1;
  83. }
  84.  
  85. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  86. {
  87. return 1;
  88. }
  89.  
  90. public OnPlayerExitVehicle(playerid, vehicleid)
  91. {
  92. return 1;
  93. }
  94.  
  95. public OnPlayerStateChange(playerid, newstate, oldstate)
  96. {
  97. if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  98. {
  99. if(playerCollisionTimerId[playerid] != INVALID_COLLISION_TIMER_ID)
  100. KillTimer(playerCollisionTimerId[playerid]);// extra security purposes
  101.  
  102. new vehicle_id = GetPlayerVehicleID(playerid);
  103. new Float:vehicle_health;
  104.  
  105. GetVehicleHealth(vehicle_id, vehicle_health);
  106. prevVehicleHealth[playerid] = vehicle_health; // to prevent possible glitches
  107.  
  108. // start timer, player is certainly in a vehicle
  109. playerCollisionTimerId[playerid] = SetTimerEx("PlayerCollisionChecker", COLLISION_TIMER_INTERVAL, true, "ii", playerid, vehicle_id);
  110. }
  111. if( (newstate != oldstate) && (oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) )
  112. {
  113. // player is definitely out of vehicle (but was in vehicle previously)
  114. KillTimer(playerCollisionTimerId[playerid]);
  115. playerCollisionTimerId[playerid] = INVALID_COLLISION_TIMER_ID;
  116. SeatBelt[playerid]=0;
  117. if(Sex(GetPlayerSkin(playerid))){ return PlayerActionMessage(playerid,30.0,"unbuckled his seat belt"); }
  118. else{ return PlayerActionMessage(playerid,30.0,"unbuckled her seat belt"); }
  119. }
  120. return 1;
  121. }
  122.  
  123. public PlayerCollisionChecker(playerid, vehicleid)
  124. {
  125. new Float:newhp;
  126. GetVehicleHealth(vehicleid, newhp);
  127.  
  128. if(prevVehicleHealth[playerid] - newhp > 0)
  129. {
  130. OnPlayerCollide(playerid, vehicleid, prevVehicleHealth[playerid] - newhp);
  131. }
  132. prevVehicleHealth[playerid] = newhp;
  133. return 1;
  134. }
  135.  
  136. public OnPlayerCollide(playerid, vehicleid, Float:vehicle_health_loss)
  137. {
  138. new Float:pHP;
  139. if(SeatBelt[playerid]==0)
  140. {
  141. GetPlayerHealth(playerid,pHP);
  142. return SetPlayerHealth(playerid,pHP-HPLOSS);
  143. }
  144. return 1;
  145. }
  146.  
  147. public Sex(playerid)
  148. { new pSex = GetPlayerSkin(playerid);
  149. if( pSex == 0 || pSex == 106 || pSex == 107 || pSex == 102 || pSex == 103 || pSex == 104 || pSex == 114 || pSex == 115 || pSex == 116 || pSex == 108 || pSex == 109 || pSex == 110 || pSex == 121 || pSex == 122 || pSex == 123 || pSex == 173 || pSex == 174 || pSex == 175 || pSex == 117 || pSex == 118 || pSex == 120 || pSex == 100 || pSex == 247 || pSex == 248 || pSex == 254 || pSex == 111 || pSex == 112 || pSex == 113 || pSex == 124 || pSex == 125 || pSex == 126 ||
  150. pSex == 127 || pSex == 163 || pSex == 164 || pSex == 165 || pSex == 166 || pSex == 274 || pSex == 275 || pSex == 276 || pSex == 277 || pSex == 278 || pSex == 279 || pSex == 280 || pSex == 281 || pSex == 282 || pSex == 283 || pSex == 284 || pSex == 285 || pSex == 286 || pSex == 287 || pSex == 288 || pSex == 146 || pSex == 154 || pSex == 97 || pSex == 45 || pSex == 18 || pSex == 128 || pSex == 132 || pSex == 33 || pSex == 58 || pSex == 59 || pSex == 160 || pSex == 161 ||
  151. pSex == 162 || pSex == 200 || pSex == 202 || pSex == 32 || pSex == 33 || pSex == 34 || pSex == 258 || pSex == 259 || pSex == 26 || pSex == 51 || pSex == 52 || pSex == 80 || pSex == 81 || pSex == 23 || pSex == 96 || pSex == 99 || pSex == 147 || pSex == 153 || pSex == 167 || pSex == 68 || pSex == 171 || pSex == 176 || pSex == 177 || pSex == 179 || pSex == 187 || pSex == 189 || pSex == 203 || pSex == 204 || pSex == 155 || pSex == 209 || pSex == 217 || pSex == 260 || pSex == 16 ||
  152. pSex == 27 || pSex == 264 || pSex == 70 || pSex == 134 || pSex == 135 || pSex == 137 || pSex == 181 || pSex == 213 || pSex == 212 || pSex == 230 || pSex == 239 || pSex == 249 || pSex == 241 || pSex == 242 || pSex == 252 || pSex == 253 || pSex == 255 || pSex == 29 || pSex == 30 || pSex == 49 || pSex == 50 || pSex == 57 || pSex == 61 || pSex == 62 || pSex == 66 || pSex == 73 || pSex == 78 || pSex == 78 || pSex == 82 || pSex == 83 || pSex == 84 || pSex == 101 || pSex == 136 || pSex == 14 ||
  153. pSex == 142 || pSex == 143 || pSex == 144 || pSex == 15 || pSex == 156 || pSex == 168 || pSex == 17 || pSex == 170 || pSex == 180 || pSex == 182 || pSex == 183 || pSex == 184 || pSex == 186 || pSex == 185 || pSex == 188 || pSex == 19 || pSex == 20 || pSex == 206 || pSex == 21 || pSex == 22 || pSex == 210 || pSex == 220 || pSex == 221 || pSex == 222 || pSex == 223 || pSex == 227 || pSex == 228 || pSex == 234 || pSex == 235 || pSex == 236 || pSex == 24 || pSex == 240 || pSex == 25 || pSex == 261 ||
  154. pSex == 28 || pSex == 35 || pSex == 37 || pSex == 36 || pSex == 44 || pSex == 46 || pSex == 48 || pSex == 47 || pSex == 262 || pSex == 229 || pSex == 58 || pSex == 59 || pSex == 60 || pSex == 67 || pSex == 7 || pSex == 72 || pSex == 94 || pSex == 95 || pSex == 98 || pSex == 265 || pSex == 266 || pSex == 267 || pSex == 269 || pSex == 270 || pSex == 271 || pSex == 272)
  155. {
  156. return 1;
  157. }
  158. return 0;
  159. }
  160.  
  161. public MotorBike(vehicleid)
  162. { new pModel=GetVehicleModel(vehicleid);
  163. if(pModel==581 || pModel==509 || pModel==481 || pModel==462 || pModel==521 || pModel==463 || pModel==510 || pModel==522 || pModel==461 || pModel==448 || pModel==471 || pModel==468 || pModel==586) { return 1; }
  164. return 0;
  165. }
  166.  
  167. stock GetPlayerNameEx(playerid)
  168. {
  169. new string[24];
  170. GetPlayerName(playerid,string,24);
  171. new str[24];
  172. strmid(str,string,0,strlen(string),24);
  173. for(new i = 0; i < MAX_PLAYER_NAME; i++)
  174. {
  175. if (str[i] == '_') str[i] = ' ';
  176. }
  177. return str;
  178. }
  179.  
  180. public PlayerActionMessage(playerid,Float:radius,message[])
  181. {
  182. new string[128];
  183. format(string, sizeof(string), "* %s %s", GetPlayerNameEx(playerid), message);
  184. ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  185. return 1;
  186. }
  187.  
  188. public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
  189. {
  190. if(IsPlayerConnected(playerid))
  191. {
  192. new Float:posx, Float:posy, Float:posz;
  193. new Float:oldposx, Float:oldposy, Float:oldposz;
  194. new Float:tempposx, Float:tempposy, Float:tempposz;
  195. GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  196. for(new i = 0; i < MAX_PLAYERS; i++)
  197. {
  198. if(IsPlayerConnected(i))
  199. {
  200. if(!BigEar[i])
  201. {
  202. GetPlayerPos(i, posx, posy, posz);
  203. tempposx = (oldposx -posx);
  204. tempposy = (oldposy -posy);
  205. tempposz = (oldposz -posz);
  206. if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  207. {
  208. if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
  209. {
  210. SendClientMessage(i, col1, string);
  211. }
  212. }
  213. else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  214. {
  215. if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
  216. {
  217. SendClientMessage(i, col2, string);
  218. }
  219. }
  220. else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  221. {
  222. if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
  223. {
  224. SendClientMessage(i, col3, string);
  225. }
  226. }
  227. else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  228. {
  229. if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
  230. {
  231. SendClientMessage(i, col4, string);
  232. }
  233. }
  234. else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  235. {
  236. if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
  237. {
  238. SendClientMessage(i, col5, string);
  239. }
  240. }
  241. }
  242. else
  243. {
  244. SendClientMessage(i, col1, string);
  245. }
  246. }
  247. }
  248. }
  249. return 1;
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement