OnPlayerTakeDamage gets called wrong
#1

Hi, I've recently made a skin hit system which uses OnPlayerTakeDamage.
But after i restart my server (without the player leaving), when a player spawns the public will automatically get called.

Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    SendClientMessage(playerid, -1, "This will get called after restart on spawn");
    //Other Code
    return 1;
}
This is a SA:MP bug am i right?
Reply
#2

Confirmed.
Reply
#3

how much is the amount of damage lost? if it's 0.0 can't you detect it with that?
Reply
#4

Alternate Fix
I'm aware that you can remove few lines from what is being stated in this post but SA-MP acts weird sometimes so I'm just making sure that nothing would go off the plan.

Make a public variable on top of your script.
pawn Code:
new Spawned[MAX_PLAYERS];
Add this to the following callbacks: OnPlayerConnect & OnPlayerDisconnect
pawn Code:
Spawned[playerid] = 0;
Add this to the following callbacks: OnGameModeInit, OnGameModeExit
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    Spawned[i] = 0;
}
Add this to the following callback: OnPlayerSpawn
pawn Code:
Spawned[playerid] = 1;
Now change your code to:
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(!Spawned[playerid])
    {
        Spawned[playerid] = 1;
    }
    else
    {
        SendClientMessage(playerid, -1, "This will get called after restart on spawn");
        //Other Code
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)