Advertisement
Guest User

Castle

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