Advertisement
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 <sscanf2>
- #include <zcmd>
- #include <YSI\y_ini>
- new idoffile[MAX_PLAYERS];
- #define VEHICLE_FOLDER "Vehicles/Vehicle_%d.ini" //This will be path were will be saved files of vehicles
- //Now let's create an enumerator that holds vehicle's information
- enum vfInfo //We name our enumerator as vfInfo. You can name it however you want.
- {
- dID,
- dModel, //This will be used to save model of vehicle
- Float:dX, //This will be used to save X cordinate of vehicle
- Float:dY, //This will be used to save Y cordinate of vehicle
- Float:dZ, //This will be used to save Z cordinate of vehicle
- Float:dA, //This will be used to save Angle of vehicle
- dColor1, //This will be used to save Vehicle color1
- dColor2, //This will be used to save Vehicle color2
- };
- new DVehicles[MAX_VEHICLES][vfInfo]; //Variable that stores enumerator above
- main()
- {
- print("\n----------------------------------");
- print(" SA-MP tutorial by Dusan01(Vuzimir)");
- print("----------------------------------\n");
- }
- public OnGameModeInit()
- {
- // Don't use these lines if it's a filterscript
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- for(new b = 0; b < sizeof(DVehicles); b++) //loop
- {
- new gFile[35]; //string
- format(gFile, 50, VEHICLE_FOLDER ,b); //formating string
- if(fexist(gFile)) //checking does file exist witch is in format
- {
- INI_ParseFile(gFile, "LoadVehicle", .bExtra = true, .extra = b); //Y_INI function to load from vehicles
- if(DVehicles[b][dModel] != 0) //if model is everytning expect 0
- {
- DVehicles[b][dID] = CreateVehicle(DVehicles[b][dModel], DVehicles[b][dX],DVehicles[b][dY],DVehicles[b][dZ],DVehicles[b][dA], DVehicles[b][dColor1], DVehicles[b][dColor2], 0); //creating vehicle
- }
- }
- }
- return 1;
- }
- public OnGameModeExit()
- {
- 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)
- {
- idoffile[playerid] = -1;
- 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("/mycommand", cmdtext, true, 10) == 0)
- {
- // Do something here
- return 1;
- }
- return 0;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- 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)
- {
- if(newkeys & KEY_YES) //if player pres KEY_YES that is 'Y'
- {
- if(idoffile[playerid] > -1) //if id of file is bigger then -1
- {
- new fileid = idoffile[playerid]; //geting id of file
- new vehz = GetPlayerVehicleID(playerid); //geting player vehicle id
- new Float:X,Float:Y,Float:Z,Float:A; //variables for pos of vehicle
- GetVehicleZAngle(vehz, A); //geting vehicle Angle
- GetPlayerPos(playerid, X,Y,Z); //Getting player position and storing i to X,Y,Z
- DVehicles[fileid][dX] = X; //setting new cordinate X for vehicle
- DVehicles[fileid][dY] = Y; //setting new cordinate Y for vehicle
- DVehicles[fileid][dZ] = Z; //setting new cordinate Z for vehicle
- DVehicles[fileid][dA] = A; //setting Angle for vehicle
- DestroyVehicle(vehz); //Destronying vehicle
- CreateVehicle(DVehicles[fileid][dModel], DVehicles[fileid][dX],DVehicles[fileid][dY],DVehicles[fileid][dZ],DVehicles[fileid][dA], DVehicles[fileid][dColor1], DVehicles[fileid][dColor2], 0); //creating new vehicle with saved variables
- SaveVehicle(fileid); //Now saving vehicle to file
- idoffile[playerid] = -1; //seting player variable to -1
- RemovePlayerFromVehicle(playerid); //Removing player from vehicle
- SendClientMessage(playerid,-1,"U have cretated vehicle, congratz!");
- return 1;
- }
- }
- 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[])
- {
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- //now lets add callback for saving and loading
- forward SaveVehicle(fileid); //This will forward for callback SaveVehicle
- public SaveVehicle(fileid)
- {
- new dFile[128]; //This is string witch will search for file
- format(dFile, sizeof(dFile),VEHICLE_FOLDER,fileid); //Formating string
- new INI:File = INI_Open(dFile); //Opening file
- INI_WriteInt(File,"Model",DVehicles[fileid][dModel]); //Saving Model to file from variable dModel
- INI_WriteFloat(File,"X",DVehicles[fileid][dX]); //Saving Cordinate X to file from variable dX
- INI_WriteFloat(File,"Y",DVehicles[fileid][dY]); //Saving Cordinate Y to file from variable dY
- INI_WriteFloat(File,"Z",DVehicles[fileid][dZ]); //Saving Cordinate Z to file from variable dZ
- INI_WriteFloat(File,"A",DVehicles[fileid][dA]); //Saving Angle to file from variable dA
- INI_WriteInt(File,"Color1",DVehicles[fileid][dColor1]); //Saving Color1 to file from variable dColor1
- INI_WriteInt(File,"Color2",DVehicles[fileid][dColor2]); //Saving Color2 to file from variable dColor2
- INI_Close(File);
- return 1;
- }
- forward LoadVehicle(fileid, name[], value[]); //This will forward for callback LoadVehicle
- public LoadVehicle(fileid, name[], value[])
- {
- INI_Int("Model",DVehicles[fileid][dModel]); //This will reard Model from file and store it to dModel
- INI_Float("X",DVehicles[fileid][dX]); //This will reard Cordinate X from file and store it to dX
- INI_Float("Y",DVehicles[fileid][dY]); //This will reard Cordinate Y from file and store it to dY
- INI_Float("Z",DVehicles[fileid][dZ]); //This will reard Cordinate Z from file and store it to dZ
- INI_Float("A",DVehicles[fileid][dA]); //This will reard Angle from file and store it to dA
- INI_Int("Color1",DVehicles[fileid][dColor1]); //This will reard Color1 from file and store it to dColor1
- INI_Int("Color2",DVehicles[fileid][dColor2]); //This will reard Color1 from file and store it to dColor1
- return 1;
- }
- CMD:createveh(playerid, params[]) //command for create vehicle
- {
- new fileid = 0; //variable for file counting, witch file is not created
- new Float:X,Float:Y,Float:Z; //Varables for position
- GetPlayerPos(playerid, X,Y,Z); //Getting player position and storing i to X,Y,Z
- for(new b = 0; b < sizeof(DVehicles); b++) //this is loop
- {
- if(DVehicles[b][dModel] != 0) //checking witch files are free (not created)
- {
- fileid = b+1; //Saving file ID to fileid
- }
- }
- if(fileid > MAX_VEHICLES) return SendClientMessage(playerid, -1, "MAX_VEHICLES reached, u cannot create more vehicles"); //if MAX_VEHICLE reach's you will not be in able to create more vehicles
- new model,color1, color2; //Againg more variables for parameters
- if(sscanf(params, "iii", model, color1, color2)) //In this part we will use sscanf, this is checking are all parameters filled to script can create vehicle
- {
- SendClientMessage(playerid, -1, "/createveh [Model] [Color1] [Color2]");
- return 1;
- }
- DVehicles[fileid][dModel] = model; //this will save parameters witch we filled in to variables
- DVehicles[fileid][dX] = X; //this will save parameters witch we filled in to variables
- DVehicles[fileid][dY] = Y; //this will save parameters witch we filled in to variables
- DVehicles[fileid][dZ] = Z; //this will save parameters witch we filled in to variables
- DVehicles[fileid][dColor1] = color1; //this will save parameters witch we filled in to variables
- DVehicles[fileid][dColor2] = color2; //this will save parameters witch we filled in to variables
- DVehicles[fileid][dID] = CreateVehicle(model, X,Y,Z,0, color1, color2, 0); //creating vehicle
- PutPlayerInVehicle(playerid, DVehicles[fileid][dID], 0); //Putting player in vehicle witch player created
- idoffile[playerid] = fileid;
- SendClientMessage(playerid, -1, "You have created vehicle, now select angle in witch direction you want and press 'Y' to finish and save file.");
- return 1;
- }
- CMD:destroyveh(playerid, params[]) //command for destroy vehilce
- {
- new fileid; //filed for sscanf
- if(sscanf(params, "i", fileid)) //In this part we will use sscanf, this is checking are all parameters filled to script can create vehicle
- {
- SendClientMessage(playerid, -1, "/destroyveh [FILE ID]");
- return 1;
- }
- new dFile[128]; //This is string witch will search for file
- format(dFile, sizeof(dFile),VEHICLE_FOLDER,fileid); //Formating string
- if(!fexist(dFile)) return SendClientMessage(playerid, -1, "That file does not exist!");//checking does file exist witch is in format
- fremove(dFile); //Removing file
- DestroyVehicle(DVehicles[fileid][dID]); //Destroying vehicle
- DVehicles[fileid][dModel] = 0; //Setting variables to default
- DVehicles[fileid][dX] = 0.0; //Setting variables to default
- DVehicles[fileid][dY] = 0.0; //Setting variables to default
- DVehicles[fileid][dZ] = 0.0; //Setting variables to default
- DVehicles[fileid][dA] = 0.0; //Setting variables to default
- DVehicles[fileid][dColor1] = 0; //Setting variables to default
- DVehicles[fileid][dColor2] = 0; //Setting variables to default
- SendClientMessage(playerid, -1, "You have been destroyed vehicle");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement