Car spawn help
#1

Hi all. Trying to create command, that spawns cars. And now I have a question. How to do, that one player can spawn a lot of cars? Now if i spawn first car ant type /scar second time, first car disappears. I want to spawn a lot of cars. Also I need that, if I have spawned 3 cars for example and first car destroys, other 2 stays.

Код:
new sCar[MAX_PLAYERS];
Код:
if(!strcmp(cmdtext, "/scar", false, 5))
{
    if(!strlen(cmdtext[5]) return SendClientMessage(playerid, red, "Usage: /scar [Model ID]");
    new veh = strval(cmdtext[5]);
    if(veh < 400 || veh > 611) return SendClientMessage(playerid, red, "ERROR: Invalid Vehicle Model");
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x,y,z); GetPlayerFacingAngle(playerid, a);
    sCar[playerid] = CreateVehicle(veh, x,y,z, a, -1, -1, -1);
    return 1;
}
Код:
public OnVehicleDeath(vehicleid)
{
    for(new x; x<MAX_PLAYERS; x++)
    {
        if(sCar[x] != 0) continue;
        if(sCar[x] == vehicleid) 
        {
            DestroyVehicle(vehicleid);
            break;
        }
    }
    return 1;
}
Reply
#2

Any help?
Reply
#3

PHP код:
if(!strcmp(cmdtext"/car"true)) 
        { 
        new 
Float:up[3], carid
          
GetPlayerPos(playeridup[0], up[1], up[2]); 
        
carid CreateVehicle(411up[0]+2up[1]+2up[2], 0, -1, -10); 
        
PutPlayerInVehicle(playeridcarid0); 
        new 
currentveh
          
currentveh GetPlayerVehicleID(playerid); 
          
DestroyVehicle(currentveh); 
        
LinkVehicleToInterior(caridGetPlayerInterior(playerid)); 
        
SetVehicleVirtualWorld(caridGetPlayerVirtualWorld(playerid)); 
        
SendClientMessage(playerid0x20C92EFF"* You spawned a new Infernus car, you can also use the /carmenu to spawn other vehicle types."); 
        return 
1
        } 
Try it(Untested)
Reply
#4

It's because you are always making a new car under the same id as the last one...

Try adding [100] to the scar variable.

new sCar[MAX_PLAYERS][100];

And then when making a new car make a loop to check for an available vehicleid

Like this:

for(new v=0;v<100;v++)
{
if (!IsValidVehicle(sCar[playerid][v]))
{
sCar[playerid][v] = CreateVehicle(...);
return 1;
}
}

This is only if you want to be able to make 100 cars...

You could set the variable to 3 and then when spawning a 4th one check if the first is a valid vehicle and destroy it and then use it's id for the new car for example...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)