Car spawn help - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Car spawn help (
/showthread.php?tid=648034)
Car spawn help -
,TomY' - 14.01.2018
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;
}
Re: Car spawn help -
,TomY' - 14.01.2018
Any help?
Re: Car spawn help -
KayJ - 15.01.2018
PHP код:
if(!strcmp(cmdtext, "/car", true))
{
new Float:up[3], carid;
GetPlayerPos(playerid, up[0], up[1], up[2]);
carid = CreateVehicle(411, up[0]+2, up[1]+2, up[2], 0, -1, -1, 0);
PutPlayerInVehicle(playerid, carid, 0);
new currentveh;
currentveh = GetPlayerVehicleID(playerid);
DestroyVehicle(currentveh);
LinkVehicleToInterior(carid, GetPlayerInterior(playerid));
SetVehicleVirtualWorld(carid, GetPlayerVirtualWorld(playerid));
SendClientMessage(playerid, 0x20C92EFF, "* You spawned a new Infernus car, you can also use the /carmenu to spawn other vehicle types.");
return 1;
}
Try it(Untested)
Re: Car spawn help -
andrejc999 - 15.01.2018
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...