18.07.2014, 02:59
Hey! So I decided to take a crack at making my own dynamic vehicles system, where you can create a vehicle dynamically via /dvcreate [model] [colour 1] [colour 2].
Below, is the code.
However, doing it my way has made it impossible to spawn throwaway vehicles (vehicles that are used by admins, and go away after the gamemodeexits), delete dynamic cars dynamically, and edit dynamic cars dynamically. If you're unsure why, its because I save using the car ids after the player is inside the car (PutPlayerInVehicle, GetPlayerVehicleID, dini_Create (file of course being named the vehicle id .ini (%d.ini)))
However, this is conflicting as crap.
I want to be able to do /dl, and get the cars id by looking at the ID, and being able to do /dvdelete. However, if I delete vehicles, then I cause conflictions because when the vehicles spawn, their ID will not match their file and it will not properly delete the vehicles and the file.
TLDR; So here's what I mean if you don't quite get it: When vehicles spawn, they are to take on the ID of their file, but if I allow the use of dynamically deleting, and creating thowaway cars, then their in game ID will not match the id of their file.
Example:
*Jason spawns Vehicle 9*
*Jason deletes Vehicle 8*
*Jason restarts the server*
*Vehicle 9, takes on in-game ID 8, while keeping their file name 9.ini*
See the confliction?
Giving a HUGE REP+ to anyone who can help me with this.
Below, is the code.
pawn Код:
CMD:dvcreate(playerid, params[])
{
if(Player[playerid][AdminLevel] >= 4)
{
new carid, col1, col2, Float: dvposx, Float: dvposy, Float: dvposz, Float: dvposa, model, string[128], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(sscanf(params, "ddd", model, col1, col2))
{
SendClientMessage(playerid, WHITE, "SYNTAX: /dvcreate [model] [colour 1] [colour 2]");
SendClientMessage(playerid, GREY, "Models: Vehicle models begin at 400, and end at 611.");
return 1;
}
else if(model < 400 || model > 611)
{
{
SendClientMessage(playerid, GREY, "Vehicle IDs start at 400 and end at 611.");
SendClientMessage(playerid, WHITE, "SYNTAX: /dvcreate [model] [colour 1] [colour 2]");
SendClientMessage(playerid, GREY, "Models: Vehicle models begin at 400, and end at 611.");
return 1;
}
}
else
{
GetPlayerPos(playerid, dvposx, dvposy, dvposz);
carid = CreateVehicle(model, dvposx, dvposy+4, dvposz, dvposa, col1, col2, -1);
GetVehicleZAngle(carid, dvposa);
PutPlayerInVehicle(playerid, carid, 0);
format(string, sizeof(string), "Vehicles/%d.ini", GetPlayerVehicleID(playerid));
if(!fexist(string))
{
dini_Create(string);
}
dini_IntSet(string, "model", model);
dini_IntSet(string, "Faction", 0);
dini_IntSet(string, "Gang", 0);
dini_IntSet(string, "Rank", 0);
dini_FloatSet(string, "ParkedX", dvposx);
dini_FloatSet(string, "ParkedY", dvposy);
dini_FloatSet(string, "ParkedZ", dvposz);
dini_FloatSet(string, "ParkedA", dvposa);
dini_FloatSet(string, "VehicleVW", GetPlayerVirtualWorld(playerid));
dini_FloatSet(string, "VehicleInt", GetPlayerInterior(playerid));
dini_IntSet(string, "Colour1", col1);
dini_IntSet(string, "Colour2", col2);
dini_IntSet(string, "RespawnDelay", -1);
dini_IntSet(string, "VehAdminLevel", 0);
format(string, sizeof(string), "[Admin] %s has created dynamic vehicle %d (Model %d).", name, carid, model);
AdminActionLog(string);
return 1;
}
}
else
{
SendClientMessage(playerid, GREY, NOAUTH);
}
return 1;
}
However, this is conflicting as crap.
I want to be able to do /dl, and get the cars id by looking at the ID, and being able to do /dvdelete. However, if I delete vehicles, then I cause conflictions because when the vehicles spawn, their ID will not match their file and it will not properly delete the vehicles and the file.
TLDR; So here's what I mean if you don't quite get it: When vehicles spawn, they are to take on the ID of their file, but if I allow the use of dynamically deleting, and creating thowaway cars, then their in game ID will not match the id of their file.
Example:
*Jason spawns Vehicle 9*
*Jason deletes Vehicle 8*
*Jason restarts the server*
*Vehicle 9, takes on in-game ID 8, while keeping their file name 9.ini*
See the confliction?
Giving a HUGE REP+ to anyone who can help me with this.