Guest User

Blitzersystem - Dini

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