PDA

View Full Version : OnPlayerTakeDamage


CriticalRP
06/12/2013, 10:17 AM
It looks like OnPlayerTakeDamage is failing to work or return any value.

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
format(gString, sizeof(gString), "{aa0000}- %d HP", amount);
PlayerDamage[playerid] = Create3DTextLabel(gString, 0xFFFFFFFF, 0.0, 0.0, 0.0, 7.5, -1);
Attach3DTextLabelToPlayer(PlayerDamage[playerid], playerid, 0.0, 0.0, 0.4);
SetTimerEx("RemoveDamageLabel", 3000, false, "d", playerid);
}
return 1;
}

McBan
06/12/2013, 10:23 AM
Looks like another system is conflicting with it.

CriticalRP
06/12/2013, 10:43 AM
Is any of these includes has something to do with it?

#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#include <zcmd>
#include <SPC>
#include <streamer>
#include <strlib>
#include <regex>
#include <foreach>
#include <fixes>
#include <timerfix>

xVIP3Rx
06/12/2013, 10:46 AM
Health is a float not an integer...

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
format(gString, sizeof(gString), "{aa0000}- %f HP", amount); //Hp is a float..
PlayerDamage[playerid] = Create3DTextLabel(gString, 0xFFFFFFFF, 0.0, 0.0, 0.0, 7.5, -1);
Attach3DTextLabelToPlayer(PlayerDamage[playerid], playerid, 0.0, 0.0, 0.4);
SetTimerEx("RemoveDamageLabel", 3000, false, "d", playerid);
}
return 1;
}

CriticalRP
06/12/2013, 10:47 AM
This is not my problem here, I have also tried printing whenever a player is taking damage, still doesnt work.

Konstantinos
06/12/2013, 10:50 AM
This is not my problem here, I have also tried printing whenever a player is taking damage, still doesnt work.

Whenever a player is taking damage by another player or self-inflicted?


public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
print("OnPlayerTakeDamage is being called..");
return 1;
}

CriticalRP
06/12/2013, 10:56 AM
Tried them both, both don't work.

Pottus
06/12/2013, 10:57 AM
This code wouldn't work anyways, it will create 3dtext with lost reference the timer should be set using the 3dtext ID not the playerid.

RajatPawar
06/12/2013, 11:02 AM
Pottus;2808483']This code wouldn't work anyways, it will create 3dtext with lost reference the timer should be set using the 3dtext ID not the playerid.Should - he uses a MAX_PLAYER array so the playerID parameter is enough to destroy or modify it!
OT: You should try a print through OnPlayerGiveDamage too, and try de-including some files as said above! Check if a hook to this callback exists somewhere.

Konstantinos
06/12/2013, 11:06 AM
Tried them both, both don't work.

Some of the includes may conflict then as McBan said. Open those includes and search for OnPlayerTakeDamage.

Pottus;2808483']This code wouldn't work anyways, it will create 3dtext with lost reference the timer should be set using the 3dtext ID not the playerid.

He passed playerid as an argument so he can use PlayerDamage[playerid] as the ID of the 3D label in RemoveDamageLabel.

EDIT: Pottus;2808491']What happens when a player is shot twice think about it, the 3dtext id reference would be lost and you'd start getting 3dtext labels that wouldn't be deleted read the code.

You're right, I didn't think about that!

---

However, a player gets shot and all those 3D Labels will be on the other - unreadable. It'd be better to destroy the current 3D Label and create another one, but with what Pottus said.


Delete3DTextLabel(PlayerDamage[playerid]);
PlayerDamage[playerid] = Create3DTextLabel(gString, 0xFFFFFFFF, 0.0, 0.0, 0.0, 7.5, -1);
Attach3DTextLabelToPlayer(PlayerDamage[playerid], playerid, 0.0, 0.0, 0.4);
SetTimerEx("RemoveDamageLabel", 3000, false, "d", PlayerDamage[playerid]);


// an example:
forward RemoveDamageLabel(labelid);
public RemoveDamageLabel(labelid)
{
Delete3DTextLabel(labelid);
}

Pottus
06/12/2013, 11:06 AM
Should - he uses a MAX_PLAYER array so the playerID parameter is enough to destroy or modify it!
OT: You should try a print through OnPlayerGiveDamage too, and try de-including some files as said above! Check if a hook to this callback exists somewhere.

What happens when a player is shot twice think about it, the 3dtext id reference would be lost and you'd start getting 3dtext labels that wouldn't be deleted read the code.

CriticalRP
06/12/2013, 11:42 AM
Everything's sorted out but that includes thing, I couldn't find any conflict or something that coalesces with OnPlayerTakeDamage.

Riddick94
06/12/2013, 12:53 PM
Delete3DTextLabel(PlayerDamage[playerid]);
PlayerDamage[playerid] = Create3DTextLabel(gString, 0xFFFFFFFF, 0.0, 0.0, 0.0, 7.5, -1);
Attach3DTextLabelToPlayer(PlayerDamage[playerid], playerid, 0.0, 0.0, 0.4);
SetTimerEx("RemoveDamageLabel", 3000, false, "d", PlayerDamage[playerid]);

Can you imagine these timers called everytime when callback is called? Also, my suggestion is to kill timer before it's called.

CriticalRP
06/12/2013, 01:00 PM
Optimization is not the actual problem here, I just want the public to be called.

yanir3
06/12/2013, 01:01 PM
Yes you need to insert
Fix() in the function

OK

Richie©
06/12/2013, 02:21 PM
Why not just use SetPlayerChatBubble (http://wiki.sa-mp.com/wiki/SetPlayerChatBubble) ?

CriticalRP
06/12/2013, 10:12 PM
This is not my problem here, the problem is that the callback in not being called.

Pottus
06/12/2013, 10:17 PM
Why not just use SetPlayerChatBubble (http://wiki.sa-mp.com/wiki/SetPlayerChatBubble) ?

That is probably a very very good way to do it.

CriticalRP
08/12/2013, 04:25 PM
I can't even use SendClientMessage as the callback is not being called.

Anyone?

CriticalRP
11/12/2013, 09:27 PM
Bump.