/car [id] problem -
Fantje - 14.03.2015
Yoo
I have an command to spawn car:
/car [id]
The problem is that when you spawn a car it spawns good, but when you spawn a new car the old one disappear.
How to fix that?
PHP код:
CMD:car(playerid,params[]) {
if(PlayerInfo[playerid][Level] >= 3) {
new tmp[256], tmp2[256], tmp3[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index); tmp3 = strtok(params,Index);
if(isnull(tmp)) return SendClientMessage(playerid, red, "USAGE: /car [Modelid/Name] [colour1] [colour2]");
new car, colour1, colour2, string[128];
if(!IsNumeric(tmp)) car = GetVehicleModelIDFromName(tmp); else car = strval(tmp);
if(car < 400 || car > 611) return SendClientMessage(playerid, red, "ERROR: Invalid Vehicle Model");
if(isnull(tmp2)) colour1 = random(126); else colour1 = strval(tmp2);
if(!strlen(tmp3)) colour2 = random(126); else colour2 = strval(tmp3);
if(PlayerInfo[playerid][pCar] != -1 && !IsPlayerAdmin(playerid) ) CarDeleter(PlayerInfo[playerid][pCar]);
new LVehicleID,Float:X,Float:Y,Float:Z, Float:Angle,int1; GetPlayerPos(playerid, X,Y,Z); GetPlayerFacingAngle(playerid,Angle); int1 = GetPlayerInterior(playerid);
LVehicleID = CreateVehicle(car, X+3,Y,Z, Angle, colour1, colour2, -1); LinkVehicleToInterior(LVehicleID,int1); PutPlayerInVehicle(playerid, LVehicleID, 0);
PlayerInfo[playerid][pCar] = LVehicleID;
CMDMessageToAdmins(playerid,"CAR");
format(string, sizeof(string), "%s spawned a \"%s\" (Model:%d) colour (%d, %d), at %0.2f, %0.2f, %0.2f", pName(playerid), VehicleNames[car-400], car, colour1, colour2, X, Y, Z);
SaveToFile("CarSpawns",string);
format(string, sizeof(string), "You have spawned a \"%s\" (Model:%d) colour (%d, %d)", VehicleNames[car-400], car, colour1, colour2);
return SendClientMessage(playerid,lightblue, string);
} else return SendClientMessage(playerid,red,"ERROR: You need to be level 3 to use this command");
}
Re: /car [id] problem -
Nicker - 14.03.2015
if(PlayerInfo[playerid][pCar] != -1 && !IsPlayerAdmin(playerid) ) CarDeleter(PlayerInfo[playerid][pCar]);
Delete this line.
Re: /car [id] problem -
Evocator - 14.03.2015
Because of this;
Код:
if(PlayerInfo[playerid][pCar] != -1 && !IsPlayerAdmin(playerid) ) CarDeleter(PlayerInfo[playerid][pCar]);
TL;DR: Set a variable to the vehicle's id, and under OnVehicleSpawn destroy it, then reset the variable.
Actually thats good for controlling normal players and how they spawn vehicles. For someone your trust (aka admins) it should be a little different, let me explain;
IMO admins should be able to spawn as many vehicles as they wish, but theres a problem. What to do with the spawned vehicles? CreateVehicle syncs the vehicle data so that everytime the vehicle is destroyed, it respawns where it was created. And thus having an unlimited amount of vehicles on your server. To solve such problem, you can specify a var to such vehicle that its spawned and not a static one, and then once its destroyed you can check if that bool/var is set to true and destroy the vehicle.
Re: /car [id] problem -
Abagail - 14.03.2015
pawn Код:
if(PlayerInfo[playerid][pCar] != -1 && !IsPlayerAdmin(playerid) ) CarDeleter(PlayerInfo[playerid][pCar]);
The ironic thing is you explicitly mention "how to fix that"? Well why would you fix something you caused? That's pretty illogical, I am guessing you just took this from a random script.
OT: Delete the line or login as RCON.
Respuesta: /car [id] problem -
alexus - 14.03.2015
I am agree... that's not a script problem. It's a "copy 'n paste" one... First at all you have to know what do you want to do and study the code you paste in your script.
Re: /car [id] problem -
Fantje - 14.03.2015
Why so mean guys? My english is not that good so I said "I have a command". Yes this is another gamemode. Not mine. I removed it and it is not working...
Re: /car [id] problem -
Abagail - 14.03.2015
That's the only thing I can see removing a vehicle, perhaps there's something destroying elsewhere(or you removed the wrong line)?
Re: /car [id] problem -
Fantje - 14.03.2015
Problem is solved when login as rcon

Thanks