Problem with playerid
#1

I'm trying to make a function that will heal a players vehicle while player is in range of point.

My problem is that it only works for id 0, unless I put it under OnPlayerUpdate which i don't wanna do.

Код:
forward repair(playerid);

public OnGameModeInit()
{
    SetTimer("repair", 2000, true);
}

public repair(playerid)
{
	new Float:x, Float:y, Float:z;
	new vehicleid = GetPlayerVehicleID(playerid);
   	GetPlayerPos(playerid, x, y, z);
   	if(IsPlayerInVehicle(playerid, vehicleid))
        {
	    if(IsPlayerInRangeOfPoint(playerid, 650.0, -1171.4510, -226.3357, 14.1484))
	    {
		SetVehicleHealth(vehicleid, 1000.0);
	    }
	    if(IsPlayerInRangeOfPoint(playerid, 150.0, 1977.5227, -2352.5647, 13.1115))
	    {
		SetVehicleHealth(vehicleid, 1000.0);
	    }
	    if(IsPlayerInRangeOfPoint(playerid, 150.0, 1757.5624, -2536.8030, 13.1132))
	    {
		SetVehicleHealth(vehicleid, 1000.0);
	    }
	    if(IsPlayerInRangeOfPoint(playerid, 150.0, 1972.2734, -2527.6707, 13.1140))
	    {
	        SetVehicleHealth(vehicleid, 1000.0);
	    }
	    if(IsPlayerInRangeOfPoint(playerid, 150.0, 1490.7642, -2510.8005, 13.1258))
	    {
		SetVehicleHealth(vehicleid, 1000.0);
	    }
	    if(IsPlayerInRangeOfPoint(playerid, 100.0, 1724.5593, -2275.1589, 61.8035))
	    {
		SetVehicleHealth(vehicleid, 1000.0);
            }
 	}
	return 1;
}
Can anyone help me out?
Thanks
Reply
#2

use a for loop in the repair function
Reply
#3

pawn Код:
public repair(playerid)
{
    new Float:x, Float:y, Float:z;
    new vehicleid = GetPlayerVehicleID(playerid);
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS;i++)
    {
        if(IsPlayerInVehicle(i, vehicleid))
        {
            if(IsPlayerInRangeOfPoint(i, 650.0, -1171.4510, -226.3357, 14.1484))
            {
                SetVehicleHealth(vehicleid, 1000.0);
            }
            if(IsPlayerInRangeOfPoint(i, 150.0, 1977.5227, -2352.5647, 13.1115))
            {
                SetVehicleHealth(vehicleid, 1000.0);
            }
            if(IsPlayerInRangeOfPoint(i, 150.0, 1757.5624, -2536.8030, 13.1132))
            {
                SetVehicleHealth(vehicleid, 1000.0);
            }
            if(IsPlayerInRangeOfPoint(i, 150.0, 1972.2734, -2527.6707, 13.1140))
            {
                SetVehicleHealth(vehicleid, 1000.0);
            }
            if(IsPlayerInRangeOfPoint(i, 150.0, 1490.7642, -2510.8005, 13.1258))
            {
                SetVehicleHealth(vehicleid, 1000.0);
            }
            if(IsPlayerInRangeOfPoint(i, 100.0, 1724.5593, -2275.1589, 61.8035))
            {
                SetVehicleHealth(vehicleid, 1000.0);
            }
        }
    }
    return 1;
}
here you go
Reply
#4

Thanks for helping but unfortunately it is still only working for id 0
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)