Vehicle damage check not working
#1

I have this vehicle damage check and is a player not in a vehicle check and it only seems to work for one playerid at a time. As in, other players' cars blow up and they don't get a client message. It was originally under a foreach loop and wasn't working either.

pawn Код:
public DerbySys(playerid) //
{
    if (IsPlayerInRangeOfPoint(playerid, 500, -1364,1004.5,1220)) //map coords...
    {
        if (!IsPlayerInAnyVehicle(playerid))
        {
            GetDerbyCar(playerid);
            return 1;
        }
        if (IsPlayerInVehicle(playerid,RandDerbyCar[playerid]))
        {
            new Float:Vhealth;
            GetVehicleHealth(RandDerbyCar[playerid],Vhealth);
            if (Vhealth <= 250)
            {
                DestroyVehicle(RandDerbyCar[playerid]);
                SendClientMessage(playerid,0xFFFFFFFF,"Vehicle was destroyed. New vehicle created.");
                return 1;
            }
        }
    }
    return 1;
}
Reply
#2

They won't get a new vehicle because you don't give it to them.

pawn Код:
if (Vhealth <= 250)
{
    DestroyVehicle(RandDerbyCar[playerid]);
    SendClientMessage(playerid,0xFFFFFFFF,"Vehicle was destroyed. New vehicle created.");
    GetDerbyCar(playerid);
    return 1;
}
Reply
#3

That's not the issue. They should have their vehicle destroyed, and a message should be sent. It only works for 1 player, the others have no effect.
Reply
#4

How u are using DerbySys? As a timer under OnGamemodeInit?
Reply
#5

Quote:
Originally Posted by Hanuman
Посмотреть сообщение
How u are using DerbySys? As a timer under OnGamemodeInit?
Yes, as a timer. Is that the issue?
Reply
#6

The issue is probably that you used SetTimer and in the callback you used playerid as parameter (SetTimerEx has parameters only, SetTimer not).

Show us how you set the timer, just to be sure.
Reply
#7

pawn Код:
SetTimer("DerbySys",1000,1);
If that's the case should it be:
pawn Код:
SetTimerEx("DerbySys",1000,true,"playerid");
Reply
#8

You're setting the timer for one person thats why. Change to a global timer(Place it under OnGameModeInit)
EDIT:
pawn Код:
SetTimer("DerbySys",1000, 1);
EDIT2:
I read that wrong. No don't use the second one, the first one should work.
Reply
#9

If you keep this in OnGameModeInit/OnFilterScriptInit:
pawn Код:
SetTimer("DerbySys",1000,1);
then change to:
pawn Код:
forward DerbySys();
public DerbySys()
{
    for (new playerid; playerid != MAX_PLAYERS; ++playerid)
    {
        if (!IsPlayerConnected(playerid) || !IsPlayerInRangeOfPoint(playerid, 500, -1364,1004.5,1220)) continue;
        if (!IsPlayerInAnyVehicle(playerid))
        {
            GetDerbyCar(playerid);
            continue;
        }
        if (IsPlayerInVehicle(playerid,RandDerbyCar[playerid]))
        {
            new Float:Vhealth;
            GetVehicleHealth(RandDerbyCar[playerid],Vhealth);
            if (Vhealth <= 250)
            {
                DestroyVehicle(RandDerbyCar[playerid]);
                SendClientMessage(playerid,0xFFFFFFFF,"Vehicle was destroyed. New vehicle created.");
            }
        }
    }
}
Else you'd have to set the timer when a player joins the derby:
pawn Код:
SetTimerEx("DerbySys", 1000, true, "i", playerid);
and use it as you have it but keep in mind to store the timer ID in an array and when a player leaves derby to destroy the timer.
Reply
#10

I implemented your code into the script. I won't know if it works until one of the Beta Testers is up, or Ranger is up. Thanks for the help and the rewrite. I left you credit in the script.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)