PDA

View Full Version : Damage system help!


TheSnicky
14/08/2014, 07:41 PM
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
{
new
weaponName[24],
victimName[MAX_PLAYER_NAME],
attackerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, victimName, sizeof (victimName));
GetPlayerName(issuerid, attackerName, sizeof (attackerName));
GetWeaponName(weaponid, weaponName, sizeof (weaponName));
if (IsHurt[playerid] == 0)
{
new string[64];
format(string,sizeof(string),"(( Has been injured %f , Weapon: %s ))", amount, weaponName);
new Text3D:wounded;
wounded = Create3DTextLabel(string, 0xAA3333AA, 30.0, 40.0, 50.0, 40.0, 0);
Attach3DTextLabelToPlayer(wounded, playerid, 0.0, 0.0, 0.7);
Update3DTextLabelText(wounded, 0xAA3333AA, string);
}
}
return 1;
}

It compiles without any erros or anything. But when I shot him once, it says " (( Has been injured 46.0000 times )) " But I want when I shoot him once, to says " (( Has been injured 1 time )). Please help!

Faisal_khan
14/08/2014, 07:45 PM
Float: amount is not the no. of times the player has been shot, but it is the health which has been reduced.

TheSnicky
14/08/2014, 07:45 PM
How do I make it like I want it ?

Cepillado
14/08/2014, 07:50 PM
Maybe you could make something like

new Injuries[MAX_PLAYERS];

and then

if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
{
Injuries[playerid] ++;

Faisal_khan
14/08/2014, 07:52 PM
Untested:new shot[MAX_PLAYERS];
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
{
new
weaponName[24],
victimName[MAX_PLAYER_NAME],
attackerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, victimName, sizeof (victimName));
GetPlayerName(issuerid, attackerName, sizeof (attackerName));
GetWeaponName(weaponid, weaponName, sizeof (weaponName));
shot[playerid]++;
if(IsHurt[playerid] == 0)
{
new string[64];
format(string,sizeof(string),"(( Has been injured %d times, Weapon: %s ))", shot[playerid], weaponName);
new Text3D:wounded;
wounded = Create3DTextLabel(string, 0xAA3333AA, 30.0, 40.0, 50.0, 40.0, 0);
Attach3DTextLabelToPlayer(wounded, playerid, 0.0, 0.0, 0.7);
Update3DTextLabelText(wounded, 0xAA3333AA, string);
}
}
return 1;
}

TheSnicky
14/08/2014, 09:29 PM
Now it says "Has been injured 0.0000 times"

TheSnicky
14/08/2014, 09:32 PM
Someone please help!! :P

Cepillado
14/08/2014, 09:35 PM
Can you show us how you added it?

TheSnicky
14/08/2014, 09:36 PM
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
{
new
weaponName[24],
victimName[MAX_PLAYER_NAME],
attackerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, victimName, sizeof (victimName));
GetPlayerName(issuerid, attackerName, sizeof (attackerName));
GetWeaponName(weaponid, weaponName, sizeof (weaponName));
shot[playerid] ++;
if (IsHurt[playerid] == 0)
{
new string[64];
format(string,sizeof(string),"(( Has been injured %d , Weapon: %s ))", shot[playerid], weaponName);
new Text3D:wounded;
wounded = Create3DTextLabel(string, 0xAA3333AA, 30.0, 40.0, 50.0, 40.0, 0);
Attach3DTextLabelToPlayer(wounded, playerid, 0.0, 0.0, 0.7);
Update3DTextLabelText(wounded, 0xAA3333AA, string);
}
}
return 1;
}

Cepillado
14/08/2014, 09:41 PM
Where is the new shot[MAX_PLAYERS];?

TheSnicky
14/08/2014, 09:43 PM
I added that too, but not on the OnPlayerTakeDamage, do I need to add it there?

TheSnicky
14/08/2014, 09:45 PM
Do I have to add it on OnPlayerTakeDamage, because I didn't add it on there?

Cepillado
14/08/2014, 09:47 PM
No, it isn't because of that, I think that is because you are still using %f in the string, change it to %i or %d and see if it works

TheSnicky
14/08/2014, 09:48 PM
format(string,sizeof(string),"(( Has been injured %d , Weapon: %s ))", shot[playerid], weaponName);
I'm using this, should I change it ?

Cepillado
14/08/2014, 09:51 PM
No, I'm sorry, I didn't notice that you had already changed it. However, there is something that I don't understand, if you are using %d then why is it saying "has been injured 0.0000 times"? 0.000 is a float, it should show "has been injured x times", as a whole number.

Faisal_khan
15/08/2014, 06:31 AM
This string which you are getting, "has been injured 0.0000 times" is way too different to (( Has been injured %d , Weapon: %s )).

Oh one more thing, try this:new shot[MAX_PLAYERS];
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
{
new
weaponName[24],
victimName[MAX_PLAYER_NAME],
attackerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, victimName, sizeof (victimName));
GetPlayerName(issuerid, attackerName, sizeof (attackerName));
GetWeaponName(weaponid, weaponName, sizeof (weaponName));
if(IsHurt[playerid] == 0)
{
new string[64];
shot[playerid]++;
format(string,sizeof(string),"(( Has been injured %d times, Weapon: %s ))", shot[playerid], weaponName);
new Text3D:wounded;
wounded = Create3DTextLabel(string, 0xAA3333AA, 30.0, 40.0, 50.0, 40.0, 0);
Attach3DTextLabelToPlayer(wounded, playerid, 0.0, 0.0, 0.7);
Update3DTextLabelText(wounded, 0xAA3333AA, string);
}
}
return 1;
}