SA-MP Forums Archive
ELEGY HELP 3! - 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: ELEGY HELP 3! (/showthread.php?tid=370508)



ELEGY HELP 3! - necrobg3 - 20.08.2012

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.


Re: ELEGY HELP 3! - AliveBG - 20.08.2012

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.


Re: ELEGY HELP 3! - milanosie - 20.08.2012

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]);
    }



Re: ELEGY HELP 3! - necrobg3 - 20.08.2012

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


Re: ELEGY HELP 3! - necrobg3 - 20.08.2012

Hello? Please i really need a help.


Re: ELEGY HELP 3! - AliveBG - 21.08.2012

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;




Re: ELEGY HELP 3! - necrobg3 - 21.08.2012

Thanks. +REP for you.