Help- :(
#1

Hello, I am developing a system, and I'm a simple doubt, using the code below ..

PHP код:
for (new 0MAX_PLAYERSi++) 

    if (
GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid)) 
    { 
        
GetPlayerHealth(ihealth), SetPlayerHealth(ihealth 7); 
        
//// 
        
GetPlayerHealth(playeridhealth), SetPlayerHealth(playeridhealth 7); 
    } 

the intention is to take the lives of all who are in the same vehicle as the "playerid" (driver), the player (passenger) will receive some kind of damage? if not, what is the solution?
Reply
#2

CMD:NAME OF THE COMMAND(playerid,params[]) {
new string[120], healt, passenger;
if (IsPlayerInAnyVehicle(playerid)) {
GetPlayerHealth(playerid, health);
return SendClientMessage(playerid,blue,string);
} else return SendClientMessage(playerid,red,"ERROR: You are not in a vehicle");
return 1;
}
Reply
#3

Your code will take 7 hp from anyone who's in the same vehicle of playerid.
And will take 14 hp from playerid.

You should use IsPlayerInVehicle. So players that aren't in vehicles won't be affected if you check someone who is not in a vehicle.

Код:
for (new i = 0; i < MAX_PLAYERS; i++)  
{  
    if(IsPlayerInVehicle(i, GetPlayerVehicleID(playerid)))
    {
        // playerid will be in the vehicle aswell:
       	GetPlayerHealth(i, health);
        SetPlayerHealth(i, health - 7);
    }  
}
Reply
#4

Quote:
Originally Posted by Larceny
Посмотреть сообщение
Your code will take 7 hp from anyone who's in the same vehicle of playerid.
And will take 14 hp from playerid.

You should use IsPlayerInVehicle. So players that aren't in vehicles won't be affected if you check someone who is not in a vehicle.

Код:
for (new i = 0; i < MAX_PLAYERS; i++)  
{  
    if(IsPlayerInVehicle(i, GetPlayerVehicleID(playerid)))
    {
        // playerid will be in the vehicle aswell:
       	GetPlayerHealth(i, health);
        SetPlayerHealth(i, health - 7);
    }  
}
correct?

PHP код:
                if (IsPlayerInVehicle(ivehicleid))
                {
                    if(
CintoPlayerid[i] == 1) return 1;
                    
GetPlayerHealth(ihealth);
                    
SetPlayerHealth(ihealth 7);
                }
                return 
1
Reply
#5

Use
Код:
if(CintoPlayerid[i] == 1) continue;
Otherwise it will stop the loop before it checks all the players if CintoPlayerid[i] is true.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)