Sync Player Health and Armour
#1

So...i have a deathmatch system with many features.

I need to figure it out how to do a sync player health and armour.

I have 2 var, Health[playerid] and Armour[playerid], and I check every time when someone shoot in him using OnPlayerGiveDamage

here what I use: https://pastebin.com/ed6WhGW2

So all works, but the problem is when no one shot him, and he falls from a building or else (when no one shoot in him) hes health or amour(if has) are decrease, so after that, a player come and shot for example 1 bullet the health will change to the variable health/armour (the variable does not know when it's been downgraded his last health/armour) so .. i need to know how to do that. When the player take damage from falling/explosion to decrease in health[playerid] or armour[playerid]..

Example:

The player has health 100 (Health[playerid] = 100.0).
The player lost 50 hp from falling from a building (remain health: 50, but the variabile Health[playerid] remain 100);
Another player came to our player and shot 1 bullet with m4 (-10hp). his health is set to 90 not to 40.

I know that his variabile (health[playerid]) is changed only when someone shoot in him, but i don't really know how to check if the player has falling or something else..

Can someone give me some advice or explain me how to resolve that?
Reply
#2

If he's falling, then you need to add in OnPlayerTakeDamage.
Reply
#3

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
If he's falling, then you need to add in OnPlayerTakeDamage.
1. So, if is a problem if i do something like this?

Код:
if(issuerid == INVALID_PLAYER_ID) { // code here }
and is there a problem if in OnPlayerDeath i check for 2 times if killerid != INVALID_PLAYER_ID?
something like this https://pastebin.com/ZyMassCy
Reply
#4

Falling damage isn't a given damage, it's a taken by the looks.

So you need to add in OnPlayerTakeDamage and check for the fall, and modify the health variable accordingly. That should make the variable track better.


Код:
if(issuerid == INVALID_PLAYER_ID) { // code here }
And probably that is what you need to do in this (OnPlayerTakeDamage) callback... Check for invalid_player_id and use that to check for the fall. Just be careful and use output to the chat so you can check if it'll malfunction at all.


Ideally if you were to debug, you could output the damage information of everything (Give,Take,Death) to the chatlog so you can see what it's picking up.
Reply
#5

I try using OnPlayerTakeDamage, but the player health is restored now when a another player cames to him and try to beat him (with punch).

So a player has for example 50 hp. And another player cames to him and give him a punch, his health need to decrease , for example -5 hp, so the player should have 45 hp, but Player HP will restored to last HP (50). I don't know why, how can I fix this?

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(issuerid == INVALID_PLAYER_ID)
    {
        new Float: HP;
		GetPlayerHealthEx(playerid,HP);
		
		new Float: remainHP = HP - amount;
		SetPlayerHealthEx ( playerid, remainHP );
		
		if ( remainHP <= 1 )
		{
			OnPlayerDeath( playerid, INVALID_PLAYER_ID, weaponid );
			SetPlayerHealthEx ( playerid, 0.0 );
			playerdeath[playerid] = 1;
		}
    }
    return 1;
}
Reply
#6

You're not setting the Health[playerid] in that section, that's why they get their health back.


-edit- didn't see SetPlayerHealthEx s purpose...
Reply
#7

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
You're not setting the Health[playerid] in that section, that's why they get their health back.


-edit- didn't see SetPlayerHealthEx s purpose...
So..how can I fix?
Reply
#8

SetHPlayerHealthEx s purpose is this... It does this, so I'm not sure what will be causing it.


What you could do is show more info to yourself. Like send all health changes to the chat window, along with the current Health[playerid] e.t.c. If the info sent to you in the chat window seems odd, then the more info you have you may be able to pick up a pattern.

Effectively a debug message, but for inside the game. Where we use print and printf for crashing servers, because you're not crashing, by displaying it in the text, then you'll be able to run the test for a while and see what variables are coming through.
Reply
#9

just type this OnPlayerTakeDamage
Health[playerid] -= amount;
you don't need nothing more.
Reply
#10

Quote:
Originally Posted by Mugalito
Посмотреть сообщение
just type this OnPlayerTakeDamage
Health[playerid] -= amount;
you don't need nothing more.
Look at his code... I thought that too, but his SetPlayerHealthEx does this, as it does also in the other callbacks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)