Guest User

Untitled

a guest
Jan 5th, 2009
2,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define MAX_BEEPS 15 //How many times a vehicle beeps before the beeping stops
  4. #define BEEP_INTERVAL 1 //How many seconds between beeps, 1 second is realistic.
  5. #define COLOR_FAIL 0xFF0000AA
  6. #define COLOR_SUCCESS 0x33AA33AA
  7.  
  8. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  9.  
  10. new alarmed[MAX_VEHICLES];
  11. new beeps[MAX_VEHICLES];
  12. new Float:vehX,Float:vehY,Float:vehZ;
  13. new driverid;
  14. new BEEP_VOLUME = 16; //Volume of the beep
  15.  
  16. forward Alarm(vehicleid,toggle);
  17. forward beeper(veh);
  18.  
  19. public OnFilterScriptInit()
  20. {
  21. //Examples
  22. Alarm(1,1); //Activate the alarm on vehicle 1
  23. Alarm(2,1); //Activate the alarm on vehicle 2
  24. Alarm(3,1); //Activate the alarm on vehicle 3
  25. Alarm(4,1); //Activate the alarm on vehicle 4
  26. /*Please note: These are only example, you may want to remove them!*/
  27. return 1;
  28. }
  29.  
  30. public OnPlayerCommandText(playerid, cmdtext[])
  31. {
  32. dcmd(alarm,5,cmdtext);
  33. dcmd(alarmend,8,cmdtext);
  34. return 0;
  35. }
  36.  
  37. dcmd_alarm(playerid,params[])
  38. {
  39. if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /Alarm [VEHICLEID]");
  40. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be an RCON Administrator to use this command!");
  41. new idx;
  42. new tmp[256];
  43. new str[128];
  44. tmp = strtok(params, idx);
  45. if(IsVehicleConnected(strval(tmp)))
  46. {
  47. if(alarmed[strval(tmp)] == 1)
  48. {
  49. alarmed[strval(tmp)] = 0;
  50. format(str, sizeof(str), "Vehicle %d alarm deactivated.",strval(tmp));
  51. SendClientMessage(playerid,COLOR_FAIL,str);
  52. }
  53. else if(alarmed[strval(tmp)] == 0)
  54. {
  55. alarmed[strval(tmp)] = 1;
  56. format(str, sizeof(str), "Vehicle %d alarm activated.",strval(tmp));
  57. SendClientMessage(playerid,COLOR_SUCCESS,str);
  58. }
  59. }
  60. else
  61. {
  62. format(str, sizeof(str), "Vehicle %d doesn't exist!",strval(tmp));
  63. SendClientMessage(playerid,COLOR_FAIL,str);
  64. }
  65. return 1;
  66. }
  67.  
  68. dcmd_alarmend(playerid,params[])
  69. {
  70. #pragma unused params
  71. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be an RCON Administrator to use this command!");
  72. new vehid = GetPlayerVehicleID(playerid);
  73. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be in a vehicle to use this command!");
  74. if(alarmed[vehid] == 0) return SendClientMessage(playerid, 0xFF0000AA, "This vehicle is not alarmed!");
  75. if(beeps[vehid] == MAX_BEEPS || beeps[vehid] == 0) return SendClientMessage(playerid, 0xFF0000AA, "This vehicle is not sounding an alarm!");
  76. beeps[vehid] = MAX_BEEPS-1;
  77. return 1;
  78. }
  79.  
  80. public OnPlayerStateChange(playerid, newstate, oldstate)
  81. {
  82. new veh;
  83. veh = GetPlayerVehicleID(playerid);
  84. if(GetPlayerState(playerid) == 2)
  85. {
  86. if(alarmed[veh] == 1)
  87. {
  88. SetTimerEx("beeper",BEEP_INTERVAL*1000, false, "i", veh);
  89. }
  90. }
  91. return 1;
  92. }
  93.  
  94. public Alarm(vehicleid,toggle)
  95. {
  96. if(IsVehicleConnected(vehicleid))
  97. {
  98. alarmed[vehicleid] = toggle;
  99. }
  100. return 1;
  101. }
  102.  
  103. public beeper(veh)
  104. {
  105. if(beeps[veh] < MAX_BEEPS && alarmed[veh] == 1)
  106. {
  107. GetVehiclePos(veh,vehX,vehY,vehZ);
  108. driverid = GetVehicleDriver(veh);
  109. for(new x=0; x<BEEP_VOLUME; x++)
  110. {
  111. for(new i=0; i<MAX_PLAYERS; i++)
  112. {
  113. if(i != driverid) PlayerPlaySound(i, 1147, vehX,vehY,vehZ);
  114. if(i == driverid) PlayerPlaySound(i, 1147, 0.0,0.0,0.0);
  115. }
  116. }
  117. beeps[veh]++;
  118. SetTimerEx("beeper",BEEP_INTERVAL*1000, false, "i", veh);
  119. }
  120. return 1;
  121. }
  122.  
  123. public OnVehicleSpawn(vehicleid)
  124. {
  125. beeps[vehicleid] = 0;
  126. return 1;
  127. }
  128.  
  129. strtok(const string[], &index)
  130. {
  131. new length = strlen(string);
  132. while ((index < length) && (string[index] <= ' '))
  133. {
  134. index++;
  135. }
  136.  
  137. new offset = index;
  138. new result[20];
  139. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  140. {
  141. result[index - offset] = string[index];
  142. index++;
  143. }
  144. result[index - offset] = EOS;
  145. return result;
  146. }
  147.  
  148. stock IsVehicleConnected(vehicleid)
  149. {
  150. new Float:x1,Float:y1,Float:z1;
  151. GetVehiclePos(vehicleid,x1,y1,z1);
  152. if(x1==0.0 && y1==0.0 && z1==0.0)
  153. {
  154. return 0;
  155. }
  156. return 1;
  157. }
  158.  
  159. stock GetVehicleDriver(vehicleid)
  160. {
  161. for(new i; i<MAX_PLAYERS; i++)
  162. {
  163. if (IsPlayerInVehicle(i, vehicleid))
  164. {
  165. if(GetPlayerState(i) == 2)
  166. {
  167. return i;
  168. }
  169. }
  170. }
  171. return -1;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment