respawned with occupied vehicle?
#1

I made some commands, the commands to respawn factions vehicle, but the problem is, It respawned the occupied faction vehicle too, so when players are driving, their vehicle dissapears when i do /respawnarmyveh.
Can someone fix it for me?
The /respawnarmyveh
Код:
CMD:respawnarmy(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 1)
	{
		SendClientMessageEx(playerid, COLOR_WHITE, "Dibutuhkan admin LVL 1+");
	}
	else
	{
		for(new x;x<sizeof(ARMYVehicles);x++)
		{
		    if(!IsVehicleOccupied(x))
		    {
	 	    	SetVehicleToRespawn(ARMYVehicles[x]);
			}
		}
		SendClientMessageToAll(COLOR_REALRED,"[Information] {FFFFFF}Kendaraan faction ARMY telah Direspawn.");
	}
	return 1;
}
Stock IsVehicleOccupied
Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
		{
            return 1;
		}
	}
    return 0;
}
Reply
#2

set the vehicles that are occupied to a variable like unwanted.

PHP код:
    new bool:unwanted[MAX_VEHICLES];
    foreach(
Playeri)
    {
    if(
IsPlayerInAnyVehicle(i))
        {
            
unwanted[GetPlayerVehicleID(i)] = true;
        }
    } 
and then verify if the car is occupied with
PHP код:
if(!unwanted[car]) 
Reply
#3

Try this:
PHP код:
CMD:respawnarmy(playerid)
{
    if(
PlayerInfo[playerid][pAdmin] < 1) return SendClientMessageEx(playeridCOLOR_WHITE"Dibutuhkan admin LVL 1+");
    for(new 
x;x<sizeof(ARMYVehicles);x++)
    {
        if(!
IsVehicleOccupied(ARMYVehicles[x])
             
SetVehicleToRespawn(ARMYVehicles[x]);
    }
    
SendClientMessageToAll(COLOR_REALRED,"[Information] {FFFFFF}Kendaraan faction ARMY telah Direspawn.");
    return 
1;

You were passing the iterator to the parameter of the IsVehicleOccupied function, whereas you needed to pass the vehicle ID stored in the ARMYVehicles array, simply change !IsVehicleOccupied(x) to !IsVehicleOccupied(ARMYVehicles[x]).
Reply
#4

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
You were passing the iterator to the parameter of the IsVehicleOccupied function, whereas you needed to pass the vehicle ID stored in the ARMYVehicles array, simply change !IsVehicleOccupied(x) to !IsVehicleOccupied(ARMYVehicles[x]).
otherwise it could work.

PHP код:
stock IsVehicleOccupied(vehicleid)
{
    new 
state 0;
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerInVehicle(ivehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            
state 1;
        }
    }
    return 
state;

use this and you can also remove GetPlayerState (to use this for passengers too)
you don't had a correct return value.
Reply
#5

Quote:
Originally Posted by Mugala
Посмотреть сообщение
otherwise it could work.

PHP код:
stock IsVehicleOccupied(vehicleid)
{
    new 
state 0;
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerInVehicle(ivehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            
state 1;
        }
    }
    return 
state;

use this and you can also remove GetPlayerState (to use this for passengers too)
you don't had a correct return value.
Код:
C:\Users\gratiotio\Desktop\MGP\gamemodes\a.pwn(67322) : error 001: expected token: "-identifier-", but found "state"
C:\Users\gratiotio\Desktop\MGP\gamemodes\a.pwn(67327) : error 001: expected token: "-identifier-", but found "="
C:\Users\gratiotio\Desktop\MGP\gamemodes\a.pwn(67327) : error 029: invalid expression, assumed zero
C:\Users\gratiotio\Desktop\MGP\gamemodes\a.pwn(67327) : warning 215: expression has no effect
C:\Users\gratiotio\Desktop\MGP\gamemodes\a.pwn(67330) : error 001: expected token: "-identifier-", but found ";"
Reply
#6

Quote:
Originally Posted by Mugala
Посмотреть сообщение
otherwise it could work.

PHP код:
stock IsVehicleOccupied(vehicleid)
{
    new 
state 0;
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerInVehicle(ivehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            
state 1;
        }
    }
    return 
state;

use this and you can also remove GetPlayerState (to use this for passengers too)
you don't had a correct return value.
why do you use
PHP код:
stock 
,and not simply
PHP код:
IsVehicleOccupied(vehicleid
Reply
#7

Quote:
Originally Posted by PepsiCola23
Посмотреть сообщение
why do you use
PHP код:
stock 
,and not simply
PHP код:
IsVehicleOccupied(vehicleid
And the difference is?
Reply
#8

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
And the difference is?
Stop the abuse of stock!
https://sampforum.blast.hk/showthread.php?tid=570635
Reply
#9

Thats the most meaningless thing i ever heard, this affects the performance in no way. Show me a benchmark to 'stop the abuse of stock' otherwise you're following posts blindly.
Reply
#10

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Thats the most meaningless thing i ever heard, this affects the performance in no way. Show me a benchmark to 'stop the abuse of stock' otherwise you're following posts blindly.
It indeed doesn't matter stock or not it will work either way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)