28.06.2018, 18:28
I am using the weapon-config plugin and I am working on an 'injury system'. The idea is that if you die, you respawn at the location where you died and you're forced into an animation. This only happens if you are not injured already.
Right now I've got the following code:
In here I store the coordinates where the player died:
This part is supposed to be respawning the player in the same location where he died:
Instead of moving the player to the stored coordinates he is being teleported to Blueberry (coordinates 0.0, 0.0, 0.0). I have tried using the OnPlayerDeath callback too but I can't seem to get it working.
Does anyone have an idea of what I am doing wrong?
Right now I've got the following code:
In here I store the coordinates where the player died:
PHP код:
public OnPlayerDamage(&playerid, &Float:amount, &issuerid, &weapon, &bodypart)
{
<blabla>
new Float:hp;
GetPlayerHealth(playerid, hp);
if(hp - amount <= 0.0)
{
SendClientMessageToAll(COLOR_WHITE, "New HP = less than 0");
GetPlayerPos(playerid, pInfo[playerid][pInjuredX], pInfo[playerid][pInjuredY], pInfo[playerid][pInjuredZ]);
new str[128];
format(str, sizeof(str), "Injured coords; %f, %f, %f", pInfo[playerid][pInjuredX], pInfo[playerid][pInjuredY], pInfo[playerid][pInjuredZ]);
SendClientMessageToAll(COLOR_WHITE, str);
}
return 1;
}
PHP код:
public OnPlayerPrepareDeath(playerid, animlib[32], animname[32], &anim_lock, &respawn_time)
{
respawn_time = 1;
SendClientMessageToAll(COLOR_WHITE, "OnPlayerPrepareDeath called");
return 1;
}
public OnPlayerDeathFinished(playerid, bool:cancelable)
{
if(pInfo[playerid][pInjured] == 0)
{
SendClientMessageToAll(COLOR_WHITE, "Injured = 0");
pInfo[playerid][pInjured] = 1;
pInfo[playerid][pInjuredRefreshTimer] = 5;
SetPlayerPos(playerid, pInfo[playerid][pInjuredX], pInfo[playerid][pInjuredY], pInfo[playerid][pInjuredZ]);
SetPlayerSkin(playerid, pInfo[playerid][pSkin]);
new str[128];
format(str, sizeof(str), "Injured coords (OnPlayerDeath); %f, %f, %f", pInfo[playerid][pInjuredX], pInfo[playerid][pInjuredY], pInfo[playerid][pInjuredZ]);
SendClientMessageToAll(COLOR_WHITE, str);
pInfo[playerid][pHealth] = 100.0;
pInfo[playerid][pArmor] = 0.0;
SetPlayerHealth(playerid, pInfo[playerid][pHealth]);
SetPlayerArmour(playerid, pInfo[playerid][pArmor]);
PlayDeathAnimation(playerid);
}
else
{
SendClientMessageToAll(COLOR_WHITE, "Injured != 0");
pInfo[playerid][pInjured] = 0;
pInfo[playerid][pInjuredRefreshTimer] = 0;
pInfo[playerid][pHealth] = 50.0;
pInfo[playerid][pArmor] = 0.0;
SetPlayerHealth(playerid, pInfo[playerid][pHealth]);
SetPlayerArmour(playerid, pInfo[playerid][pArmor]);
}
return 1;
}
Instead of moving the player to the stored coordinates he is being teleported to Blueberry (coordinates 0.0, 0.0, 0.0). I have tried using the OnPlayerDeath callback too but I can't seem to get it working.
Does anyone have an idea of what I am doing wrong?