//First, of course we need to include these files first
#include <a_samp> //Without this, we won't be able to use all samp functions/callbacks
#include <zcm> //Without this, we won't be able to create commands
#include <sscanf2> //Without this, we won't be able to use creating commands
#include <YSI\y_ini> //Without this, we won't be able to save and load files
new idoffile[MAX_PLAYERS]; //this will be used later in commands for saving Angle of vehicle and saving it
#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, // This will be used to save ID of vehicle
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
//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; //filedd 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;
}
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 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 files
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 OnPlayerConnect(playerid)
{
idoffile[playerid] = -1;
return 1;
}
Why? with this system u can make house system, bizz...
In this tutorial i just explained how does work dynamic systems and how u should use it, with this u can make whatever you want another dynamic system... |
Well you should at least explain the difference between a dynamic and static system. The positive and negative sides of static/dynamic systems. And explain how you can apply the same kind of system for multiple purposes. Otherwise it's fine.
|
Ahh thanks, i totally forgot about that, i will edit tut, thanks
|
#include <zcmd>
One typo...
pawn Code:
|