ELEGY HELP 3!
#1

Hey guys. I tired many times to construct that command but it don't work.
When i spawn the elegy everything is ok, i make the command for all players.
But when i exit the vehicle and type /elegy again, it gets spawned again.
I wanna make the command when anyone type /elegy again the other car gets destroyed and let spawn new car.
Here is the command.

pawn Код:
if (strcmp("/elegy", cmdtext, true, 10) == 0)
    {
    new Float: X, Float: Y, Float: Z, Float: A;
    new vehicleid[MAX_PLAYERS];
    if(IsPlayerInAnyVehicle(playerid))  return SendClientMessage(playerid, COLOR_RED, "ERROR: You are driving a vehicle.");
    if(vehicleid[playerid])
    {
        DestroyVehicle(vehicleid[playerid]);
    }
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, A);
    vehicleid[playerid] = CreateVehicle(562, X, Y, Z, A, 0, 0, 0);
    PutPlayerInVehicle(playerid, vehicleid[playerid], 0);
    return 1;
    }
+REP for the dude who help me.
Reply
#2

Try this:
PHP код:
if(strcmp(cmdtext"/elegy"true) == 0)
{
    new 
FloatXFloatYFloatZFloatA;
    new 
vehicleid[MAX_PLAYERS], vehspawned[MAX_PLAYERS];
    if(
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridCOLOR_RED"ERROR: You are driving a vehicle.");
    if(
vehspawned[playerid] == 1)
    {
        
DestroyVehicle(vehicleid[playerid]);
        
vehspawned[playerid] = 0;
    }
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridA);
    
vehicleid[playerid] = CreateVehicle(562XYZA000);
    
vehspawned[playerid] = 1;
    
PutPlayerInVehicle(playeridvehicleid[playerid], 0);
    return 
1;

Edit: I forgot this.
Reply
#3

new vehicleid[MAX_PLAYERS];

Should be a global variable, so OUTSIDE of the command and placed at the TOP of your script.

And it should be

pawn Код:
if(vehicleid[playerid] != 0)
    {
        DestroyVehicle(vehicleid[playerid]);
    }
Reply
#4

The both ways don't work. At the second way ( milanosie ) i get error: invalid function or declaration.
Reply
#5

Hello? Please i really need a help.
Reply
#6

Sorry, this will works
PHP код:
new vehcheid[MAX_PLAYERS], vehspawned[MAX_PLAYERS]; // as global variable
// OnPlayerConnect
vehspawned[playerid] = 0;
// OnPlayerCommandText
if(strcmp(cmdtext"/elegy"true) == 0)
{
    new 
FloatXFloatYFloatZFloatA;
    if(
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridCOLOR_RED"ERROR: You are driving a vehicle.");
    if(
vehspawned[playerid] == 1)
    {
        
DestroyVehicle(vehcheid[playerid]);
        
vehspawned[playerid] = 0;
    }
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridA);
    
vehcheid[playerid] = CreateVehicle(562XYZA000);
    
vehspawned[playerid] = 1;
    
PutPlayerInVehicle(playeridvehcheid[playerid], 0);
    return 
1;

Reply
#7

Thanks. +REP for you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)