removing the last spawned vehicle after spawning the new one
#1

hey guys ...
could some body tell me how can i remove the last spawned vehicle by player, after he/she spawns another one?
for example, a player spawns an infernus , then he/she decides to spawn an NRG , therefore, the infernus will get removed automatically...
Reply
#2

ye for that u will be needing a variable / a array:
a example ::-
<in command or place where player spawn vehicle>
pawn Код:
if( pVehicleSpawned[playerid] != -1 ) // this variable need to be set to -1 at player connect or at any other place required
{
    for( new i; i < MAX_PLAYERS; i++ )
    {
          if( IsPlayerInVehicle( i,  pVehicleSpawned[playerid] ) DestroyVehicle( pVehicleSpawned[playerid] );// will delete vehicle id the playerid had spawned earlier if it is not occupied by anyone
    }
}
pVehicleSpawned[playerid] = CreateVehicle(...); // create new vehicle and store vehicleid as seen by server in the variable..for playerid
//end
i made a fs which come with some similar example:
see its part where i createvehicle: http://************/79ltguu
Reply
#3

i did this but it didnt work i added these lines on OnPlayerModelSelection (im using mSelection include) :
Код:
	if(listid == vehlist)
	{
		if(response)
		{
			if( pVehicleSpawned[playerid] != -1 )
			{
			    for( new i; i < MAX_PLAYERS; i++ )
			    {
			          if( IsPlayerInVehicle( i,  pVehicleSpawned[playerid] ) DestroyVehicle( pVehicleSpawned[playerid] );
			    }
			}
			pVehicleSpawned[playerid] = CreateVehicle(...);
			new Float:pos[3]; GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
     		CreateVehicle(modelid, pos[0] + 2.5, pos[1], pos[2] + 2.5, 0.0, random(128), random(128), -1);
		}
		else
		{
		    return 0;
		}
and it gave me these errors:
Код:
E:\pawn project\gamemodes\zzz.pwn(565) : error 017: undefined symbol "pVehicleSpawned"
E:\pawn project\gamemodes\zzz.pwn(565) : warning 215: expression has no effect
E:\pawn project\gamemodes\zzz.pwn(565) : error 001: expected token: ";", but found "]"
E:\pawn project\gamemodes\zzz.pwn(565) : error 029: invalid expression, assumed zero
E:\pawn project\gamemodes\zzz.pwn(565) : fatal error 107: too many error messages on one line
Reply
#4

gactually u didnt understood what i mean tthere e.e

pawn Код:
//-- top of script add under includes
new pVehicleSpawned[MAX_PLAYERS];
//------
//in onplayerconnect add this:
pVehicleSpawned[playerid] = -1;
//-------
    if(listid == vehlist)
    {
        if(response)
        {
            if( pVehicleSpawned[playerid] != -1 )
            {
                for( new i; i < MAX_PLAYERS; i++ )
                {
                      if( IsPlayerInVehicle( i,  pVehicleSpawned[playerid] ) DestroyVehicle( pVehicleSpawned[playerid] );
                }
            }
            new Float:pos[3]; GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                    pVehicleSpawned[playerid] = CreateVehicle(modelid, pos[0] + 2.5, pos[1], pos[2] + 2.5, 0.0, random(128), random(128), -1);
        }
        else
        {
            return 0;
        }
Reply
#5

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
gactually u didnt understood what i mean tthere e.e

pawn Код:
//-- top of script add under includes
new pVehicleSpawned[MAX_PLAYERS];
//------
//in onplayerconnect add this:
pVehicleSpawned[playerid] = -1;
//-------
    if(listid == vehlist)
    {
        if(response)
        {
            if( pVehicleSpawned[playerid] != -1 )
            {
                for( new i; i < MAX_PLAYERS; i++ )
                {
                      if( IsPlayerInVehicle( i,  pVehicleSpawned[playerid] ) DestroyVehicle( pVehicleSpawned[playerid] );
                }
            }
            new Float:pos[3]; GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                    pVehicleSpawned[playerid] = CreateVehicle(modelid, pos[0] + 2.5, pos[1], pos[2] + 2.5, 0.0, random(128), random(128), -1);
        }
        else
        {
            return 0;
        }
oh im a lil bit noob in scripting :P
i did it bro, it compiles successfully but when i test it in-game , it doesnt work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)