12.03.2017, 22:42
(
Последний раз редактировалось se3a; 13.03.2017 в 03:25.
)
im new here i want some help pls
i trying to make commend for buy vehicles > callback to this stock but i failed
can somone help me pls!
i trying to make commend for buy vehicles > callback to this stock but i failed
can somone help me pls!
PHP код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <Streamer>
#include <foreach>
#include <YSI\y_ini>
new bool:validcar[MAX_VEHICLES];
stock GetFreeVehicleSlot()
{
for(new i = 0; i < sizeof(validcar); i ++)
{
if(!validcar[i]) return i;
}
return -1;
}
enum carDataEnum { //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 carData[MAX_VEHICLES][carDataEnum];
stock CreateVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[MAX_PLAYER_NAME])
{
//now put all the data into the array
//To get the index, use the first free slot with the function before
new carid = GetFreeVehicleSlot();
carData[carid][model] = modelid;
carData[carid][xspawn] = x;
carData[carid][yspawn] = y;
carData[carid][zspawn] = z;
carData[carid][anglespawn] = angle;
carData[carid][col1] = color1;
carData[carid][col2] = color2;
carData[carid][respawn] = respawntime;
carData[carid][owner] = ownername;
//... 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])
{
new iniid = ini_CreateIniFile(filename);
ini_SetInt(iniid, "Model", carData[vehicle][model]);
ini_SetFloat(iniid, "XSpawn", carData[vehicle][xspawn]);
//... do this for all elements in the array/enum
ini_CloseIni(iniid);
}
//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 = 0;
new fname[36];
for(new i = 0; 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
CreateVehicleEx(ini_GetInt(iniid, "Model"), ini_GetFloat(iniid, "XSpawn"), ...);
ini_CloseIni(iniid);
}
stock LoadAllVehicles()
{
new fname[36];
new index = 0;
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);
}
}
CMD:createhouse(playerid, params[])
{
//now put all the data into the array
//To get the index, use the first free slot with the function before
new carid = GetFreeVehicleSlot();
carData[carid][model] = modelid;
carData[carid][xspawn] = x;
carData[carid][yspawn] = y;
carData[carid][zspawn] = z;
carData[carid][anglespawn] = angle;
carData[carid][col1] = color1;
carData[carid][col2] = color2;
carData[carid][respawn] = respawntime;
carData[carid][owner] = ownername;
//... 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;
}