OnPlayerTakeDamage - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerTakeDamage (
/showthread.php?tid=395517)
OnPlayerTakeDamage -
Blackazur - 26.11.2012
Hello, i have a Problem with OnPlayerTakeDamage:
Код:
[18:37:37] [debug] Run time error 4: "Array index out of bounds"
[18:37:37] [debug] Accessing element at index 65535 past array upper bound 49
[18:37:37] [debug] AMX backtrace:
[18:37:37] [debug] #0 00044a5c in public OnPlayerTakeDamage ()
Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(PlayerTeam[playerid] != PlayerTeam[issuerid])
{
new Float:hp;
new Float:armour;
GetPlayerHealth(playerid,hp);
GetPlayerArmour(playerid,armour);
switch(weaponid)
{
case 4: // Knife
{
if(armour > 0.0)
{
SetPlayerArmour(playerid,armour-50.0);
}
else
{
SetPlayerHealth(playerid,hp-45.0);
}
}
}
}
return 1;
}
Re: OnPlayerTakeDamage -
you10 - 26.11.2012
You need to check that issuerid is a valid playerid.
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
if(PlayerTeam[playerid] != PlayerTeam[issuerid])
{
new Float:hp;
new Float:armour;
GetPlayerHealth(playerid,hp);
GetPlayerArmour(playerid,armour);
switch(weaponid)
{
case 4: // Knife
{
if(armour > 0.0)
{
SetPlayerArmour(playerid,armour-50.0);
}
else
{
SetPlayerHealth(playerid,hp-45.0);
}
}
}
}
}
return 1;
}
Re: OnPlayerTakeDamage -
Gangster-rocks - 26.11.2012
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(PlayerTeam[playerid] != PlayerTeam[issuerid])
{
new Float:hp;
new Float:armour;
GetPlayerHealth(playerid,hp);
GetPlayerArmour(playerid,armour);
switch(weaponid)
{
case 4: // Knife
{
if(armour > 0.0)
{
SetPlayerArmour(playerid,armour-50.0);
}
else if(hp > 0.0)
{
SetPlayerHealth(playerid,hp-45.0);
}
}
}
}
return 1;
}
i am pretty sure it will work now