Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a comment
- // uncomment the line below if you want to write a filterscript
- //#define FILTERSCRIPT
- #include <a_samp>
- #include <Dini>
- forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
- enum cInfo { //You have to use an enum here, because you have to put different variable types into one array
- model,
- Float:xspawn,
- Float:yspawn,
- Float:zspawn,
- Float:anglespawn,
- col1,
- col2,
- respawn,
- owner[MAX_PLAYER_NAME]
- }
- new CarInfo[MAX_VEHICLES][cInfo];
- new bool:validcar[MAX_VEHICLES];
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Blank Filterscript by your name here");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- #else
- main()
- {
- print("\n----------------------------------");
- print(" Blank Gamemode by your name here");
- print("----------------------------------\n");
- }
- #endif
- public OnGameModeInit()
- {
- // Don't use these lines if it's a filterscript
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 110.4660,1106.0591,14.0094, 269.1425, 0, 0, 0, 0, 0, 0);
- LoadAllVehicles();
- return 1;
- }
- public OnGameModeExit()
- {
- SaveAllVehicles();
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/buy", cmdtext, true, 10) == 0)
- {
- if (PlayerToPoint(15, playerid,110.4660,1106.0591,13.6094))
- {
- ShowPlayerDialog(playerid,0,DIALOG_STYLE_LIST,"CarShop","Sentinel\nSabre\nGreenwood\nBurrito","Rinktis","iseiti");
- }
- else
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "asile ne cia");
- }
- return 1;
- }
- if (strcmp("/test", cmdtext, true, 10) == 0)
- {
- new carid = GetPlayerVehicleID(playerid);
- new test[64];
- format(test, sizeof(test), "%d, %d, %f, %f, %f, %s", carid, CarInfo[carid][model], CarInfo[carid][xspawn], CarInfo[carid][yspawn], CarInfo[carid][zspawn], CarInfo[carid][owner]);
- SendClientMessage(playerid, 0xFFFFFFFF, test);
- new object;
- object = CreateObject(18646, 0, 0, 0, 0.0, 0.0, 96.0);
- AttachObjectToVehicle(object, carid, -0.5, 0.0, 0.9, 0.0, 0.0, 0.0);
- return 1;
- }
- if (strcmp("/respawn", cmdtext, true, 10) == 0)
- {
- SaveAllVehicles();
- DestroyAllVehicles();
- LoadAllVehicles();
- return 1;
- }
- if (strcmp("/savev", cmdtext, true, 10) == 0)
- {
- SaveAllVehicles();
- return 1;
- }
- if (strcmp("/park", cmdtext, true, 10) == 0)
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- new carid = GetPlayerVehicleID(playerid);
- new Float:x, Float:y, Float:z;
- GetVehiclePos(carid, x, y, z);
- CarInfo[carid][xspawn] = x;
- CarInfo[carid][yspawn] = y;
- CarInfo[carid][zspawn] = z;
- SendClientMessage(playerid, 0xFFFFFFFF, "Tavo masina buvo pastatyta.");
- }
- else
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "Tu turi sedeti masinoje.");
- }
- return 1;
- }
- return 0;
- }
- stock strmatch(const String1[], const String2[])
- {
- if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- new IsOwner[MAX_PLAYER_NAME];
- GetPlayerName(playerid, IsOwner, sizeof(IsOwner));
- // if(strcmp(CarInfo[vehicleid][owner], IsOwner, true, strlen(CarInfo[vehicleid][owner])))
- if(!strmatch(CarInfo[vehicleid][owner], IsOwner))
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "Jus negalite vairuoti sios masinos!");
- TogglePlayerControllable(playerid,1);
- RemovePlayerFromVehicle(playerid);
- }
- else
- {
- }
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- return 1;
- }
- public OnPlayerObjectMoved(playerid, objectid)
- {
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnVehicleMod(playerid, vehicleid, componentid)
- {
- return 1;
- }
- public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
- {
- return 1;
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnRconLoginAttempt(ip[], password[], success)
- {
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- return 1;
- }
- public OnPlayerStreamIn(playerid, forplayerid)
- {
- return 1;
- }
- public OnPlayerStreamOut(playerid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamOut(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == 0) //Jei dialogid bus lygus 0
- {
- if(response) //Jei paspaude mygtuka "Sutinku"
- {
- new BuyerName[20];
- GetPlayerName(playerid, BuyerName, sizeof(BuyerName));
- if(listitem == 0) //Jei pirmas pasirinkimas
- {
- // new CarBla[256];
- // CreateVehicle(405, 102.0081,1109.1520,13.5795,181.9413,69,1,3600);
- // format(message, sizeof(message), "parkinai masina cord: %f %f %f", vehx, vehy, vehz);
- CreateVehicleEx(405, 102.0081, 1109.1520, 13.5795, 181.9413, 69, 1, 3600, BuyerName);
- }
- else if(listitem == 1) //Jei antras pasirinkimas
- {
- CreateVehicleEx(475, 102.0081, 1109.1520, 13.5795, 181.9413, 69, 1, 3600, BuyerName);
- }
- else if(listitem == 2) //Jei antras pasirinkimas
- {
- CreateVehicleEx(492, 102.0081, 1109.1520, 13.5795, 181.9413, 69, 1, 3600, BuyerName);
- }
- else if(listitem == 3) //Jei antras pasirinkimas
- {
- CreateVehicleEx(482, 102.0081, 1109.1520, 13.5795, 181.9413, 69, 1, 3600, BuyerName);
- }
- }
- return 1;
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
- {
- if(IsPlayerConnected(playerid))
- {
- new Float:oldposx, Float:oldposy, Float:oldposz;
- new Float:tempposx, Float:tempposy, Float:tempposz;
- GetPlayerPos(playerid, oldposx, oldposy, oldposz);
- tempposx = (oldposx -x);
- tempposy = (oldposy -y);
- tempposz = (oldposz -z);
- //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
- if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
- {
- return 1;
- }
- }
- return 0;
- }
- stock GetFreeVehicleSlot()
- {
- for(new i = 1; i < sizeof(validcar); i ++)
- {
- if(!validcar[i]) return i;
- }
- return -1;
- }
- stock CreateVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[])
- {
- //now put all the data into the array
- //To get the index, use the first free slot with the function before
- new carid = GetFreeVehicleSlot();
- CarInfo[carid][model] = modelid;
- CarInfo[carid][xspawn] = x;
- CarInfo[carid][yspawn] = y;
- CarInfo[carid][zspawn] = z;
- CarInfo[carid][anglespawn] = angle;
- CarInfo[carid][col1] = color1;
- CarInfo[carid][col2] = color2;
- CarInfo[carid][respawn] = respawntime;
- // CarInfo[carid][owner] = ownername;
- strcat(CarInfo[carid][owner], ownername, MAX_PLAYER_NAME);
- //... you can just add any data you like
- //dont forget to mark the carslot as used in the validcar array
- validcar[carid] = true;
- //At last create the vehicle in the game
- CreateVehicle(modelid, x, y, z, angle, color1, color2, respawntime);
- return carid; //Make the function return the carid/array index. This is not necessarily needed, but good style
- }
- stock SaveVehicle(vehicle, filename[36])
- {
- dini_Create(filename);
- dini_IntSet( filename , "Model", CarInfo[vehicle][model]);
- dini_FloatSet(filename , "XSpawn", CarInfo[vehicle][xspawn]);
- dini_FloatSet(filename, "YSpawn", CarInfo[vehicle][yspawn]);
- dini_FloatSet(filename, "ZSpawn", CarInfo[vehicle][zspawn]);
- dini_FloatSet(filename, "Angle", CarInfo[vehicle][anglespawn]);
- dini_IntSet(filename, "COL1", CarInfo[vehicle][col1]);
- dini_IntSet(filename, "COL2", CarInfo[vehicle][col2]);
- dini_IntSet(filename, "Respawn", CarInfo[vehicle][respawn]);
- dini_Set(filename, "Owner", CarInfo[vehicle][owner]);
- }
- //this function will save all vehicles in files with a continous number as name, because it will be easier to load
- //than some other name
- stock SaveAllVehicles()
- {
- new saveindex = 1;
- new fname[36];
- for(new i = 1; i < MAX_VEHICLES; i ++)
- {
- if(validcar[i])
- {
- format(fname, sizeof(fname), "/vehicles/%d.ini", saveindex); //You can also add a subfolder here<.
- //ex: format(fname, sizeof(fname), "/vehicles/%d.ini", saveindex); //will put all the files onto /scriptfiles/vehicles/ if the folder exists
- SaveVehicle(i, fname);
- saveindex ++; //Increase the filename number for the next vehicle
- }
- }
- }
- stock LoadVehicle(filename[36])
- {
- // new iniid = ini_OpenIni(filename);
- //Now just use CreateVehicleEx and load all the parameters from the ini file
- //The function will do all the rest for you
- // ini_CloseIni(iniid);
- CreateVehicleEx(dini_Int(filename, "Model"), dini_Float(filename, "XSpawn"), dini_Float(filename, "YSpawn"), dini_Float(filename, "ZSpawn"), dini_Float(filename, "Angle"), dini_Int(filename, "COL1"), dini_Int(filename, "COL2"),dini_Int(filename, "Respawn"), dini_Get(filename, "Owner") );
- }
- stock LoadAllVehicles()
- {
- new fname[36];
- new index = 1;
- format(fname, sizeof(fname), "/vehicles/%d.ini", index);
- while(fexist(fname)) //Here's the reason why the ini files are named continuosly
- //This function keeps loading the files with next number as long as there is a next one
- //and then stops loading, so you do not need a plugin to get all files in a folder or so
- {
- LoadVehicle(fname);
- index ++;
- format(fname, sizeof(fname), "/vehicles/%d.ini", index);
- }
- }
- stock DestroyAllVehicles()
- {
- for(new i = 0; i < MAX_VEHICLES; i++)
- {
- DestroyVehicle(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment