Advertisement
Guest User

Blitzersystem - CFG

a guest
Feb 15th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.24 KB | None | 0 0
  1. #include <a_samp>
  2. //#include <Dini> wird nicht mehr gebraucht
  3.  
  4. #define MAX_BLITZER 50 //<--- Maximale Anzahl an Blitzer | Kann geändert werden.
  5. #define DIALOG_BLITZER 0 //<--- ACHTUNG: Die Dialogid muss je nach Gamemode angepasst werden!
  6. #define DIALOG_BLITZER_MAXRANGE 1 //<--- ACHTUNG: Die Dialogid muss je nach Gamemode angepasst werden!
  7. #define DIALOG_BLITZER_MAXSPEED 2 //<--- ACHTUNG: Die Dialogid muss je nach Gamemode angepasst werden!
  8.  
  9. #define ROT 0xFF0000FF
  10. #define GRÜN 0x00FF00FF
  11. #define GRAU 0x5A5A5AFF
  12.  
  13. forward BlitzedOff(playerid);
  14. forward IsInRangeOfBlitzer(playerid);
  15.  
  16. new Temp[MAX_PLAYERS],Blitzed[MAX_PLAYERS],BBlitzer[MAX_PLAYERS];
  17.  
  18. enum _BlitzerData
  19. {
  20.     Float:BlitzerX,
  21.     Float:BlitzerY,
  22.     Float:BlitzerZ,
  23.     Float:BlitzerRotation,
  24.     Text3D:label,
  25.     erstellt,
  26.     maxrange,
  27.     maxspeed,
  28.     Obj
  29. };
  30.  
  31. new Blitzer[MAX_BLITZER][_BlitzerData];
  32.  
  33. public OnFilterScriptInit()
  34. {
  35.     print("\n--------------------------------------");
  36.     print("     Blitzersystem - sa-mp.de");
  37.     print("--------------------------------------\n");
  38.     BlitzerLaden();
  39.     return 1;
  40. }
  41.  
  42. public OnFilterScriptExit()
  43. {
  44.     BlitzerSpeichern();
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerCommandText(playerid, cmdtext[])
  49. {
  50.     if(strcmp("/createblitzer",cmdtext,true,10) == 0)
  51.     {
  52.         if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,ROT,"Du bist kein Admin!");
  53.         ShowPlayerDialog(playerid,DIALOG_BLITZER,DIALOG_STYLE_LIST,"Blitzersystem - 123marvin123","Blitzer aufstellen\nBlitzer abbauen\nAlle Blitzer abbauen","Bestätigen","Abbrechen");
  54.         return 1;
  55.     }
  56.     return 0;
  57. }
  58.  
  59. public OnPlayerStateChange(playerid, newstate, oldstate)
  60. {
  61.     if(newstate == PLAYER_STATE_DRIVER)
  62.     {
  63.         BBlitzer[playerid] = SetTimerEx("IsInRangeOfBlitzer",1000,true,"i",playerid);
  64.     }
  65.     else if(oldstate == PLAYER_STATE_DRIVER)
  66.     {
  67.         KillTimer(BBlitzer[playerid]);
  68.     }
  69.     return 1;
  70. }
  71.  
  72. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  73. {
  74.     new Float:x,Float:y,Float:z,Float:rotation,string[50];
  75.     GetPlayerPos(playerid,x,y,z);
  76.     GetPlayerFacingAngle(playerid,rotation);
  77.     switch (dialogid)
  78.     {
  79.         case DIALOG_BLITZER:
  80.         {
  81.             if(!response)return SendClientMessage(playerid,GRAU,"* Vorgang abgebrochen.");
  82.             switch (listitem)
  83.             {
  84.                 case 0:
  85.                 {
  86.                     {
  87.                         ShowPlayerDialog(playerid,DIALOG_BLITZER_MAXRANGE,DIALOG_STYLE_INPUT,"Blitzersystem - 123marvin123","Gebe nun den Radius ein:","Bestätigen","Abbrechen");
  88.                     }
  89.                 }
  90.                 case 1:
  91.                 {
  92.                     for(new i = 0; i < MAX_BLITZER; i++)
  93.                     {
  94.                         if(Blitzer[i][erstellt] == 0)continue;
  95.                         if(Blitzer[i][erstellt] == 1)
  96.                         {
  97.                             if(IsPlayerInRangeOfPoint(playerid,10.0,Blitzer[i][BlitzerX],Blitzer[i][BlitzerY],Blitzer[i][BlitzerZ]))
  98.                             {
  99.                                 DestroyObject(Blitzer[i][Obj]);
  100.                                 Blitzer[i][BlitzerX] = 0;
  101.                                 Blitzer[i][BlitzerY] = 0;
  102.                                 Blitzer[i][BlitzerZ] = 0;
  103.                                 Blitzer[i][erstellt] = 0;
  104.                                 Blitzer[i][maxrange] = 0;
  105.                                 Blitzer[i][maxspeed] = 0;
  106.                                 Blitzer[i][Obj] = -1;
  107.                                 Delete3DTextLabel(Blitzer[i][label]);
  108.                                 //dini_Remove(Datei);
  109.                                 BlitzerSpeichern();
  110.                             }
  111.                         }
  112.                     }
  113.                 }
  114.                 case 2:
  115.                 {
  116.                     for(new i = 0; i < MAX_BLITZER; i++)
  117.                     {
  118.                         if(Blitzer[i][erstellt] == 0)continue;
  119.                         if(Blitzer[i][erstellt] == 1)
  120.                         {
  121.                                 DestroyObject(Blitzer[i][Obj]);
  122.                                 Blitzer[i][BlitzerX] = 0;
  123.                                 Blitzer[i][BlitzerY] = 0;
  124.                                 Blitzer[i][BlitzerZ] = 0;
  125.                                 Blitzer[i][erstellt] = 0;
  126.                                 Blitzer[i][maxrange] = 0;
  127.                                 Blitzer[i][maxspeed] = 0;
  128.                                 Blitzer[i][Obj] = -1;
  129.                                 Delete3DTextLabel(Blitzer[i][label]);
  130.                                 //dini_Remove(Datei);
  131.                         }
  132.                     }
  133.                     BlitzerSpeichern();
  134.                 }
  135.             }
  136.         }
  137.         case DIALOG_BLITZER_MAXRANGE:
  138.         {
  139.             new zahl = strval(inputtext);
  140.             if(!response)return SendClientMessage(playerid,GRAU,"* Vorgang abgebrochen.");
  141.             Temp[playerid] = zahl;
  142.             ShowPlayerDialog(playerid,DIALOG_BLITZER_MAXSPEED,DIALOG_STYLE_INPUT,"Blitzersystem - 123marvin123","Gebe nun die Maximale Geschwindigkeit in km/h an:","Bestätigen","Abbrechen");
  143.         }
  144.         case DIALOG_BLITZER_MAXSPEED:
  145.         {
  146.             new zahl = strval(inputtext);
  147.             if(!response)return SendClientMessage(playerid,GRAU,"* Vorgang abgebrochen.");
  148.             for(new i = 0; i < MAX_BLITZER; i++)
  149.             {
  150.                 if(Blitzer[i][erstellt] == 1)continue;
  151.                 Blitzer[i][BlitzerX] = x;
  152.                 Blitzer[i][BlitzerY] = y;
  153.                 Blitzer[i][BlitzerZ] = z;
  154.                 Blitzer[i][erstellt] = 1;
  155.                 Blitzer[i][maxspeed] = zahl;
  156.                 Blitzer[i][maxrange] = Temp[playerid];
  157.                 Blitzer[i][BlitzerRotation] = rotation;
  158.                 Blitzer[i][Obj] = CreateObject(18880,x+1,y+1,z-1,0.0,0.0,rotation);
  159.                 format(string,sizeof(string),"Blitzer ID: %i\nMax. Speed: %i km/h\nRadius: %i",i,zahl,Temp[playerid]);
  160.                 Blitzer[i][label] = Create3DTextLabel(string,GRAU,x+1,y+1,z+1,Temp[playerid] / 2,0);
  161.                 Temp[playerid] = 0;
  162.                 return 1;
  163.             }
  164.         }
  165.     }
  166.     return 1;
  167. }
  168.  
  169. stock BlitzerSpeichern()
  170. {
  171.     new File: file = fopen("Blitzer/Blitzer.cfg", io_write);
  172.     if (file)
  173.     {
  174.         for(new i = 0; i < MAX_BLITZER; i++)
  175.         {
  176.             if(Blitzer[i][erstellt] == 0)continue;
  177.             new coordsstring[100];
  178.             format(coordsstring, sizeof(coordsstring), "%f|%f|%f|%d|%d|%f\n",
  179.             Blitzer[i][BlitzerX],
  180.             Blitzer[i][BlitzerY],
  181.             Blitzer[i][BlitzerZ],
  182.             Blitzer[i][maxspeed],
  183.             Blitzer[i][maxrange],
  184.             Blitzer[i][BlitzerRotation]);
  185.             fwrite(file, coordsstring);
  186.         }
  187.         fclose(file);
  188.     }
  189.     return 1;
  190. }
  191.  
  192. stock BlitzerLaden()
  193. {
  194.     new string[50];
  195.     for(new i = 0;i < MAX_BLITZER; i++)
  196.     {
  197.         Blitzer[i][erstellt] = 0;
  198.     }
  199.     new arrCoords[6][20];
  200.     new strFromFile2[100];
  201.     new File: file = fopen("Blitzer/Blitzer.cfg", io_read);
  202.     if (file)
  203.     {
  204.         new i = 0;
  205.         while (fread(file, strFromFile2))
  206.         {
  207.             split(strFromFile2, arrCoords, '|');
  208.             Blitzer[i][BlitzerX] = floatstr(arrCoords[0]);
  209.             Blitzer[i][BlitzerY] = floatstr(arrCoords[1]);
  210.             Blitzer[i][BlitzerZ] = floatstr(arrCoords[2]);
  211.             Blitzer[i][maxspeed] = strval(arrCoords[3]);
  212.             Blitzer[i][maxrange] = strval(arrCoords[4]);
  213.             Blitzer[i][BlitzerRotation] = floatstr(arrCoords[5]);
  214.             Blitzer[i][erstellt] = 1;
  215.             Blitzer[i][Obj] = CreateObject(18880,Blitzer[i][BlitzerX]+1,Blitzer[i][BlitzerY]+1,Blitzer[i][BlitzerZ]-1,0.0,0.0,Blitzer[i][BlitzerRotation]);
  216.             format(string,sizeof(string),"Blitzer ID: %i\nMax. Speed: %i km/h\nRadius: %i",i,Blitzer[i][maxspeed],Blitzer[i][maxrange]);
  217.             Blitzer[i][label] = Create3DTextLabel(string,GRAU,Blitzer[i][BlitzerX]+1,Blitzer[i][BlitzerY]+1,Blitzer[i][BlitzerZ]+1,Blitzer[i][maxrange] / 2,0);        
  218.             i ++;
  219.         }
  220.         fclose(file);
  221.     }
  222.     return 1;
  223. }
  224.  
  225. stock split(const strsrc[], strdest[][], delimiter)
  226. {
  227.     new i, li;
  228.     new aNum;
  229.     new len;
  230.     while(i <= strlen(strsrc)){
  231.         if(strsrc[i]==delimiter || i==strlen(strsrc)){
  232.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  233.             strdest[aNum][len] = 0;
  234.             li = i+1;
  235.             aNum++;
  236.         }
  237.         i++;
  238.     }
  239.     return 1;
  240. }
  241.  
  242. stock ErmittleGeschwindigkeit(playerid,bool:kmh) {
  243.     new Float:x,Float:y,Float:z,Float:rtn;
  244.     if(IsPlayerInAnyVehicle(playerid))
  245.     {
  246.         GetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z);
  247.     }
  248.     else
  249.     {
  250.         GetPlayerVelocity(playerid,x,y,z);
  251.     }
  252.     rtn = floatsqroot(x*x+y*y+z*z);
  253.     return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
  254. }
  255.  
  256. public BlitzedOff(playerid)
  257. {
  258.     Blitzed[playerid] = 0;
  259.     return 1;
  260. }
  261.  
  262. public IsInRangeOfBlitzer(playerid)
  263. {
  264.     new string[128],zuviel;
  265.     if(!IsPlayerInAnyVehicle(playerid))return 1;
  266.     if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)return 1;
  267.     for(new i = 0; i < MAX_BLITZER; i++)
  268.     {
  269.         if(Blitzer[i][erstellt] == 0)continue;
  270.         if(Blitzed[playerid] == 1)return 1;
  271.         if(Blitzer[i][erstellt] == 1)
  272.         {
  273.             if(IsPlayerInRangeOfPoint(playerid,Blitzer[i][maxrange],Blitzer[i][BlitzerX],Blitzer[i][BlitzerY],Blitzer[i][BlitzerZ]))
  274.             {
  275.                 if(ErmittleGeschwindigkeit(playerid,true) > Blitzer[i][maxspeed])
  276.                 {
  277.                     zuviel = ErmittleGeschwindigkeit(playerid,true)-Blitzer[i][maxspeed];
  278.                     GivePlayerMoney(playerid,-zuviel*10);
  279.                     format(string,sizeof(string),"Du bist %ikm/h zuschnell gefahren! Das heißt $%i Strafe!",zuviel,zuviel*10);
  280.                     SendClientMessage(playerid,ROT,string);
  281.                     Blitzed[playerid] = 1;
  282.                     SetTimerEx("BlitzedOff",6000,false,"i",playerid);
  283.                     return 1;
  284.                 }
  285.             }
  286.         }
  287.     }
  288.     return 1;
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement