gamer931215

gCamera 1.1b

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