Problem with, Health Drain if Player is not near point + message
#1

I am having a slight issue with a timer and some stuff :P

I am trying to create a zone by using
pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 700.0, -118.3844, 1151.4380, 19.5938))
That gives me a quick and easy circle around Fort Carson, I made it as a positive check instead of a negative (!) just in case I wanted to add another zone by using an "else if" with other coordinates.

So what I want is that when a player is not inside one of these zones, their health will slowly drain (its quite quick for debugging)
Here is the full code for my function:

pawn Code:
public OnGameModeInit()
{
    SetTimer("isPlayerInArea", 1000, true);
}
pawn Code:
public isPlayerInArea(playerid) // has "forward isPlayerInArea(playerid);"
{
    if(IsPlayerInRangeOfPoint(playerid, 700.0, -118.3844, 1151.4380, 19.5938)) // center of Fort Carson
    {
        return 1; // does nothing if player is in area
    }
    else
    {
        new Float:dhealth;
        GetPlayerHealth(playerid, dhealth);
        SetPlayerHealth(playerid, dhealth - 1.0);
    }
    return 1;
}
Now this works perfectly fine for 1 player, but with more players it only drains for the first player.
I tried to do some other things, but that made everyone loose health even if they were not outside.

I also want it to display a message once when the player enters and leaves the area, they way I tried ended up spaming every second, so I though I probably needed some type of trigger and check to see if the message plays, and if it has, don't play it again, unless the player enters again.
I hope you understand where I want to go with this, and if you can help it would be very appreciated!
Reply
#2

You need to create a loop in the isPlayerInArea function, and remove the playerid parameter.
Reply
#3

pawn Code:
public isPlayerInArea() // change "forward isPlayerInArea(playerid);", to "forward isPlayerInArea();"
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 700.0, -118.3844, 1151.4380, 19.5938)) // center of Fort Carson
        {
            return 1; // does nothing if player is in area
        }
        else
        {
            new Float:dhealth;
            GetPlayerHealth(i, dhealth);
            SetPlayerHealth(i, dhealth - 1.0);
        }
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by iGetty
View Post
pawn Code:
public isPlayerInArea() // change "forward isPlayerInArea(playerid);", to "forward isPlayerInArea();"
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 700.0, -118.3844, 1151.4380, 19.5938)) // center of Fort Carson
        {
            return 1; // does nothing if player is in area
        }
        else
        {
            new Float:dhealth;
            GetPlayerHealth(i, dhealth);
            SetPlayerHealth(i, dhealth - 1.0);
        }
    }
    return 1;
}
I did something like this, it ended up draining everyones health, if one person was outside, maybe I did it wrong, will try this out.

EDIT:
Yeah this did not work, it was close though, but for some reason the first player dies a few times on connect, and the other players only loose health if the first player is also outside, if the first player enters, no one looses health.

I have tried a few more methods but I just can't get it to work properly.
Does anyone know how it can be done?
Reply
#5

I am still having issues with this, does anyone have any suggestions?

(Yeah this is a bump, but it should be fine now, been a few days :P )

It would be really nice to get this working.


Thanks!
Reply
#6

I don't get it, if he is NEAR the point, he should loose HP? or the other way around?
Reply
#7

When the player is not near the point.

The point is at Fort Carson, that town is a safe zone, everywhere outside of the area is dangerous and your health will drain.
Reply
#8

Try this:
pawn Code:
public OnGameModeInit()
{
    SetTimer("IsPlayerInArea", 1000, true);
    return 1;
}
pawn Code:
forward IsPlayerInArea();
public IsPlayerInArea()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerInRangeOfPoint(i, 700.0, -118.3844, 1151.4380, 19.5938))
        {
            new Float:pHP;
            GetPlayerHealth(i, pHP);
            SetPlayerHealth(i, pHP-1.0);
        }
    }
        return 1;
}
Reply
#9

Quote:
Originally Posted by Sandiel
View Post
Try this:
pawn Code:
public OnGameModeInit()
{
    SetTimer("IsPlayerInArea", 1000, true);
    return 1;
}
pawn Code:
forward IsPlayerInArea();
public IsPlayerInArea()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerInRangeOfPoint(i, 700.0, -118.3844, 1151.4380, 19.5938))
        {
            new Float:pHP;
            GetPlayerHealth(i, pHP);
            SetPlayerHealth(i, pHP-1.0);
        }
    }
        return 1;
}
This does not seem to do anything :/
Reply
#10

Quote:
Originally Posted by LeonRedfield
View Post
This does not seem to do anything :/
Hmmm....It should work, are you sure that your server loads fine, no errors, or anything?
Also, if you are getting errors while compiling, post the lines here.
Reply
#11

Quote:
Originally Posted by Sandiel
View Post
Hmmm....It should work, are you sure that your server loads fine, no errors, or anything?
Also, if you are getting errors while compiling, post the lines here.
Yeah it compiles fine, no errors.
The server loads fine, me and others able to connect, and my /version command is updated so the .amx file has been properly uploaded to the new test. And its doing nothing at all for any players.
Reply
#12

Well i guess you could try it with player timers (SetTimerEx) to pass the playerid param,
pawn Code:
SetTimerEx("IsPlayerInArea", 1000, true, "i", playerid);
Then use your origional code.

Only downfall with that is each player would have a timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)