SetPlayerHealth help
#1

Hello, I have on my OnPlayerUpdate code so that when you enter a certain area, you should drop a few health each time you stay there. So I put it to SetPlayerHealth(playerid, -5); and it killed me right away. But I want the player to drop 5 health everytime OnPlayerUpdate ticks, is that possible? if so :P how?
Reply
#2

Uhm, OnPlayerUpdate 'ticks' up to 32 times per second. So what do you even expect?
Reply
#3

use a variable to detect if the player lost -5 health or not
Reply
#4

Quote:
Originally Posted by DaTa[X]
Посмотреть сообщение
use a variable to detect if the player lost -5 health or not
Completely irrelevant to his goal.

Make your own repeating timer which will decrease your health every x amount of time you will define.
Reply
#5

This?

Код:
new Float: hp;
GetPlayerHealth(playerid, hp);
SetPlayerHealth(playerid, hp-5);
Reply
#6

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
Completely irrelevant to his goal.

Make your own repeating timer which will decrease your health every x amount of time you will define.
Quote:
Originally Posted by return0
Посмотреть сообщение
This?

Код:
new Float: hp;
GetPlayerHealth(playerid, hp);
SetPlayerHealth(playerid, hp-5);
I made a timer that starts on OnPlayerspawn, But its still not working.

Код:
public healthy(playerid)
{
	if(PlayerInfo[playerid][pOthers] == 0)
	{
	    if(IsPlayerInRangeOfPoint(playerid,20.0,1658.5326,-3886.6897,60.7104))
	    {
	        GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
	        new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
	        SetTimerEx("healthy", 4000, false, "i", playerid);
		}
		else if(IsPlayerInRangeOfPoint(playerid,20.0,1656.0800,-3867.5583,52.9705))
		{
			GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
  			new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
    		SetTimerEx("healthy", 4000, false, "i", playerid);
		}
  		else if(IsPlayerInRangeOfPoint(playerid,20.0,1653.4971,-3840.3416,37.3747))
		{
			GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
  			new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
     		SetTimerEx("healthy", 4000, false, "i", playerid);
		}
	 	else if(IsPlayerInRangeOfPoint(playerid,20.0,1641.8463,-3819.9185,31.1975))
		{
			GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
  			new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
    		SetTimerEx("healthy", 4000, false, "i", playerid);
		}
  		else if(IsPlayerInRangeOfPoint(playerid,20.0,1622.8149,-3802.0142,29.7752))
  		{
			GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
  			new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
    		SetTimerEx("healthy", 4000, false, "i", playerid);
		}
		else if(IsPlayerInRangeOfPoint(playerid,20.0,1610.4227,-3780.5847,32.2803))
		{
			GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
  			new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
    		SetTimerEx("healthy", 4000, false, "i", playerid);
		}
		else if(IsPlayerInRangeOfPoint(playerid,20.0,1609.8184,-3750.0193,45.0269))
  		{
  			GameTextForPlayer(playerid, "~g~You hear a ringing noice & your health is dropping!",3500,5);
    		new Float: hp;
			GetPlayerHealth(playerid, hp);
			SetPlayerHealth(playerid, hp-5);
     		SetTimerEx("healthy", 4000, false, "i", playerid);
		}
	}
	return 1;
}
Thats the timer code.

Код:
SetTimerEx("healthy", 4000, false, "i", playerid);
That is on the OnPlayerSpawn, but its still not working.

EDIT: It works but I get insta killed

EDIT2: Works sometimes
Reply
#7

Here is how I would do this...

1) Use streamer plugin
2) Define a dynamic area
3) Start a timer when entering dynamic area to start reducing health
4) Stop timer if activated when player dies, disconnects, or leaves area
Reply
#8

pawn Код:
new bool:IsInArea[MAX_PLAYERS];
new HealthTimer[MAX_PLAYERS];

forward areacheck();
forward health(playerid);

public OnGameModeInit()
{
SetTimer("areacheck", 200, 1);
}

public areacheck()
{
    for (new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            if (IsPlayerInRangeOfPoint(put things here) && IsInArea[i]==false)
            {
                HealthTimer[i]=SetTimerEx("health", 400, 1, "i", i);
                IsInArea[i]=true;
            }
            else
            {
                if (IsInArea[i]==true)
                {
                    IsInArea[i]=false;
                    KillTimer(HealthTimer[i]);
                }
            }
        }
    }
}

public health(playerid)
{
    new Float:h;
    GetPlayerHealth(playerid, h);
    SetPlayerHealth(playerid, h-5)
}
Reply
#9

@Hurtlocker that is a very poor way to do it.
Reply
#10

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
pawn Код:
new bool:IsInArea[MAX_PLAYERS];
new HealthTimer[MAX_PLAYERS];

forward areacheck();
forward health(playerid);

public OnGameModeInit()
{
SetTimer("areacheck", 200, 1);
}

public areacheck()
{
    for (new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            if (IsPlayerInRangeOfPoint(put things here) && IsInArea[i]==false)
            {
                HealthTimer[i]=SetTimerEx("health", 400, 1, "i", i);
                IsInArea[i]=true;
            }
            else
            {
                if (IsInArea[i]==true)
                {
                    IsInArea[i]=false;
                    KillTimer(HealthTimer[i]);
                }
            }
        }
    }
}

public health(playerid)
{
    new Float:h;
    GetPlayerHealth(playerid, h);
    SetPlayerHealth(playerid, h-5)
}
I tried your code to, It works, but it wont stop if I move away from there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)