/car [id] problem
#1

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], Indextmp strtok(params,Index), tmp2 strtok(params,Index); tmp3 strtok(params,Index);
        if(
isnull(tmp)) return SendClientMessage(playeridred"USAGE: /car [Modelid/Name] [colour1] [colour2]");
        new 
carcolour1colour2string[128];
           if(!
IsNumeric(tmp)) car GetVehicleModelIDFromName(tmp); else car strval(tmp);
        if(
car 400 || car 611) return  SendClientMessage(playeridred"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] != -&& !IsPlayerAdmin(playerid) ) CarDeleter(PlayerInfo[playerid][pCar]);
        new 
LVehicleID,Float:X,Float:Y,Float:ZFloat:Angle,int1;    GetPlayerPos(playeridX,Y,Z);    GetPlayerFacingAngle(playerid,Angle);   int1 GetPlayerInterior(playerid);
        
LVehicleID CreateVehicle(carX+3,Y,ZAnglecolour1colour2, -1); LinkVehicleToInterior(LVehicleID,int1); PutPlayerInVehicle(playeridLVehicleID0);
        
PlayerInfo[playerid][pCar] = LVehicleID;
        
CMDMessageToAdmins(playerid,"CAR");
        
format(stringsizeof(string), "%s spawned a \"%s\" (Model:%d) colour (%d, %d), at %0.2f, %0.2f, %0.2f"pName(playerid), VehicleNames[car-400], carcolour1colour2XYZ);
        
SaveToFile("CarSpawns",string);
        
format(stringsizeof(string), "You have spawned a \"%s\" (Model:%d) colour (%d, %d)"VehicleNames[car-400], carcolour1colour2);
        return 
SendClientMessage(playerid,lightbluestring);
    } else return 
SendClientMessage(playerid,red,"ERROR: You need to be level 3 to use this command");

Reply
#2

if(PlayerInfo[playerid][pCar] != -1 && !IsPlayerAdmin(playerid) ) CarDeleter(PlayerInfo[playerid][pCar]);

Delete this line.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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...
Reply
#7

That's the only thing I can see removing a vehicle, perhaps there's something destroying elsewhere(or you removed the wrong line)?
Reply
#8

Problem is solved when login as rcon Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)