SA-MP Forums Archive
Help- :( - 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: Help- :( (/showthread.php?tid=579769)



Help- :( - DeadNudock - 29.06.2015

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?


Re: Help- :( - Rodri99 - 29.06.2015

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


Re: Help- :( - Larceny - 29.06.2015

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



Re: Help- :( - DeadNudock - 29.06.2015

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



Re: Help- :( - Larceny - 29.06.2015

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