gCamera.pwn 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. gCamera - Speedcamera in SA-MP WITH FLASH EFFECT!
  3. V1.1 - Released on 10-04-2011 (Updated at 12-04-2011)
  4. Filterscript version with ingame speedcam generator!
  5. ©Gamer931215
  6. I want to thank my friend HighFlyer in this release for some tips and testing it (like textlabels, using a streamer, etc) !
  7. Use at own risk, do NOT re-release,mirror,sell it or even worse: clame this as your own!
  8. */
  9. #include <a_samp>
  10. #include <zcmd>
  11. #include <YSI/y_ini>
  12. //===================================================================================================
  13. // Settings
  14. //===================================================================================================
  15. // SETTING: VALUE: Discription:
  16. #define CAMERA_LIMIT 100 //Max loaded cameras (keep this as low as possible for the best performance)
  17. #define CAMERA_UPDATE_INTERVAL 750 //update interval of all speedcams (in miliseconds)
  18. #define CAMERA_FLASH_TIME 1200 //ammount of miliseconds until the "flash" effect gets removed again
  19. #define CAMERA_DIALOG_RANGE 1337 //dialog ID range (Example: 0 will take dialogid's 0 - 9)
  20. #define CAMERA_USEMPH 0 //toggles camera using mph by default (0=kmh, 1=mph)
  21. #define CAMERA_LABEL_COLOR 0xFF000FFF //The default color of the camera's label
  22. #define CAMERA_PERSPECTIVE false //Sets playercamera temporary at the camera's position while flashing
  23. //streamer options (will be used if STREAMER_ENABLED is set on true)
  24. #define STREAMER_ENABLED false //uses a streamer (true/false)
  25. #define STREAMER_ADD CreateDynamicObject //put here at the value the command your streamer uses to make an object (CreateDynamicObject by default)
  26. #define STREAMER_REMOVE DestroyDynamicObject //put here at the value the command your streamer uses to remove an object (STREAMER_REMOVE by default)
  27. #if STREAMER_ENABLED == true //ignore this line
  28. #include streamer //put your include name here
  29. #endif //ignore this line
  30. //===================================================================================================
  31. // Variables
  32. //===================================================================================================
  33. #define DIALOG_MAIN CAMERA_DIALOG_RANGE
  34. #define DIALOG_RANGE CAMERA_DIALOG_RANGE +1
  35. #define DIALOG_LIMIT CAMERA_DIALOG_RANGE +2
  36. #define DIALOG_FINE CAMERA_DIALOG_RANGE +3
  37. #define DIALOG_EDIT CAMERA_DIALOG_RANGE +4
  38. #define DIALOG_EANGLE CAMERA_DIALOG_RANGE +5
  39. #define DIALOG_ELIMIT CAMERA_DIALOG_RANGE +6
  40. #define DIALOG_ERANGE CAMERA_DIALOG_RANGE +7
  41. #define DIALOG_EFINE CAMERA_DIALOG_RANGE +8
  42. #define DIALOG_ETYPE CAMERA_DIALOG_RANGE +9
  43. #define DIALOG_LABEL CAMERA_DIALOG_RANGE +10
  44. #define COLOR_RED 0xFF1E00FF
  45. #define COLOR_GREEN 0x05FF00FF
  46. enum _camera
  47. {Float:_x,Float:_y,Float:_z,Float:_rot,_range,_limit,_fine,_usemph,_objectid,bool:_active,bool:_activelabel,_labeltxt[128],Text3D:_label}
  48. new SpeedCameras[CAMERA_LIMIT][_camera],loaded_cameras = 0,Text:flash;
  49. //stocks for attaching labels to camera (must be defined before use, thats why this one is at the top)
  50. stock Text3D:AttachLabelToCamera(cameraid,text[])
  51. {
  52. new position,buffer[128];format(buffer,sizeof buffer,"%s",text);
  53. for(new i = 0;strfind(buffer,"\\n",true) != -1;i++)
  54. {
  55. position = strfind(buffer,"\\n",true);
  56. strdel(buffer,position,position +2);
  57. strins(buffer,"\r\n",position,sizeof(buffer));
  58. }
  59. return Create3DTextLabel(buffer,CAMERA_LABEL_COLOR,SpeedCameras[cameraid][_x],SpeedCameras[cameraid][_y],SpeedCameras[cameraid][_z] +7,100,0,0);
  60. }
  61. stock UpdateCameraLabel(Text3D:labelid,text[])
  62. {
  63. new position,buffer[128];format(buffer,sizeof buffer,"%s",text);
  64. for(new i = 0;strfind(buffer,"\\n",true) != -1;i++)
  65. {
  66. position = strfind(buffer,"\\n",true);
  67. strdel(buffer,position,position +2);
  68. strins(buffer,"\r\n",position,sizeof(buffer));
  69. }
  70. return Update3DTextLabelText(labelid,CAMERA_LABEL_COLOR,buffer);
  71. }
  72. //===================================================================================================
  73. // Initialize
  74. //===================================================================================================
  75. public OnFilterScriptInit()
  76. {
  77. SetTimer("UpdateCameras",CAMERA_UPDATE_INTERVAL,true);
  78. flash = TextDrawCreate(-20.000000,2.000000,"|");
  79. TextDrawUseBox(flash,1);
  80. TextDrawBoxColor(flash,0xffffff66);
  81. TextDrawTextSize(flash,660.000000,22.000000);
  82. TextDrawAlignment(flash,0);
  83. TextDrawBackgroundColor(flash,0x000000ff);
  84. TextDrawFont(flash,3);
  85. TextDrawLetterSize(flash,1.000000,52.200000);
  86. TextDrawColor(flash,0xffffffff);
  87. TextDrawSetOutline(flash,1);
  88. TextDrawSetProportional(flash,1);
  89. TextDrawSetShadow(flash,1);
  90. print("====================================");
  91. print("| gCamera V1.0 |");
  92. print("| ©Gamer931215 |");
  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("====================================");
  104. RemoveCameras();
  105. print("All cameras have been removed.");
  106. return 1;
  107. }
  108. //===================================================================================================
  109. // Commands
  110. //===================================================================================================
  111. COMMAND:gcam(playerid,params[])
  112. {
  113. if(!IsPlayerAdmin(playerid)) return 0;
  114. ShowPlayerDialog(playerid,DIALOG_MAIN,DIALOG_STYLE_LIST,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Main menu","{37FF00}Create speedcamera\n\nGet closest speedcamera ID\nEdit closest speedcamera\n{FF1400}Delete closest speedcamera\n{FF1400}Delete all speedcameras","OK","Cancel");
  115. return 1;
  116. }
  117. //===================================================================================================
  118. // Callbacks
  119. //===================================================================================================
  120. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  121. {
  122. if(!response) {
  123. DeletePVar(playerid,"range");
  124. DeletePVar(playerid,"limit");
  125. DeletePVar(playerid,"fine");
  126. DeletePVar(playerid,"selected");
  127. return 1;
  128. }
  129. switch(dialogid)
  130. {
  131. //======================================================
  132. // Main menu
  133. //======================================================
  134. case DIALOG_MAIN:
  135. {
  136. switch(listitem)
  137. {
  138. case 0: ShowPlayerDialog(playerid,DIALOG_RANGE,DIALOG_STYLE_INPUT,"Insert a range","Please insert a range (recommended: 20-30)","OK","Cancel");
  139. case 1:
  140. {
  141. new cam = GetClosestCamera(playerid);
  142. if(cam == -1) return SendClientMessage(playerid,COLOR_RED,"No nearby cameras found!");
  143. SendClientMessageEx(playerid,COLOR_GREEN,"sis","The closest cameraID is ID: ",cam,".");
  144. }
  145. case 2:
  146. {
  147. new cam = GetClosestCamera(playerid);
  148. if(cam == -1) return SendClientMessage(playerid,COLOR_RED,"No nearby cameras found!");
  149. SetPVarInt(playerid,"selected",cam);
  150. ShowPlayerDialog(playerid,DIALOG_EDIT,DIALOG_STYLE_LIST,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor","Change angle\nChange range\nChange speedlimit\nChange fine\nToggle mph mode\nAdd/Remove/Edit textlabel\n{FF1400}Delete camera","OK","Cancel");
  151. }
  152. case 3:
  153. {
  154. new cam = GetClosestCamera(playerid);
  155. if(cam == -1) return SendClientMessage(playerid,COLOR_RED,"No nearby cameras found!");
  156. DestroySpeedCam(cam);
  157. SendClientMessage(playerid,COLOR_GREEN,"Camera has been removed.");
  158. DeletePVar(playerid,"selected");
  159. }
  160. case 4:
  161. {
  162. for(new i = 0;i<loaded_cameras +1;i++)
  163. {
  164. if(SpeedCameras[i][_active] == true)
  165. {
  166. DestroySpeedCam(i);
  167. }
  168. }
  169. SendClientMessage(playerid,COLOR_GREEN,"All speedcameras have been removed.");
  170. }
  171. }
  172. }
  173. //======================================================
  174. // Making a speedcam
  175. //======================================================
  176. case DIALOG_RANGE:
  177. {
  178. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_RANGE,DIALOG_STYLE_INPUT,"Insert a range","Please insert a range (recommended: 20-30)","OK","Cancel");
  179. SetPVarInt(playerid,"range",strval(inputtext));
  180. ShowPlayerDialog(playerid,DIALOG_LIMIT,DIALOG_STYLE_INPUT,"Insert a speedlimit","Please insert a speedlimit","OK","Cancel");
  181. }
  182. case DIALOG_LIMIT:
  183. {
  184. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LIMIT,DIALOG_STYLE_INPUT,"Insert a speedlimit","Please insert a speedlimit","OK","Cancel");
  185. SetPVarInt(playerid,"limit",strval(inputtext));
  186. ShowPlayerDialog(playerid,DIALOG_FINE,DIALOG_STYLE_INPUT,"Insert a fine","Please insert a fine","OK","Cancel");
  187. }
  188. case DIALOG_FINE:
  189. {
  190. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_FINE,DIALOG_STYLE_INPUT,"Insert a fine","Please insert a fine","OK","Cancel");
  191. SetPVarInt(playerid,"fine",strval(inputtext));
  192. new Float:x,Float:y,Float:z,Float:angle;
  193. GetPlayerPos(playerid,x,y,z);GetPlayerFacingAngle(playerid,angle);
  194. angle = angle + 180;if(angle > 360){angle = angle - 360;}
  195. new id = CreateSpeedCam(x,y,z -3,angle,GetPVarInt(playerid,"range"),GetPVarInt(playerid,"limit"),GetPVarInt(playerid,"fine"),CAMERA_USEMPH);
  196. SetPlayerPos(playerid,x,y+2,z);
  197. DeletePVar(playerid,"range");
  198. DeletePVar(playerid,"limit");
  199. DeletePVar(playerid,"fine");
  200. SetPVarInt(playerid,"selected",id);
  201. ShowPlayerDialog(playerid,DIALOG_EDIT,DIALOG_STYLE_LIST,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor","Change angle\nChange range\nChange speedlimit\nChange fine\nToggle mph mode\nAdd/Remove/Edit textlabel\n{FF1400}Delete camera","OK","Cancel");
  202. }
  203. //======================================================
  204. // Edit menu
  205. //======================================================
  206. case DIALOG_EDIT:
  207. {
  208. switch(listitem)
  209. {
  210. case 0: ShowPlayerDialog(playerid,DIALOG_EANGLE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Angle","Please enter a new angle","OK","Cancel");
  211. case 1: ShowPlayerDialog(playerid,DIALOG_ERANGE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Range","Please enter a new range","OK","Cancel");
  212. case 2: ShowPlayerDialog(playerid,DIALOG_ELIMIT,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Speedlimit","Please enter a new speedlimit","OK","Cancel");
  213. case 3: ShowPlayerDialog(playerid,DIALOG_EFINE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Fine","Please enter a new fine","OK","Cancel");
  214. case 4: ShowPlayerDialog(playerid,DIALOG_ETYPE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Mph/Kmh","enter 1 to use mph and 0 for kmh","OK","Cancel");
  215. case 5: ShowPlayerDialog(playerid,DIALOG_LABEL,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Textlabel","Please fill in the text you want to attach, or leave it empty to remove an existing label!","OK","Cancel");
  216. case 6:
  217. {
  218. DestroySpeedCam(GetPVarInt(playerid,"selected"));
  219. SendClientMessage(playerid,COLOR_GREEN,"Camera has been removed.");
  220. DeletePVar(playerid,"selected");
  221. }
  222. }
  223. }
  224. //======================================================
  225. // Editing a speedcam
  226. //======================================================
  227. case DIALOG_EANGLE:
  228. {
  229. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_EANGLE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Angle","Please enter a new angle","OK","Cancel");
  230. new id = GetPVarInt(playerid,"selected");
  231. new rot = strval(inputtext);
  232. rot = rot + 180;
  233. if (rot > 360)
  234. {
  235. rot = rot - 360;
  236. }
  237. SpeedCameras[id][_rot] = rot;
  238. SetObjectRot(SpeedCameras[id][_objectid],0,0,rot);
  239. SaveCamera(id);
  240. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","The angle of cameraID ",id," has succesfully been updated to ",strval(inputtext),".");
  241. }
  242. case DIALOG_ERANGE:
  243. {
  244. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_ERANGE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Range","Please enter a new range","OK","Cancel");
  245. new id = GetPVarInt(playerid,"selected");
  246. SpeedCameras[id][_range] = strval(inputtext);
  247. SaveCamera(id);
  248. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","The range of cameraID ",id," has succesfully been updated to ",strval(inputtext),".");
  249. }
  250. case DIALOG_ELIMIT:
  251. {
  252. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_ELIMIT,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Speedlimit","Please enter a new Speedlimit","OK","Cancel");
  253. new id = GetPVarInt(playerid,"selected");
  254. SpeedCameras[id][_limit] = strval(inputtext);
  255. SaveCamera(id);
  256. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","The speedlimit of cameraID ",id," has succesfully been updated to ",strval(inputtext),".");
  257. }
  258. case DIALOG_EFINE:
  259. {
  260. if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_EFINE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Fine","Please enter a new fine","OK","Cancel");
  261. new id = GetPVarInt(playerid,"selected");
  262. SpeedCameras[id][_fine] = strval(inputtext);
  263. SaveCamera(id);
  264. SendClientMessageEx(playerid,COLOR_GREEN,"sisis","The fine of cameraID ",GetPVarInt(playerid,"selected")," has succesfully been updated to ",strval(inputtext),".");
  265. }
  266. case DIALOG_ETYPE:
  267. {
  268. if(!strlen(inputtext) || strval(inputtext) != 0 && strval(inputtext) != 1) return ShowPlayerDialog(playerid,DIALOG_ETYPE,DIALOG_STYLE_INPUT,"{00A5FF}gCamera {FFFFFF}- {FFDC00}Editor - Mph/Kmh","enter 1 to use mph and 0 for kmh","OK","Cancel");
  269. new id = GetPVarInt(playerid,"selected");
  270. SpeedCameras[id][_usemph] = strval(inputtext);
  271. if(strval(inputtext) == 1)
  272. {
  273. SendClientMessageEx(playerid,COLOR_GREEN,"sis","CameraID ",GetPVarInt(playerid,"selected")," does now meassure speed in mph.");
  274. } else {
  275. SendClientMessageEx(playerid,COLOR_GREEN,"sis","CameraID ",GetPVarInt(playerid,"selected")," does now meassure speed in kmh.");
  276. }
  277. }
  278. case DIALOG_LABEL:
  279. {
  280. new id = GetPVarInt(playerid,"selected");
  281. if(!strlen(inputtext))
  282. {
  283. if(SpeedCameras[id][_activelabel] == true)
  284. {
  285. Delete3DTextLabel(SpeedCameras[id][_label]);
  286. SpeedCameras[id][_activelabel] = false;
  287. SpeedCameras[id][_labeltxt] = 0;
  288. }
  289. SendClientMessageEx(playerid,COLOR_GREEN,"sis","The textlabel of cameraID ",GetPVarInt(playerid,"selected")," has succesfully been removed.");
  290. } else {
  291. if(SpeedCameras[id][_activelabel] == true)
  292. {
  293. format(SpeedCameras[id][_labeltxt],128,"%s",inputtext);
  294. UpdateCameraLabel(SpeedCameras[id][_label],inputtext);
  295. } else {
  296. SpeedCameras[id][_activelabel] = true;
  297. format(SpeedCameras[id][_labeltxt],128,"%s",inputtext);
  298. SpeedCameras[id][_label] = AttachLabelToCamera(id,inputtext);
  299. }
  300. SendClientMessageEx(playerid,COLOR_GREEN,"sisss","The textlabel of cameraID ",GetPVarInt(playerid,"selected")," has succesfully been updated to ",inputtext,".");
  301. }
  302. SaveCamera(id);
  303. }
  304. }
  305. return 0;
  306. }
  307. //===================================================================================================
  308. // Functions
  309. //===================================================================================================
  310. stock LoadCameras()
  311. {
  312. new file[64];
  313. for(new i = 0;i<CAMERA_LIMIT;i++)
  314. {
  315. format(file,sizeof file,"/SpeedCameras/%i.txt",i);
  316. if(fexist(file))
  317. {
  318. INI_ParseFile(file,"LoadCam",.bExtra = true,.extra = i);
  319. #if STREAMER_ENABLED == true
  320. SpeedCameras[i][_objectid] = STREAMER_ADD(18880,SpeedCameras[i][_x],SpeedCameras[i][_y],SpeedCameras[i][_z],0,0,SpeedCameras[i][_rot]);
  321. #else
  322. SpeedCameras[i][_objectid] = CreateObject(18880,SpeedCameras[i][_x],SpeedCameras[i][_y],SpeedCameras[i][_z],0,0,SpeedCameras[i][_rot]);
  323. #endif
  324. SpeedCameras[i][_active] = true;
  325. if(SpeedCameras[i][_activelabel] == true)
  326. {
  327. SpeedCameras[i][_label] = AttachLabelToCamera(i,SpeedCameras[i][_labeltxt]);
  328. }
  329. loaded_cameras++;
  330. }
  331. }
  332. printf("gCamera has succesfully loaded %i camera(s).",loaded_cameras);
  333. }
  334. forward LoadCam(cameraid,name[],value[]);
  335. public LoadCam(cameraid,name[],value[])
  336. {
  337. INI_Float("_x",SpeedCameras[cameraid][_x]);
  338. INI_Float("_y",SpeedCameras[cameraid][_y]);
  339. INI_Float("_z",SpeedCameras[cameraid][_z]);
  340. INI_Float("_rot",SpeedCameras[cameraid][_rot]);
  341. INI_Int("_range",SpeedCameras[cameraid][_range]);
  342. INI_Int("_limit",SpeedCameras[cameraid][_limit]);
  343. INI_Int("_fine",SpeedCameras[cameraid][_fine]);
  344. INI_Int("_usemph",SpeedCameras[cameraid][_usemph]);
  345. INI_Bool("_activelabel",SpeedCameras[cameraid][_activelabel]);
  346. INI_String("_labeltxt",SpeedCameras[cameraid][_labeltxt],128);
  347. return 1;
  348. }
  349. stock RemoveCameras()
  350. {
  351. for(new i = 0;i<loaded_cameras +1;i++)
  352. {
  353. if(SpeedCameras[i][_active] == true)
  354. {
  355. #if STREAMER_ENABLED == true
  356. STREAMER_REMOVE(SpeedCameras[i][_objectid]);
  357. #else
  358. DestroyObject(SpeedCameras[i][_objectid]);
  359. #endif
  360. if(SpeedCameras[i][_activelabel] == true)
  361. {
  362. Delete3DTextLabel(SpeedCameras[i][_label]);
  363. }
  364. }
  365. }
  366. return 1;
  367. }
  368. stock generate_id()
  369. {
  370. new file[64];
  371. for(new i = 0;i<CAMERA_LIMIT;i++)
  372. {
  373. format(file,sizeof file,"/SpeedCameras/%i.txt",i);
  374. if(!fexist(file)) return i;
  375. }
  376. return -1;
  377. }
  378. stock CreateSpeedCam(Float:x,Float:y,Float:z,Float:rot,range,limit,fine,use_mph = 0)
  379. {
  380. new newid = generate_id();
  381. if(newid == -1)
  382. {
  383. print("gSpeedcam: ERROR! Cannot create speedcam, max ammount of speedcameras has been reached!");
  384. return 1;
  385. }
  386. if (newid == loaded_cameras || newid > loaded_cameras)
  387. {
  388. loaded_cameras++;
  389. }
  390. SpeedCameras[newid][_x] = x;
  391. SpeedCameras[newid][_y] = y;
  392. SpeedCameras[newid][_z] = z;
  393. SpeedCameras[newid][_rot] = rot;
  394. SpeedCameras[newid][_range] = range;
  395. SpeedCameras[newid][_limit] = limit;
  396. SpeedCameras[newid][_fine] = fine;
  397. SpeedCameras[newid][_usemph] = use_mph;
  398. #if STREAMER_ENABLED == true
  399. SpeedCameras[newid][_objectid] = STREAMER_ADD(18880,x,y,z,0,0,rot);
  400. #else
  401. SpeedCameras[newid][_objectid] = CreateObject(18880,x,y,z,0,0,rot);
  402. #endif
  403. SpeedCameras[newid][_active] = true;
  404. SpeedCameras[newid][_activelabel] = false;
  405. SpeedCameras[newid][_labeltxt] = 0;
  406. new file[64];format(file,sizeof file,"/SpeedCameras/%i.txt",newid);
  407. new INI:handler = INI_Open(file);
  408. INI_WriteFloat(handler,"_x",SpeedCameras[newid][_x]);
  409. INI_WriteFloat(handler,"_y",SpeedCameras[newid][_y]);
  410. INI_WriteFloat(handler,"_z",SpeedCameras[newid][_z]);
  411. INI_WriteFloat(handler,"_rot",SpeedCameras[newid][_rot]);
  412. INI_WriteInt(handler,"_range",SpeedCameras[newid][_range]);
  413. INI_WriteInt(handler,"_limit",SpeedCameras[newid][_limit]);
  414. INI_WriteInt(handler,"_fine",SpeedCameras[newid][_fine]);
  415. INI_WriteInt(handler,"_usemph",SpeedCameras[newid][_usemph]);
  416. INI_WriteBool(handler,"_activelabel",SpeedCameras[newid][_activelabel]);
  417. INI_WriteString(handler,"_labeltxt",SpeedCameras[newid][_labeltxt]);
  418. INI_Close(handler);
  419. return newid;
  420. }
  421. stock SaveCamera(cameraid)
  422. {
  423. new file[64];format(file,sizeof file,"/SpeedCameras/%i.txt",cameraid);
  424. new INI:handler = INI_Open(file);
  425. INI_WriteFloat(handler,"_x",SpeedCameras[cameraid][_x]);
  426. INI_WriteFloat(handler,"_y",SpeedCameras[cameraid][_y]);
  427. INI_WriteFloat(handler,"_z",SpeedCameras[cameraid][_z]);
  428. INI_WriteFloat(handler,"_rot",SpeedCameras[cameraid][_rot]);
  429. INI_WriteInt(handler,"_range",SpeedCameras[cameraid][_range]);
  430. INI_WriteInt(handler,"_limit",SpeedCameras[cameraid][_limit]);
  431. INI_WriteInt(handler,"_fine",SpeedCameras[cameraid][_fine]);
  432. INI_WriteInt(handler,"_usemph",SpeedCameras[cameraid][_usemph]);
  433. INI_WriteBool(handler,"_activelabel",SpeedCameras[cameraid][_activelabel]);
  434. INI_WriteString(handler,"_labeltxt",SpeedCameras[cameraid][_labeltxt]);
  435. INI_Close(handler);
  436. }
  437. stock DestroySpeedCam(cameraid)
  438. {
  439. SpeedCameras[cameraid][_active] = false;
  440. #if STREAMER_ENABLED == true
  441. STREAMER_REMOVE(SpeedCameras[cameraid][_objectid]);
  442. #else
  443. DestroyObject(SpeedCameras[cameraid][_objectid]);
  444. #endif
  445. if(SpeedCameras[cameraid][_activelabel] == true)
  446. {
  447. Delete3DTextLabel(SpeedCameras[cameraid][_label]);
  448. }
  449. SpeedCameras[cameraid][_activelabel] = false;
  450. SpeedCameras[cameraid][_labeltxt] = 0;
  451. new file[64];format(file,sizeof file,"/SpeedCameras/%i.txt",cameraid);
  452. if(fexist(file)){fremove(file);}
  453. return 1;
  454. }
  455. stock SetSpeedCamRange(cameraid,limit)
  456. {
  457. SpeedCameras[cameraid][_limit] = limit;
  458. return 1;
  459. }
  460. stock SetSpeedCamFine(cameraid,fine)
  461. {
  462. SpeedCameras[cameraid][_fine] = fine;
  463. return 1;
  464. }
  465. stock Float:GetDistanceBetweenPoints(Float:x,Float:y,Float:tx,Float:ty)
  466. {
  467. new Float:temp1, Float:temp2;
  468. temp1 = x-tx;temp2 = y-ty;
  469. return floatsqroot(temp1*temp1+temp2*temp2);
  470. }
  471. stock GetClosestCamera(playerid)
  472. {
  473. new Float:distance = 10,Float:temp,Float:x,Float:y,Float:z,current = -1;GetPlayerPos(playerid,x,y,z);
  474. for(new i = 0;i<loaded_cameras +1;i++)
  475. {
  476. if(SpeedCameras[i][_active] == true)
  477. {
  478. temp = GetDistanceBetweenPoints(x,y,SpeedCameras[i][_x],SpeedCameras[i][_y]);
  479. if(temp < distance)
  480. {
  481. distance = temp;
  482. current = i;
  483. }
  484. }
  485. }
  486. return current;
  487. }
  488. stock Float:GetVehicleSpeed(vehicleid,UseMPH = 0)
  489. {
  490. new Float:speed_x,Float:speed_y,Float:speed_z,Float:temp_speed;
  491. GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
  492. if(UseMPH == 0)
  493. {
  494. temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
  495. } else {
  496. temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*85.4166672;
  497. }
  498. floatround(temp_speed,floatround_round);return temp_speed;
  499. }
  500. stock SendClientMessageEx(playerid,color,type[],{Float,_}:...)
  501. {
  502. new string[128];
  503. for(new i = 0;i<numargs() -2;i++)
  504. {
  505. switch(type[i])
  506. {
  507. case 's':
  508. {
  509. new result[128];
  510. for(new a= 0;getarg(i +3,a) != 0;a++)
  511. {
  512. result[a] = getarg(i +3,a);
  513. }
  514. if(!strlen(string))
  515. {
  516. format(string,sizeof string,"%s",result);
  517. } else format(string,sizeof string,"%s%s",string,result);
  518. }
  519. case 'i':
  520. {
  521. new result = getarg(i +3);
  522. if(!strlen(string))
  523. {
  524. format(string,sizeof string,"%i",result);
  525. } else format(string,sizeof string,"%s%i",string,result);
  526. }
  527. case 'f':
  528. {
  529. new Float:result = Float:getarg(i +3);
  530. if(!strlen(string))
  531. {
  532. format(string,sizeof string,"%f",result);
  533. } else format(string,sizeof string,"%s%f",string,result);
  534. }
  535. }
  536. }
  537. SendClientMessage(playerid,color,string);
  538. return 1;
  539. }
  540. //===================================================================================================
  541. // Timers
  542. //===================================================================================================
  543. forward UpdateCameras();
  544. public UpdateCameras()
  545. {
  546. for(new a = 0;a<MAX_PLAYERS;a++)
  547. {
  548. if(!IsPlayerConnected(a)) continue;
  549. if(!IsPlayerInAnyVehicle(a)) continue;
  550. if(GetPVarInt(a,"PlayerHasBeenFlashed") == 1)
  551. {
  552. continue;
  553. } else if (GetPVarInt(a,"PlayerHasBeenFlashed") == 2)
  554. {
  555. DeletePVar(a,"PlayerHasBeenFlashed");
  556. continue;
  557. }
  558. for(new b = 0;b<loaded_cameras +1;b++)
  559. {
  560. if(SpeedCameras[b][_active] == false) continue;
  561. if(IsPlayerInRangeOfPoint(a,SpeedCameras[b][_range],SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z]))
  562. {
  563. new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(a),SpeedCameras[b][_usemph]));
  564. new limit = SpeedCameras[b][_limit];
  565. if(speed > limit)
  566. {
  567. TextDrawShowForPlayer(a,flash);
  568. #if CAMERA_PERSPECTIVE == true
  569. SetPlayerCameraPos(a,SpeedCameras[b][_x],SpeedCameras[b][_y],SpeedCameras[b][_z] + 5);
  570. new Float:x,Float:y,Float:z;GetPlayerPos(a,x,y,z);
  571. SetPlayerCameraLookAt(a,x,y,z);
  572. #endif
  573. SetPVarInt(a,"PlayerHasBeenFlashed",1);
  574. SetTimerEx("RemoveFlash",CAMERA_FLASH_TIME,false,"i",a);
  575. if(GetPlayerState(a) == PLAYER_STATE_DRIVER)
  576. {
  577. if(SpeedCameras[b][_usemph] == 0)
  578. {
  579. SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"kmh where you were allowed to drive ",limit, "kmh.");
  580. SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
  581. } else {
  582. SendClientMessageEx(a,0xFF1E00FF,"sisis","You are driving too fast! you got busted driving ",speed,"mph where you were allowed to drive ",limit, "mph.");
  583. SendClientMessageEx(a,0xFF1E00FF,"sis","You got yourself a fine of $",SpeedCameras[b][_fine],".");
  584. }
  585. GivePlayerMoney(a, - SpeedCameras[b][_fine]);
  586. }
  587. }
  588. }
  589. }
  590. }
  591. }
  592. forward RemoveFlash(playerid);
  593. public RemoveFlash(playerid)
  594. {
  595. TextDrawHideForPlayer(playerid,flash);
  596. SetPVarInt(playerid,"PlayerHasBeenFlashed",2);
  597. #if CAMERA_PERSPECTIVE == true
  598. SetCameraBehindPlayer(playerid);
  599. #endif
  600. }