Guest User

radar

a guest
Aug 1st, 2012
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.22 KB | None | 0 0
  1. /*
  2. Skripta -->> ©Gamer931215
  3. Prijedlozi -->> HighFlyer
  4. Editirano i prevedeno na hrvatski -->> LG
  5. */
  6. #include <a_samp>
  7. #include <zcmd>
  8. #include <YSI\y_ini>
  9. //===================================================================================================
  10. // Settings
  11. //===================================================================================================
  12. // SETTING: VALUE: Discription:
  13.  
  14. #define CAMERA_LIMIT 100 //Max loaded cameras (keep this as low as possible for the best performance)
  15. #define CAMERA_UPDATE_INTERVAL 750 //update interval of all speedcams (in miliseconds)
  16. #define CAMERA_FLASH_TIME 1200 //ammount of miliseconds until the "flash" effect gets removed again
  17. #define CAMERA_DIALOG_RANGE 1337 //dialog ID range (Example: 0 will take dialogid's 0 - 9)
  18. #define CAMERA_USEMPH 0 //toggles camera using mph by default (0=kmh, 1=mph)
  19. #define CAMERA_LABEL_COLOR 0xFF000FFF //The default color of the camera's label
  20. #define CAMERA_PERSPECTIVE false //Sets playercamera temporary at the camera's position while flashing
  21.  
  22. //streamer options (will be used if STREAMER_ENABLED is set on true)
  23. #define STREAMER_ENABLED false //uses a streamer (true/false)
  24. #define STREAMER_ADD CreateDynamicObject //put here at the value the command your streamer uses to make an object (CreateDynamicObject by default)
  25. #define STREAMER_REMOVE DestroyDynamicObject //put here at the value the command your streamer uses to remove an object (STREAMER_REMOVE by default)
  26. #if STREAMER_ENABLED == true //ignore this line
  27. #include streamer //put your include name here
  28. #endif //ignore this line
  29. //===================================================================================================
  30. // Variables
  31. //===================================================================================================
  32. #define DIALOG_MAIN CAMERA_DIALOG_RANGE
  33. #define DIALOG_RANGE CAMERA_DIALOG_RANGE +1
  34. #define DIALOG_LIMIT CAMERA_DIALOG_RANGE +2
  35. #define DIALOG_FINE CAMERA_DIALOG_RANGE +3
  36. #define DIALOG_EDIT CAMERA_DIALOG_RANGE +4
  37. #define DIALOG_EANGLE CAMERA_DIALOG_RANGE +5
  38. #define DIALOG_ELIMIT CAMERA_DIALOG_RANGE +6
  39. #define DIALOG_ERANGE CAMERA_DIALOG_RANGE +7
  40. #define DIALOG_EFINE CAMERA_DIALOG_RANGE +8
  41. #define DIALOG_ETYPE CAMERA_DIALOG_RANGE +9
  42. #define DIALOG_LABEL CAMERA_DIALOG_RANGE +10
  43. #define COLOR_RED 0xFF1E00FF
  44. #define COLOR_GREEN 0x05FF00FF
  45. enum _camera
  46. {Float:_x,Float:_y,Float:_z,Float:_rot,_range,_limit,_fine,_usemph,_objectid,bool:_active,bool:_activelabel,_labeltxt[128],Text3D:_label}
  47. new SpeedCameras[CAMERA_LIMIT][_camera],loaded_cameras = 0,Text:flash;
  48. //stocks for attaching labels to camera (must be defined before use, thats why this one is at the top)
  49. stock Text3D:AttachLabelToCamera(cameraid,text[])
  50. {
  51. new position,buffer[128];format(buffer,sizeof buffer,"%s",text);
  52. for(new i = 0;strfind(buffer,"\\n",true) != -1;i++)
  53. {
  54. position = strfind(buffer,"\\n",true);
  55. strdel(buffer,position,position +2);
  56. strins(buffer,"\r\n",position,sizeof(buffer));
  57. }
  58. return Create3DTextLabel(buffer,CAMERA_LABEL_COLOR,SpeedCameras[cameraid][_x],SpeedCameras[cameraid][_y],SpeedCameras[cameraid][_z] +7,100,0,0);
  59. }
  60. stock UpdateCameraLabel(Text3D:labelid,text[])
  61. {
  62. new position,buffer[128];format(buffer,sizeof buffer,"%s",text);
  63. for(new i = 0;strfind(buffer,"\\n",true) != -1;i++)
  64. {
  65. position = strfind(buffer,"\\n",true);
  66. strdel(buffer,position,position +2);
  67. strins(buffer,"\r\n",position,sizeof(buffer));
  68. }
  69. return Update3DTextLabelText(labelid,CAMERA_LABEL_COLOR,buffer);
  70. }
  71. //===================================================================================================
  72. // Initialize
  73. //===================================================================================================
  74. public OnFilterScriptInit()
  75. {
  76. SetTimer("UpdateCameras",CAMERA_UPDATE_INTERVAL,true);
  77. flash = TextDrawCreate(-20.000000,2.000000,"|");
  78. TextDrawUseBox(flash,1);
  79. TextDrawBoxColor(flash,0xffffff66);
  80. TextDrawTextSize(flash,660.000000,22.000000);
  81. TextDrawAlignment(flash,0);
  82. TextDrawBackgroundColor(flash,0x000000ff);
  83. TextDrawFont(flash,3);
  84. TextDrawLetterSize(flash,1.000000,52.200000);
  85. TextDrawColor(flash,0xffffffff);
  86. TextDrawSetOutline(flash,1);
  87. TextDrawSetProportional(flash,1);
  88. TextDrawSetShadow(flash,1);
  89. print("====================================");
  90. print("| gCamera V1.0 |");
  91. print("| ©Gamer931215 |");
  92. print("| Edit by LG |");
  93. print("====================================");
  94. print("Initializing...");
  95. LoadCameras();
  96. return 1;
  97. }
  98. public OnFilterScriptExit()
  99. {
  100. print("====================================");
  101. print("| gCamera V1.0 |");
  102. print("| ©Gamer931215 |");
  103. print("| Edit by LG |");
  104. print("====================================");
  105. RemoveCameras();
  106. print("All cameras have been removed.");
  107. return 1;
  108. }
  109. //===================================================================================================
  110. // Commands
  111. //===================================================================================================
  112. COMMAND:radar(playerid,params[])
  113. {
  114. if(!IsPlayerAdmin(playerid)) return 0;
  115. ShowPlayerDialog(playerid,DIALOG_MAIN,DIALOG_STYLE_LIST,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}glavni izbornik","{37FF00}Stvori radar\n\nID najblizeg radara\nUredi najblizi radar\n{FF1400}Unisti najblizi radar\n{FF1400}Unisti sve radare","Uredu","Ponisti");
  116. return 1;
  117. }
  118.  
  119. //===================================================================================================
  120. // Callbacks
  121. //===================================================================================================
  122. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  123. {
  124. if(!response) {
  125. DeletePVar(playerid,"range");
  126. DeletePVar(playerid,"limit");
  127. DeletePVar(playerid,"fine");
  128. DeletePVar(playerid,"selected");
  129. return 1;
  130. }
  131. switch(dialogid)
  132. {
  133. //======================================================
  134. // Main menu
  135. //======================================================
  136. case DIALOG_MAIN:
  137. {
  138. switch(listitem)
  139. {
  140. case 0: ShowPlayerDialog(playerid,DIALOG_RANGE,DIALOG_STYLE_INPUT,"Insert a range","Please insert a range (recommended: 20-30)","OK","Cancel");
  141. case 1:
  142. {
  143. new cam = GetClosestCamera(playerid);
  144. if(cam == -1) return SendClientMessage(playerid,COLOR_RED,"Nisi u blizini niti jednog radara!");
  145. SendClientMessageEx(playerid,COLOR_GREEN,"sis","ID najblizeg radara je: ",cam,".");
  146. }
  147. case 2:
  148. {
  149. new cam = GetClosestCamera(playerid);
  150. if(cam == -1) return SendClientMessage(playerid,COLOR_RED,"Nisi u blizini niti jednog radara!");
  151. SetPVarInt(playerid,"selected",cam);
  152. ShowPlayerDialog(playerid,DIALOG_EDIT,DIALOG_STYLE_LIST,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje","Promijeni kut\nPromijeni daljinu\nPromijeni max brzinu\nPromijeni kaznu\nUkljuci/iskljuci MPH mod\nDodaj/Obrisi/Uredi 3D Text Label\n{FF1400}Obrisi kameru","Uredu","Ponisti");
  153. }
  154. case 3:
  155. {
  156. new cam = GetClosestCamera(playerid);
  157. if(cam == -1) return SendClientMessage(playerid,COLOR_RED,"Nisi u blizini niti jednog radara!");
  158. DestroySpeedCam(cam);
  159. SendClientMessage(playerid,COLOR_GREEN,"Radar unisten.");
  160. DeletePVar(playerid,"selected");
  161. }
  162. case 4:
  163. {
  164. for(new i = 0;i<loaded_cameras +1;i++)
  165. {
  166. if(SpeedCameras[i][_active] == true)
  167. {
  168. DestroySpeedCam(i);
  169. }
  170. }
  171. SendClientMessage(playerid,COLOR_GREEN,"Svi radari unisteni.");
  172. }
  173. }
  174. }
  175. //======================================================
  176. // Making a speedcam
  177. //======================================================
  178. case DIALOG_RANGE:
  179. {
  180. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_RANGE,DIALOG_STYLE_INPUT,"Unesite daljinu","Unesite daljinu snimanja radara (preporuceno: 20-30)","Uredu","Ponisti");
  181. SetPVarInt(playerid,"range",strval(inputtext));
  182. ShowPlayerDialog(playerid,DIALOG_LIMIT,DIALOG_STYLE_INPUT,"Unesi max brzinu","Maximalna brzina:","Uredu","Ponisti");
  183. }
  184. case DIALOG_LIMIT:
  185. {
  186. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LIMIT,DIALOG_STYLE_INPUT,"Unesi max brzinu","Maximalna brzina:","Uredu","Ponisti");
  187. SetPVarInt(playerid,"limit",strval(inputtext));
  188. ShowPlayerDialog(playerid,DIALOG_FINE,DIALOG_STYLE_INPUT,"Unesi kaznu","Kazna:","Uredu","Ponisti");
  189. }
  190. case DIALOG_FINE:
  191. {
  192. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_FINE,DIALOG_STYLE_INPUT,"Unesi kaznu","Kazna:","Uredu","Ponisti");
  193. SetPVarInt(playerid,"fine",strval(inputtext));
  194. new Float:x,Float:y,Float:z,Float:angle;
  195. GetPlayerPos(playerid,x,y,z);GetPlayerFacingAngle(playerid,angle);
  196. angle = angle + 180;if(angle > 360){angle = angle - 360;}
  197. new id = CreateSpeedCam(x,y,z -3,angle,GetPVarInt(playerid,"range"),GetPVarInt(playerid,"limit"),GetPVarInt(playerid,"fine"),CAMERA_USEMPH);
  198. SetPlayerPos(playerid,x,y+2,z);
  199. DeletePVar(playerid,"range");
  200. DeletePVar(playerid,"limit");
  201. DeletePVar(playerid,"fine");
  202. SetPVarInt(playerid,"selected",id);
  203. ShowPlayerDialog(playerid,DIALOG_EDIT,DIALOG_STYLE_LIST,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje","Promijeni kut\nPromijeni daljinu\nPromijeni max brzinu\nPromijeni kaznu\nUkljuci/iskljuci MPH mod\nDodaj/Obrisi/Uredi 3D Text Label\n{FF1400}Obrisi kameru","Uredu","Ponisti");
  204. }
  205.  
  206. //======================================================
  207. // Edit menu
  208. //======================================================
  209. case DIALOG_EDIT:
  210. {
  211. switch(listitem)
  212. {
  213. case 0: ShowPlayerDialog(playerid,DIALOG_EANGLE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Kut","Unesite novi kut","Uredu","Ponisti");
  214. case 1: ShowPlayerDialog(playerid,DIALOG_ERANGE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Daljina","Unesite novu daljinu snimanja","Uredu","Ponisti");
  215. case 2: ShowPlayerDialog(playerid,DIALOG_ELIMIT,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Maximalna brzina","Unesite novu max brzinu","Uredu","Ponisti");
  216. case 3: ShowPlayerDialog(playerid,DIALOG_EFINE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Kazna","Unesite novu kaznu","Uredu","Ponisti");
  217. case 4: ShowPlayerDialog(playerid,DIALOG_ETYPE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Mph/Kmh","Unesite 1 za MPH ili 0 za KMH","Uredu","Ponisti");
  218. case 5: ShowPlayerDialog(playerid,DIALOG_LABEL,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - 3D Text Label","Upisite text ili ostavite prazno polje!","Uredu","Ponisti");
  219. case 6:
  220. {
  221. DestroySpeedCam(GetPVarInt(playerid,"selected"));
  222. SendClientMessage(playerid,COLOR_GREEN,"Kamera je obrisana.");
  223. DeletePVar(playerid,"selected");
  224. }
  225. }
  226. }
  227.  
  228. //======================================================
  229. // Editing a speedcam
  230. //======================================================
  231. case DIALOG_EANGLE:
  232. {
  233. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_EANGLE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Kut","Unesite novi kut","Uredu","Ponisti");
  234. new id = GetPVarInt(playerid,"selected");
  235. new rot = strval(inputtext);
  236. rot = rot + 180;
  237. if (rot > 360)
  238. {
  239. rot = rot - 360;
  240. }
  241. SpeedCameras[id][_rot] = rot;
  242. SetObjectRot(SpeedCameras[id][_objectid],0,0,rot);
  243. SaveCamera(id);
  244. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","Kut radara ",id," je uspjesno promijenjen u ",strval(inputtext),".");
  245. }
  246. case DIALOG_ERANGE:
  247. {
  248. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_ERANGE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Daljina","Unesite novu daljinu snimanja","Uredu","Ponisti");
  249. new id = GetPVarInt(playerid,"selected");
  250. SpeedCameras[id][_range] = strval(inputtext);
  251. SaveCamera(id);
  252. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","Udaljenost snimanja kamere ",id," je uspijesno promijenjen u ",strval(inputtext),".");
  253. }
  254. case DIALOG_ELIMIT:
  255. {
  256. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_ELIMIT,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Maximalna brzina","Unesite novu max brzinu","Uredu","Ponisti");
  257. new id = GetPVarInt(playerid,"selected");
  258. SpeedCameras[id][_limit] = strval(inputtext);
  259. SaveCamera(id);
  260. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","Maximalna brzina radara ",id," je uspijesno promijenjena u ",strval(inputtext),".");
  261. }
  262. case DIALOG_EFINE:
  263. {
  264. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_EFINE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Kazna","Unesite novu kaznu","Uredu","Ponisti");
  265. new id = GetPVarInt(playerid,"selected");
  266. SpeedCameras[id][_fine] = strval(inputtext);
  267. SaveCamera(id);
  268. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","Kazna radara ",GetPVarInt(playerid,"selected")," je uspijesno promijenjena u ",strval(inputtext),".");
  269. }
  270. case DIALOG_ETYPE:
  271. {
  272. if(!strlen(inputtext) || strval(inputtext) != 0 && strval(inputtext) != 1) return ShowPlayerDialog(playerid,DIALOG_ETYPE,DIALOG_STYLE_INPUT,"{00A5FF}Opcije radara {FFFFFF}- {FFDC00}Uredjivanje - Mph/Kmh","Unesite 1 za MPH ili 0 za KMH","Uredu","Ponisti");
  273. new id = GetPVarInt(playerid,"selected");
  274. SpeedCameras[id][_usemph] = strval(inputtext);
  275. if(strval(inputtext) == 1)
  276. {
  277. SendClientMessageEx(playerid,COLOR_GREEN,"sis","Radar ",GetPVarInt(playerid,"selected")," ce sada racunati brzinu u MPH.");
  278. } else {
  279. SendClientMessageEx(playerid,COLOR_GREEN,"sis","Radar ",GetPVarInt(playerid,"selected")," ce sada racunati brzinu u KMH.");
  280. }
  281. }
  282. case DIALOG_LABEL:
  283. {
  284. new id = GetPVarInt(playerid,"selected");
  285. if(!strlen(inputtext))
  286. {
  287. if(SpeedCameras[id][_activelabel] == true)
  288. {
  289. Delete3DTextLabel(SpeedCameras[id][_label]);
  290. SpeedCameras[id][_activelabel] = false;
  291. SpeedCameras[id][_labeltxt] = 0;
  292. }
  293. SendClientMessageEx(playerid,COLOR_GREEN,"sis","3D Text Label radara ",GetPVarInt(playerid,"selected")," je uspijesno unisten.");
  294. } else {
  295. if(SpeedCameras[id][_activelabel] == true)
  296. {
  297. format(SpeedCameras[id][_labeltxt],128,"%s",inputtext);
  298. UpdateCameraLabel(SpeedCameras[id][_label],inputtext);
  299. } else {
  300. SpeedCameras[id][_activelabel] = true;
  301. format(SpeedCameras[id][_labeltxt],128,"%s",inputtext);
  302. SpeedCameras[id][_label] = AttachLabelToCamera(id,inputtext);
  303. }
  304. SendClientMessageEx(playerid,COLOR_GREEN,"sisss","3D Text Label radara ",GetPVarInt(playerid,"selected")," je uspijesno promijenjen u ",inputtext,".");
  305. }
  306. SaveCamera(id);
  307. }
  308. }
  309. return 0;
  310. }
  311. //===================================================================================================
  312. // Functions
  313. //===================================================================================================
  314. stock LoadCameras()
  315. {
  316. new file[64];
  317. for(new i = 0;i<CAMERA_LIMIT;i++)
  318. {
  319. format(file,sizeof file,"/SpeedCameras/%i.txt",i);
  320. if(fexist(file))
  321. {
  322. INI_ParseFile(file,"LoadCam",.bExtra = true,.extra = i);
  323. #if STREAMER_ENABLED == true
  324. SpeedCameras[i][_objectid] = STREAMER_ADD(18880,SpeedCameras[i][_x],SpeedCameras[i][_y],SpeedCameras[i][_z],0,0,SpeedCameras[i][_rot]);
  325. #else
  326. SpeedCameras[i][_objectid] = CreateObject(18880,SpeedCameras[i][_x],SpeedCameras[i][_y],SpeedCameras[i][_z],0,0,SpeedCameras[i][_rot]);
  327. #endif
  328. SpeedCameras[i][_active] = true;
  329. if(SpeedCameras[i][_activelabel] == true)
  330. {
  331. SpeedCameras[i][_label] = AttachLabelToCamera(i,SpeedCameras[i][_labeltxt]);
  332. }
  333. loaded_cameras++;
  334. }
  335. }
  336. printf("gCamera has succesfully loaded %i camera(s).",loaded_cameras);
  337. }
  338. forward LoadCam(cameraid,name[],value[]);
  339. public LoadCam(cameraid,name[],value[])
  340. {
  341. INI_Float("_x",SpeedCameras[cameraid][_x]);
  342. INI_Float("_y",SpeedCameras[cameraid][_y]);
  343. INI_Float("_z",SpeedCameras[cameraid][_z]);
  344. INI_Float("_rot",SpeedCameras[cameraid][_rot]);
  345. INI_Int("_range",SpeedCameras[cameraid][_range]);
  346. INI_Int("_limit",SpeedCameras[cameraid][_limit]);
  347. INI_Int("_fine",SpeedCameras[cameraid][_fine]);
  348. INI_Int("_usemph",SpeedCameras[cameraid][_usemph]);
  349. INI_Bool("_activelabel",SpeedCameras[cameraid][_activelabel]);
  350. INI_String("_labeltxt",SpeedCameras[cameraid][_labeltxt],128);
  351. return 1;
  352. }
  353. stock RemoveCameras()
  354. {
  355. for(new i = 0;i<loaded_cameras +1;i++)
  356. {
  357. if(SpeedCameras[i][_active] == true)
  358. {
  359. #if STREAMER_ENABLED == true
  360. STREAMER_REMOVE(SpeedCameras[i][_objectid]);
  361. #else
  362. DestroyObject(SpeedCameras[i][_objectid]);
  363. #endif
  364. if(SpeedCameras[i][_activelabel] == true)
  365. {
  366. Delete3DTextLabel(SpeedCameras[i][_label]);
  367. }
  368. }
  369. }
  370. return 1;
  371. }
  372. stock generate_id()
  373. {
  374. new file[64];
  375. for(new i = 0;i<CAMERA_LIMIT;i++)
  376. {
  377. format(file,sizeof file,"/SpeedCameras/%i.txt",i);
  378. if(!fexist(file)) return i;
  379. }
  380. return -1;
  381. }
  382. stock CreateSpeedCam(Float:x,Float:y,Float:z,Float:rot,range,limit,fine,use_mph = 0)
  383. {
  384. new newid = generate_id();
  385. if(newid == -1)
  386. {
  387. print("Radar: GRASKA! Nije moguce stvoriti radar jer ih vec ima previse!");
  388. return 1;
  389. }
  390. if (newid == loaded_cameras || newid > loaded_cameras)
  391. {
  392. loaded_cameras++;
  393. }
  394. SpeedCameras[newid][_x] = x;
  395. SpeedCameras[newid][_y] = y;
  396. SpeedCameras[newid][_z] = z;
  397. SpeedCameras[newid][_rot] = rot;
  398. SpeedCameras[newid][_range] = range;
  399. SpeedCameras[newid][_limit] = limit;
  400. SpeedCameras[newid][_fine] = fine;
  401. SpeedCameras[newid][_usemph] = use_mph;
  402. #if STREAMER_ENABLED == true
  403. SpeedCameras[newid][_objectid] = STREAMER_ADD(18880,x,y,z,0,0,rot);
  404. #else
  405. SpeedCameras[newid][_objectid] = CreateObject(18880,x,y,z,0,0,rot);
  406. #endif
  407. SpeedCameras[newid][_active] = true;
  408. SpeedCameras[newid][_activelabel] = false;
  409. SpeedCameras[newid][_labeltxt] = 0;
  410. new file[64];format(file,sizeof file,"/SpeedCameras/%i.txt",newid);
  411. new INI:handler = INI_Open(file);
  412. INI_WriteFloat(handler,"_x",SpeedCameras[newid][_x]);
  413. INI_WriteFloat(handler,"_y",SpeedCameras[newid][_y]);
  414. INI_WriteFloat(handler,"_z",SpeedCameras[newid][_z]);
  415. INI_WriteFloat(handler,"_rot",SpeedCameras[newid][_rot]);
  416. INI_WriteInt(handler,"_range",SpeedCameras[newid][_range]);
  417. INI_WriteInt(handler,"_limit",SpeedCameras[newid][_limit]);
  418. INI_WriteInt(handler,"_fine",SpeedCameras[newid][_fine]);
  419. INI_WriteInt(handler,"_usemph",SpeedCameras[newid][_usemph]);
  420. INI_WriteBool(handler,"_activelabel",SpeedCameras[newid][_activelabel]);
  421. INI_WriteString(handler,"_labeltxt",SpeedCameras[newid][_labeltxt]);
  422. INI_Close(handler);
  423. return newid;
  424. }
  425. stock SaveCamera(cameraid)
  426. {
  427. new file[64];format(file,sizeof file,"/SpeedCameras/%i.txt",cameraid);
  428. new INI:handler = INI_Open(file);
  429. INI_WriteFloat(handler,"_x",SpeedCameras[cameraid][_x]);
  430. INI_WriteFloat(handler,"_y",SpeedCameras[cameraid][_y]);
  431. INI_WriteFloat(handler,"_z",SpeedCameras[cameraid][_z]);
  432. INI_WriteFloat(handler,"_rot",SpeedCameras[cameraid][_rot]);
  433. INI_WriteInt(handler,"_range",SpeedCameras[cameraid][_range]);
  434. INI_WriteInt(handler,"_limit",SpeedCameras[cameraid][_limit]);
  435. INI_WriteInt(handler,"_fine",SpeedCameras[cameraid][_fine]);
  436. INI_WriteInt(handler,"_usemph",SpeedCameras[cameraid][_usemph]);
  437. INI_WriteBool(handler,"_activelabel",SpeedCameras[cameraid][_activelabel]);
  438. INI_WriteString(handler,"_labeltxt",SpeedCameras[cameraid][_labeltxt]);
  439. INI_Close(handler);
  440. }
  441. stock DestroySpeedCam(cameraid)
  442. {
  443. SpeedCameras[cameraid][_active] = false;
  444. #if STREAMER_ENABLED == true
  445. STREAMER_REMOVE(SpeedCameras[cameraid][_objectid]);
  446. #else
  447. DestroyObject(SpeedCameras[cameraid][_objectid]);
  448. #endif
  449. if(SpeedCameras[cameraid][_activelabel] == true)
  450. {
  451. Delete3DTextLabel(SpeedCameras[cameraid][_label]);
  452. }
  453. SpeedCameras[cameraid][_activelabel] = false;
  454. SpeedCameras[cameraid][_labeltxt] = 0;
  455. new file[64];format(file,sizeof file,"/SpeedCameras/%i.txt",cameraid);
  456. if(fexist(file)){fremove(file);}
  457. return 1;
  458. }
  459. stock SetSpeedCamRange(cameraid,limit)
  460. {
  461. SpeedCameras[cameraid][_limit] = limit;
  462. return 1;
  463. }
  464. stock SetSpeedCamFine(cameraid,fine)
  465. {
  466. SpeedCameras[cameraid][_fine] = fine;
  467. return 1;
  468. }
  469. stock Float:GetDistanceBetweenPoints(Float:x,Float:y,Float:tx,Float:ty)
  470. {
  471. new Float:temp1, Float:temp2;
  472. temp1 = x-tx;temp2 = y-ty;
  473. return floatsqroot(temp1*temp1+temp2*temp2);
  474. }
  475.  
  476. stock GetClosestCamera(playerid)
  477. {
  478. new Float:distance = 10,Float:temp,Float:x,Float:y,Float:z,current = -1;GetPlayerPos(playerid,x,y,z);
  479. for(new i = 0;i<loaded_cameras +1;i++)
  480. {
  481. if(SpeedCameras[i][_active] == true)
  482. {
  483. temp = GetDistanceBetweenPoints(x,y,SpeedCameras[i][_x],SpeedCameras[i][_y]);
  484. if(temp < distance)
  485. {
  486. distance = temp;
  487. current = i;
  488. }
  489. }
  490. }
  491. return current;
  492. }
  493.  
  494. stock Float:GetVehicleSpeed(vehicleid,UseMPH = 0)
  495. {
  496. new Float:speed_x,Float:speed_y,Float:speed_z,Float:temp_speed;
  497. GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
  498. if(UseMPH == 0)
  499. {
  500. temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
  501. } else {
  502. temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*85.4166672;
  503. }
  504. floatround(temp_speed,floatround_round);return temp_speed;
  505. }
  506. stock SendClientMessageEx(playerid,color,type[],{Float,_}:...)
  507. {
  508. new string[128];
  509. for(new i = 0;i<numargs() -2;i++)
  510. {
  511. switch(type[i])
  512. {
  513. case 's':
  514. {
  515. new result[128];
  516. for(new a= 0;getarg(i +3,a) != 0;a++)
  517. {
  518. result[a] = getarg(i +3,a);
  519. }
  520. if(!strlen(string))
  521. {
  522. format(string,sizeof string,"%s",result);
  523. } else format(string,sizeof string,"%s%s",string,result);
  524. }
  525.  
  526. case 'i':
  527. {
  528. new result = getarg(i +3);
  529. if(!strlen(string))
  530. {
  531. format(string,sizeof string,"%i",result);
  532. } else format(string,sizeof string,"%s%i",string,result);
  533. }
  534.  
  535. case 'f':
  536. {
  537. new Float:result = Float:getarg(i +3);
  538. if(!strlen(string))
  539. {
  540. format(string,sizeof string,"%f",result);
  541. } else format(string,sizeof string,"%s%f",string,result);
  542. }
  543. }
  544. }
  545. SendClientMessage(playerid,color,string);
  546. return 1;
  547. }
  548. //===================================================================================================
  549. // Timers
  550. //===================================================================================================
  551. forward UpdateCameras();
  552. public UpdateCameras()
  553. {
  554. for(new a = 0;a<MAX_PLAYERS;a++)
  555. {
  556. if(!IsPlayerConnected(a)) continue;
  557. if(!IsPlayerInAnyVehicle(a)) continue;
  558. if(GetPVarInt(a,"PlayerHasBeenFlashed") == 1)
  559. {
  560. continue;
  561. } else if (GetPVarInt(a,"PlayerHasBeenFlashed") == 2)
  562. {
  563. DeletePVar(a,"PlayerHasBeenFlashed");
  564. continue;
  565. }
  566. for(new b = 0;b<loaded_cameras +1;b++)
  567. {
  568. if(SpeedCameras[b][_active] == false) continue;
  569. if(IsPlayerInRangeOfPoint(a,SpeedCameras[b][_range],SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z]))
  570. {
  571. new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(a),SpeedCameras[b][_usemph]));
  572. new limit = SpeedCameras[b][_limit];
  573. if(speed > limit)
  574. {
  575. TextDrawShowForPlayer(a,flash);
  576. #if CAMERA_PERSPECTIVE == true
  577. SetPlayerCameraPos(a,SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z] + 5);
  578. new Float:x,Float:y,Float:z;GetPlayerPos(a,x,y,z);
  579. SetPlayerCameraLookAt(a,x,y,z);
  580. #endif
  581. SetPVarInt(a,"PlayerHasBeenFlashed",1);
  582. SetTimerEx("RemoveFlash",CAMERA_FLASH_TIME,false,"i",a);
  583. if(GetPlayerState(a) == PLAYER_STATE_DRIVER)
  584. {
  585. if(SpeedCameras[b][_usemph] == 0)
  586. {
  587. SendClientMessageEx(a,COLOR_RED,"sisis","Voziš pre brzo! Slikan si vozeci ",speed,"km/h, a dozvoljeno je ",limit, "km/h.");
  588. SendClientMessageEx(a,COLOR_RED,"sis","Dobio si kaznu koja iznosi $",SpeedCameras[b][_fine],".");
  589. //SCM(a, COLOR_FADE2, "Pisi /prihvati ticket ili ces ici u zatvor!");
  590. } else {
  591. SendClientMessageEx(a,COLOR_RED,"sisis","Voziš pre brzo! Slikan si vozeci ",speed,"mp/h, a dozvoljeno je ",limit, "mp/h.");
  592. SendClientMessageEx(a,COLOR_RED,"sis","Dobio si kaznu koja iznosi $",SpeedCameras[b][_fine],".");
  593. //SCM(a, COLOR_FADE2, "Pisi /prihvati ticket ili ces ici u zatvor!");
  594. }
  595. GivePlayerMoney(a, - SpeedCameras[b][_fine]);
  596. }
  597. }
  598. }
  599. }
  600. }
  601. }
  602. forward RemoveFlash(playerid);
  603. public RemoveFlash(playerid)
  604. {
  605. TextDrawHideForPlayer(playerid,flash);
  606. SetPVarInt(playerid,"PlayerHasBeenFlashed",2);
  607. #if CAMERA_PERSPECTIVE == true
  608. SetCameraBehindPlayer(playerid);
  609. #endif
  610. }
Advertisement
Add Comment
Please, Sign In to add comment