remove all unoccupied cars spawned with /v command
#1

Hi is anyone know how to script this? I have a vehicle command which spawn a vehicle but I want to add if a player spawned a vehicle and he leave it empty after 3 minutes then delete the vehicle. You know just to prevent vehicle flood in server.

Maybe this will help you..

Код:
CMD:v(playerid, params[])
{
        if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
        {
            #if !defined IGNORE_VEHICLE_ACTIVATION
            ShowPlayerDefaultDialog( playerid );
            return 1;
            #endif
        }
        if ( GetPlayerState( playerid ) != PLAYER_STATE_PASSENGER ) ShowPlayerDefaultDialog( playerid );
        return 1;
}
Код:
CreatePlayerVehicle( playerid, modelid )
{
	new
	    vehicle,
		Float:x,
		Float:y,
		Float:z,
		Float:angle;

	if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
	{
	    vehicle = GetPlayerVehicleID( playerid );
	    GetVehiclePos( vehicle, x, y, z );
	    GetVehicleZAngle( vehicle, angle );
	    DestroyVehicle( vehicle );
	}
	else
	{
		GetPlayerPos( playerid, x, y, z );
		GetPlayerFacingAngle( playerid, angle );
	}
	vehicle = CreateVehicle( modelid, x, y, ( z + 1 ), angle, -1, -1, DEFAULT_RESPAWN_TIME );
	LinkVehicleToInterior( vehicle, GetPlayerInterior( playerid ) );
	#if !defined IGNORE_VIRTUAL_WORLDS
		SetVehicleVirtualWorld( vehicle, GetPlayerVirtualWorld( playerid ) );
	#endif
	#if !defined IGNORE_WARP_INTO_VEHICLE
		PutPlayerInVehicle( playerid, vehicle, 0 );
	#endif
	#if !defined IGNORE_VEHICLE_DELETION
		gDialogCreated[ vehicle ] = true;
	#endif
	return 1;
}
Reply
#2

You can use player variables, and some timers for this...

I think you're looking for some example, so:
pawn Код:
new timer_id[MAX_PLAYERS char];

j_Destroy(playerid);
public j_Destroy(playerid)
{
    DestroyVehicle(GetPVarInt(playerid, "carId"));
    SetPVarInt(playerid, "carId", -1);
    return 1;
}

//This command spawns a NRG-500 on player position
//and put the player on vehicle.
CMD:v(playerid, params[])
{
    new Float:x, Float:y, Float:z, Float:a;
   
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
   
    new veh = CreateVehicle(522, x, y, z, a, -1, -1, cellmax);
    PutPlayerInVehicle(playerid, veh, 0);
   
    //Here you sets the carId to a player variable
    //to use in future verifications.
    SetPVarInt(playerid, "carId", veh);
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    //Here you verified if the player entered on his vehicle
    //until the time of 3 minutes.
    if (ispassenger == 0 && GetPVarInt(playerid, "carId") == vehicleid)
    {
        //destroying the timer before delete the vehicle(3 minutes).
        KillTimer(timer_id{playerid});
    }

    //codes
    //---------
    //return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
    //Here you verified if the vehicle the player was get out is the same
    //vehicle he has spawned, so, starts the timer.
    if (GetPVarInt(playerid, "carId") == vehicleid)
    {
        timer_id{playerid} = SetTimerEx("j_Destroy", 3000 * 60, false, "i", playerid);
    }
   
    //codes
    //---------
    //return 1;
}
Reply
#3

I think too many timer will run every player who spawned the vehicle and leave it empty. So it would be like, if I have 200 players and they spawned a vehicle and then they exit the vehicle so 200 timers will run?

Hmm. For now maybe its okay to use a global timer which check every 3 minutes if there is an empty vehicle spawned by /v command and delete this all.

Can someone help me with this?

Thanks alot!
Reply
#4

EDIT
Reply
#5

Hi guys anyone know how to make this right?
Reply
#6

top
pawn Код:
new bool:vInfo[MAX_VEHICLES char];
in command
pawn Код:
if(vInfo[GetPlayerVehicleID( playerid )])
{
// destroy
vInfo[GetPlayerVehicleID( playerid )] = false;
}
vehicle = CreateVehicle( modelid, x, y, ( z + 1 ), angle, -1, -1, DEFAULT_RESPAWN_TIME );
vInfo[vehicle] = true;
OnVehicleSpawn

pawn Код:
if(vInfo[vehicleid])
{
// destroy
vInfo[vehicleid] = false;
}
or you can use this gDialogCreated[ vehicle ] = true; in the same way
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
top
pawn Код:
new bool:vInfo[MAX_VEHICLES char];
in command
pawn Код:
if(vInfo[GetPlayerVehicleID( playerid )])
{
// destroy
vInfo[GetPlayerVehicleID( playerid )] = false;
}
vehicle = CreateVehicle( modelid, x, y, ( z + 1 ), angle, -1, -1, DEFAULT_RESPAWN_TIME );
vInfo[vehicle] = true;
OnVehicleSpawn

pawn Код:
if(vInfo[vehicleid])
{
// destroy
vInfo[vehicleid] = false;
}
or you can use this gDialogCreated[ vehicle ] = true; in the same way
Thanks jeff for the reply. But may I ask something. Does this deletes the vehicle if its unoccupied for 3 minutes?
or it will simply replace/delete the old vehicle that the player spawned?
Reply
#8

After DEFAULT_RESPAWN_TIME yes, OnVehicleSpawn is called and
pawn Код:
if(vInfo[vehicleid])
{
// destroy vehicle
}
vInfo[vehicleid] = false;
oh i forgot replace [] to {} must be vInfo{vehicleid} not vInfo[vehicleid] in all cases
Reply
#9

Instead of using array for checking if the vehicle is valid or not, why don't you just use IsValidVehicle?
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Instead of using array for checking if the vehicle is valid or not, why don't you just use IsValidVehicle?
IsValidVehicle? uhm for what? xD read properly, anti car flood via /v command

Quote:
Originally Posted by gotwarzone
Посмотреть сообщение
I have a vehicle command which spawn a vehicle but I want to add if a player spawned a vehicle and he leave it empty after 3 minutes then delete the vehicle. You know just to prevent vehicle flood in server.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)