NRG/INF command
#1

Hi, someone give me this code:

PHP код:
new
    
infernus[MAX_PLAYERS],
    
nrg[MAX_PLAYERS];
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext,"/inf",true))
    {
        if(
infernus[playerid] == 0)
        {
            static
                
Float:pos[3];
                
            
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
            
infernus[playerid] = CreateVehicle(411pos[0], pos[1], pos[2], 0, -1, -110);
            
infernus[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable.
            
            
PutPlayerInVehicle(playeridinfernus[playerid]-10);
            
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(playeridpos[0], pos[1], pos[2]);
            
nrg[playerid] = CreateVehicle(522pos[0], pos[1], pos[2], 0, -1, -110);
            
nrg[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable.
            
            
PutPlayerInVehicle(playeridnrg[playerid]-10);
            
SendClientMessage(playerid0xFF641AFF"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
Reply
#2

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?
Reply
#3

Using Zcmd u can do it easily and remove those codes in onplayercommandtext

So add this @ top
PHP код:
#include<zcmd> 
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(411pos[0], pos[1], pos[2], 0, -1, -110); 
            
infernus[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable. 
             
            
PutPlayerInVehicle(playeridinfernus[playerid]-10); 
            
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(playeridpos[0], pos[1], pos[2]); 
            
nrg[playerid] = CreateVehicle(522pos[0], pos[1], pos[2], 0, -1, -110); 
            
nrg[playerid]++; // If the vehicle is ID "0", he can't destroy him, so I fix this bug with incrementation of the variable. 
             
            
PutPlayerInVehicle(playeridnrg[playerid]-10); 
            
SendClientMessage(playerid0xFF641AFF"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
    } 
Reply
#4

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

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(playeridCOLOR_RED"ERROR: You already have a car!");
    else
    {
        new 
Float:xFloat:yFloat:zFloat:angle;
        
GetPlayerPos(playeridxyz);
         
GetPlayerFacingAngle(playeridangle);

        new 
vehicleid=CreateVehicle(modelxyzangle, -1, -1, -1);
        
PutPlayerInVehicle(playeridvehicleid0);
        
SetVehicleVirtualWorld(vehicleidGetPlayerVirtualWorld(playerid));
        
LinkVehicleToInterior(vehicleidGetPlayerInterior(playerid));
        
ChangeVehicleColor(vehicleid,0,3);
    }
    return 
1;

If That helped you +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)