NRG/INF command -
MonSterLikeHD - 02.04.2016
Hi, someone give me this code:
PHP код:
new
infernus[MAX_PLAYERS],
nrg[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext,"/inf",true))
{
if(infernus[playerid] == 0)
{
static
Float:pos[3];
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
infernus[playerid] = CreateVehicle(411, pos[0], pos[1], pos[2], 0, -1, -1, 10);
infernus[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable.
PutPlayerInVehicle(playerid, infernus[playerid]-1, 0);
SendClientMessage(playerid,0xFF641AFF,"SERVER: You have Spawned An Infernus.");
return 1;
}
else
{
DestroyVehicle(infernus[playerid]-1);
infernus[playerid] = 0;
}
return 1;
}
if(!strcmp(cmdtext, "/nrg", true))
{
if(nrg[playerid] == 0)
{
static
Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
nrg[playerid] = CreateVehicle(522, pos[0], pos[1], pos[2], 0, -1, -1, 10);
nrg[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable.
PutPlayerInVehicle(playerid, nrg[playerid]-1, 0);
SendClientMessage(playerid, 0xFF641AFF, "SERVER: You have Spawned A NRG-500.");
return 1;
}
else if(nrg[playerid] > 0)
{
DestroyVehicle(nrg[playerid]-1);
nrg[playerid] = 0;
}
return 1;
}
return 0;
}
My problem is, i need to type the command 2 times to destroy the vehicle, but i want to use only one time
Re: NRG/INF command -
SamJust - 02.04.2016
When u enter the command first time it spawns a vehicle, and second time command'll destroy it. So what is the problem? U still have to type it 2 times even after u spawn a vehicle?
Re: NRG/INF command -
SyS - 02.04.2016
Using Zcmd u can do it easily and remove those codes in onplayercommandtext
So add this @ top
and this
PHP код:
new
infernus[MAX_PLAYERS],
nrg[MAX_PLAYERS];
add @ bottom of your script
PHP код:
CMD:inf(playerid)
{
if(infernus[playerid] == 0)
{
static
Float:pos[3];
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
infernus[playerid] = CreateVehicle(411, pos[0], pos[1], pos[2], 0, -1, -1, 10);
infernus[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable.
PutPlayerInVehicle(playerid, infernus[playerid]-1, 0);
SendClientMessage(playerid,0xFF641AFF,"SERVER: You have Spawned An Infernus.");
return 1;
}
else
{
DestroyVehicle(infernus[playerid]-1);
infernus[playerid] = 0;
return cmd_inf(playerid);
}
return 1;
}
and this
PHP код:
CMD:nrg(playerid)
{
if(nrg[playerid] == 0)
{
static
Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
nrg[playerid] = CreateVehicle(522, pos[0], pos[1], pos[2], 0, -1, -1, 10);
nrg[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable.
PutPlayerInVehicle(playerid, nrg[playerid]-1, 0);
SendClientMessage(playerid, 0xFF641AFF, "SERVER: You have Spawned A NRG-500.");
return 1;
}
else if(nrg[playerid] > 0)
{
DestroyVehicle(nrg[playerid]-1);
nrg[playerid] = 0;
return cmd_nrg(playerid);
}
return 1;
}
Re: NRG/INF command -
Vince - 02.04.2016
Vehicleids start at 1, not 0. So all this ++ and -- is just over complicating things. Besides, there is a definition called INVALID_VEHICLE_ID which exists for use in such scenarios.
Re: NRG/INF command -
Loinal - 02.04.2016
i use this
PHP код:
forward CarSpawner(playerid,model);
CMD:inf(playerid,params[])
{
if (!IsPlayerInAnyVehicle(playerid))
{
CarSpawner(playerid,411);
return SendClientMessage(playerid,0x1400FFFF,"Car Successfully Created!");
}
else return SendClientMessage(playerid,COLOR_RED,"Error: You already have a vehicle");
}
CMD:nrg(playerid,params[])
{
if (!IsPlayerInAnyVehicle(playerid))
{
CarSpawner(playerid,522);
return SendClientMessage(playerid,0x1400FFFF,"Car Successfully Created!");
}
else return SendClientMessage(playerid,COLOR_RED,"Error: You already have a vehicle");
}
public CarSpawner(playerid,model)
{
if(IsPlayerInAnyVehicle(playerid))
SendClientMessage(playerid, COLOR_RED, "ERROR: You already have a car!");
else
{
new Float:x, Float:y, Float:z, Float:angle;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
new vehicleid=CreateVehicle(model, x, y, z, angle, -1, -1, -1);
PutPlayerInVehicle(playerid, vehicleid, 0);
SetVehicleVirtualWorld(vehicleid, GetPlayerVirtualWorld(playerid));
LinkVehicleToInterior(vehicleid, GetPlayerInterior(playerid));
ChangeVehicleColor(vehicleid,0,3);
}
return 1;
}
If That helped you +rep