Advertisement
Guest User

Dynamic Car System

a guest
Jan 5th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.67 KB | None | 0 0
  1. Copyright by SporSeba97
  2.  
  3. #define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <dini>
  7. #define Rot 0xAA3333AA
  8.  
  9. #define respawn_delay -1
  10. enum CInfo
  11. {
  12.     Float:x,
  13.     Float:y,
  14.     Float:z,
  15.     Float:angle,
  16.     modelid,
  17.     color1,
  18.     color2,
  19. }
  20. new CarInfo[MAX_VEHICLES][CInfo];
  21. new CarAnzahl;
  22. forward Carsschreiben();
  23. forward Carslesen();
  24. new Farbe1[MAX_VEHICLES];
  25. new Farbe2[MAX_VEHICLES];
  26. new schreibversuche;
  27. new leseversuche;
  28. new wunschfarbe1[MAX_PLAYERS];
  29. new wunschfarbe2[MAX_PLAYERS];
  30. new CarID[MAX_VEHICLES];
  31.  
  32.  
  33. public Carsschreiben()
  34. {
  35.     if(schreibversuche==3)
  36.     {
  37.         print("Schreiben nach 3. Versuch fehlgeschlagen!!");
  38.         return 1;
  39.     }
  40.     new CarDatei[250];
  41.     format(CarDatei,sizeof(CarDatei),"/Cars.ini");
  42.     dini_IntSet(CarDatei,"Anzahl",CarAnzahl);
  43.     if(dini_Exists(CarDatei))
  44.     {
  45.         for(new i = 0; i<=(CarAnzahl);i++)
  46.         {
  47.             new string[250];
  48.             format(string,sizeof(string),"%i x",i);
  49.             dini_FloatSet(CarDatei,string,CarInfo[i][x]);
  50.             format(string,sizeof(string),"%i y",i);
  51.             dini_FloatSet(CarDatei,string,CarInfo[i][y]);
  52.             format(string,sizeof(string),"%i z",i);
  53.             dini_FloatSet(CarDatei,string,CarInfo[i][z]);
  54.             format(string,sizeof(string),"%i angle",i);
  55.             dini_FloatSet(CarDatei,string,CarInfo[i][angle]);
  56.             format(string,sizeof(string),"%i modelid",i);
  57.             dini_IntSet(CarDatei,string,CarInfo[i][modelid]);
  58.             format(string,sizeof(string),"%i color1",i);
  59.             dini_IntSet(CarDatei,string,CarInfo[i][color1]);
  60.             format(string,sizeof(string),"%i color2",i);
  61.             dini_IntSet(CarDatei,string,CarInfo[i][color2]);
  62.         }
  63.         print("Cars in Datei gespeichert!!");
  64.         schreibversuche=0;
  65.     }
  66.     else
  67.     {
  68.         print("Error: Datei nicht gefunden!!");
  69.         print("Datei wird neu erstellt!!");
  70.         dini_Create(CarDatei);
  71.         print("Neuer Schreib versuch");
  72.         schreibversuche++;
  73.         Carsschreiben();
  74.     }
  75.     return 1;
  76. }
  77.  
  78. public Carslesen()
  79. {
  80.     if(leseversuche==3)
  81.     {
  82.         print("Schreiben nach 3. Versuch fehlgeschlagen!!");
  83.         return 1;
  84.     }
  85.     new CarDatei[250];
  86.     format(CarDatei,sizeof(CarDatei),"/Cars.ini");
  87.     CarAnzahl=dini_Int(CarDatei,"Anzahl");
  88.     if(dini_Exists(CarDatei))
  89.     {
  90.         for(new i = 0; i<=(CarAnzahl);i++)
  91.         {
  92.             new string[250];
  93.             format(string,sizeof(string),"%i x",i);
  94.             CarInfo[i][x]=dini_Float(CarDatei,string);
  95.             format(string,sizeof(string),"%i y",i);
  96.             CarInfo[i][y]=dini_Float(CarDatei,string);
  97.             format(string,sizeof(string),"%i z",i);
  98.             CarInfo[i][z]=dini_Float(CarDatei,string);
  99.             format(string,sizeof(string),"%i angle",i);
  100.             CarInfo[i][angle]=dini_Float(CarDatei,string);
  101.             format(string,sizeof(string),"%i modelid",i);
  102.             CarInfo[i][modelid]=dini_Int(CarDatei,string);
  103.             format(string,sizeof(string),"%i color1",i);
  104.             CarInfo[i][color1]=dini_Int(CarDatei,string);
  105.             format(string,sizeof(string),"%i color2",i);
  106.             CarInfo[i][color2]=dini_Int(CarDatei,string);
  107.             CarID[i]=AddStaticVehicleEx(CarInfo[i][modelid],CarInfo[i][x],CarInfo[i][y],CarInfo[i][z],CarInfo[i][angle],CarInfo[i][color1],CarInfo[i][color2],respawn_delay);
  108.         }
  109.         print("Cars aus Datei gelesen");
  110.         schreibversuche=0;
  111.     }
  112.     else
  113.     {
  114.         print("Error: Datei nicht gefunden!!");
  115.         print("Datei wird neu erstellt!!");
  116.         dini_Create(CarDatei);
  117.         print("Neuer leseversuch");
  118.         schreibversuche++;
  119.         Carsschreiben();
  120.         Carslesen();
  121.     }
  122.     return 1;
  123. }
  124.  
  125. public OnFilterScriptInit()
  126. {
  127.     print("\n--------------------------------------");
  128.     print(" Dynamic Car System by SporSeba97");
  129.     print("--------------------------------------\n");
  130.     Carslesen();
  131.     return 1;
  132. }
  133.  
  134. public OnFilterScriptExit()
  135. {
  136.     Carsschreiben();
  137.     return 1;
  138. }
  139.  
  140.  
  141. public OnVehicleSpawn(vehicleid)
  142. {
  143.     return 1;
  144. }
  145.  
  146. public OnVehicleDeath(vehicleid, killerid)
  147. {
  148.     return 1;
  149. }
  150.  
  151. public OnPlayerText(playerid, text[])
  152. {
  153.     return 1;
  154. }
  155.  
  156. public OnPlayerCommandText(playerid, cmdtext[])
  157. {
  158.     if(!IsPlayerConnected(playerid)) return 1;
  159.     new idx;
  160.     new cmd[250];
  161.     cmd = strtok(cmdtext, idx);
  162.     new tmp[250];
  163.     if(strcmp(cmd,"/farbe",true)==0)
  164.     {
  165.         if(!IsPlayerAdmin(playerid))
  166.         {
  167.             SendClientMessage(playerid,Rot,"Du bist kein Admin!!");
  168.             return 1;
  169.         }
  170.         tmp = strtok(cmdtext, idx);
  171.         if(!strlen(tmp))
  172.         {
  173.             SendClientMessage(playerid, Rot, "Benutze /farbe [Farbe1][Farbe2]");
  174.             return 1;
  175.         }
  176.         wunschfarbe1[playerid]=strval(tmp);
  177.         tmp = strtok(cmdtext, idx);
  178.         if(!strlen(tmp))
  179.         {
  180.             SendClientMessage(playerid, Rot, "Benutze /farbe [Farbe1][Farbe2]");
  181.             return 1;
  182.         }
  183.         wunschfarbe2[playerid]=strval(tmp);
  184.         new string[250];
  185.         format(string, sizeof(string), "Farbe 1: %i Farbe 2: %i", wunschfarbe1[playerid],wunschfarbe2[playerid]);
  186.         SendClientMessage(playerid, Rot, string);
  187.         return 1;
  188.     }
  189.     if (strcmp(cmd,"/sveh",true) == 0)
  190.     {
  191.         if(!IsPlayerAdmin(playerid))
  192.         {
  193.             SendClientMessage(playerid,Rot,"Du bist kein Admin!!");
  194.             return 1;
  195.         }
  196.         tmp = strtok(cmdtext, idx);
  197.         if(!strlen(tmp))
  198.         {
  199.             SendClientMessage(playerid, Rot, "Benutze /sveh [modelid][Farbe1][Farbe2]");
  200.             return 1;
  201.         }
  202.         new model;
  203.         model=strval(tmp);
  204.         tmp = strtok(cmdtext, idx);
  205.         new cfarbe1;
  206.         if(!strlen(tmp))
  207.         {
  208.             cfarbe1=wunschfarbe1[playerid];
  209.         }
  210.         else
  211.         {
  212.             cfarbe1=strval(tmp);
  213.         }
  214.         new cfarbe2;
  215.         tmp = strtok(cmdtext, idx);
  216.         if(!strlen(tmp))
  217.         {
  218.             cfarbe2=wunschfarbe2[playerid];
  219.         }
  220.         else
  221.         {
  222.             cfarbe2=strval(tmp);
  223.         }
  224.         if(model < 400 || model > 611)
  225.         {
  226.         SendClientMessage(playerid, Rot, "   Du kannst nur ein Model zwischen 400 und 611 auswählen!!");
  227.         return 1;
  228.         }
  229.         new Float:X,Float:Y,Float:Z;
  230.         GetPlayerPos(playerid, X,Y,Z);
  231.         new carid = AddStaticVehicleEx(model, X,Y,Z, 0.0, cfarbe1, cfarbe2, respawn_delay);
  232.         Farbe1[carid]=cfarbe1;
  233.         Farbe2[carid]=cfarbe2;
  234.         PutPlayerInVehicle(playerid,carid,0);
  235.         SendClientMessage(playerid,Rot,"Du hast ein neues Auto erzeugt!");
  236.         return 1;
  237.     }
  238.     if(strcmp(cmd,"/speichern",true)==0)
  239.     {
  240.         new VID;
  241.         VID=GetPlayerVehicleID(playerid);
  242.         CarAnzahl++;
  243.         CarInfo[CarAnzahl][modelid]=GetVehicleModel(VID);
  244.         GetVehiclePos(VID,CarInfo[CarAnzahl][x],CarInfo[CarAnzahl][y],CarInfo[CarAnzahl][z]);
  245.         GetVehicleZAngle(VID,CarInfo[CarAnzahl][angle]);
  246.         CarInfo[CarAnzahl][color1]=Farbe1[VID];
  247.         CarInfo[CarAnzahl][color2]=Farbe2[VID];
  248.         return 1;
  249.     }
  250.     if(strcmp(cmd,"/getid",true)==0)
  251.     {
  252.         if(!IsPlayerAdmin(playerid))
  253.         {
  254.             SendClientMessage(playerid,Rot,"Du bist kein Admin!");
  255.             return 1;
  256.         }
  257.         new ID = GetPlayerVehicleID(playerid);
  258.         for(new i = 0;i<=CarAnzahl;i++)
  259.         {
  260.             if(CarID[i]==ID)
  261.             {
  262.                 new string[250];
  263.                 format(string,sizeof(string),"Das Fahrzeug hat die ID %i",i);
  264.                 SendClientMessage(playerid,Rot,string);
  265.                 return 1;
  266.             }
  267.         }
  268.         SendClientMessage(playerid,Rot,"Dieses Auto ist nicht registriert");
  269.         return 1;
  270.     }
  271.     return 0;
  272. }
  273.  
  274. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  275. {
  276.     return 1;
  277. }
  278.  
  279. public OnPlayerExitVehicle(playerid, vehicleid)
  280. {
  281.     return 1;
  282. }
  283.  
  284. public OnPlayerStateChange(playerid, newstate, oldstate)
  285. {
  286.     return 1;
  287. }
  288.  
  289. public OnPlayerEnterCheckpoint(playerid)
  290. {
  291.     return 1;
  292. }
  293.  
  294. public OnPlayerLeaveCheckpoint(playerid)
  295. {
  296.     return 1;
  297. }
  298.  
  299. public OnPlayerEnterRaceCheckpoint(playerid)
  300. {
  301.     return 1;
  302. }
  303.  
  304. public OnPlayerLeaveRaceCheckpoint(playerid)
  305. {
  306.     return 1;
  307. }
  308.  
  309. public OnRconCommand(cmd[])
  310. {
  311.     return 1;
  312. }
  313.  
  314. public OnPlayerRequestSpawn(playerid)
  315. {
  316.     return 1;
  317. }
  318.  
  319. public OnObjectMoved(objectid)
  320. {
  321.     return 1;
  322. }
  323.  
  324. public OnPlayerObjectMoved(playerid, objectid)
  325. {
  326.     return 1;
  327. }
  328.  
  329. public OnPlayerPickUpPickup(playerid, pickupid)
  330. {
  331.     return 1;
  332. }
  333.  
  334. public OnVehicleMod(playerid, vehicleid, componentid)
  335. {
  336.     return 1;
  337. }
  338.  
  339.  
  340. public OnPlayerSelectedMenuRow(playerid, row)
  341. {
  342.     return 1;
  343. }
  344.  
  345. public OnPlayerExitedMenu(playerid)
  346. {
  347.     return 1;
  348. }
  349.  
  350. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  351. {
  352.     return 1;
  353. }
  354.  
  355. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  356. {
  357.     return 1;
  358. }
  359.  
  360. public OnRconLoginAttempt(ip[], password[], success)
  361. {
  362.     return 1;
  363. }
  364.  
  365. public OnPlayerUpdate(playerid)
  366. {
  367.     return 1;
  368. }
  369.  
  370. public OnPlayerStreamIn(playerid, forplayerid)
  371. {
  372.     return 1;
  373. }
  374.  
  375. public OnPlayerStreamOut(playerid, forplayerid)
  376. {
  377.     return 1;
  378. }
  379.  
  380. public OnVehicleStreamIn(vehicleid, forplayerid)
  381. {
  382.     return 1;
  383. }
  384.  
  385. public OnVehicleStreamOut(vehicleid, forplayerid)
  386. {
  387.     return 1;
  388. }
  389.  
  390. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  391. {
  392.     return 0;
  393. }
  394.  
  395. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  396. {
  397.     return 1;
  398. }
  399.  
  400. strtok(const string[], &index)
  401. {
  402.     new length = strlen(string);
  403.     while ((index < length) && (string[index] <= ' '))
  404.     {
  405.         index++;
  406.     }
  407.  
  408.     new offset = index;
  409.     new result[20];
  410.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  411.     {
  412.         result[index - offset] = string[index];
  413.         index++;
  414.     }
  415.     result[index - offset] = EOS;
  416.     return result;
  417. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement