Here is a basic HP functions class. Feel free to use it as a template for a more complex HP system. This is by far complete; it is merely a template which you can build up on.
This serves as a replacement for default HP. However, here are only the attack, receive and death functions; you will need to script additional stuff to complete it off for anything else you might require.
Setting level.nopk to true makes the area No-PKable, although this could easily be changed to match your system. Similarly, you will need to incorporate into your movement system detection for the player being dead (player.clientr.dead, true/false).
This class will need to be joined to the player to provide the functions. For example if you saved these functions in the class "playerhp", you would use the following when the player logs on.
PHP Code:
player.join("playerhp");
The variables involved are:
- clientr.hp - player's current HP
- clientr.maxhp - player's max HP
- clientr.dead - if the player is dead or not
- clientr.lastkiller - who last killed the current player
- clientr.lastkilled - who the current player last killed
- clientr.kills - kill count
- clientr.deaths - death count
And the functions that you'll want to use:
- player.attackNearestPlayers(damage, radius); - attack players in a certain radius
- player.playerRevive(); - bring back from the dead
The other functions are automatically used by the functions themselves; you probably don't need to worry about them.
The script must be used serverside; therefore, an example of using the HP functions to attack players at a radius of 4:
PHP Code:
function onActionserverside()
{
if (params[0] == "activate")
{
player.attackNearestPlayers(4, 1);
}
}
//#CLIENTSIDE
function onWeaponFired()
{
triggeraction(0, 0, "serverside", this.name, "activate");
}
And finally the class. Enjoy.
PHP Code:
// Scripted by Skyld
public function attackNearestPlayers(damage, radius)
{
for (temp.player: findNearestPlayers(this.x, this.y))
{
if (temp.player == this)
{
continue;
}
temp.dx = temp.player.x + 1.5 - (this.x + 1.5 + vecx(this.dir) * 2);
temp.dy = temp.player.y + 2 - (this.y + 1.5 + vecy(this.dir) * 2);
temp.distance = (temp.dx * temp.dx + temp.dy * temp.dy) ^ 0.5;
if (level.nopk)
{
return;
}
if (temp.distance <= temp.radius)
{
if (!onwater(temp.player.x + 1.5, temp.player.y + 1.5) ||
temp.player.ani != "swim")
{
temp.player.onPlayerDamage(player.account, temp.damage);
}
}
}
}
public function playerRevive()
{
if (this.clientr.dead)
{
this.clientr.dead = 0;
this.clientr.hp = this.clientr.maxhp;
this.setAni("idle", "");
}
}
public function onPlayerDamage(attacker, damage)
{
if ((this.clientr.hp - temp.damage) > 0)
{
this.clientr.hp -= temp.damage;
this.setani("hurt", "");
}
else
{
this.onPlayerKilled(temp.attacker);
}
}
public function onPlayerKilled(attacker)
{
this.clientr.lastkiller = temp.attacker;
this.clientr.dead = 1;
this.clientr.hp = 0;
this.clientr.deaths ++;
player.setAni("dead", "");
temp.murderer = findPlayer(temp.attacker);
if (temp.murderer != NULL)
{
temp.murderer.playerKillCredit(this.account);
}
else
{
echo(format("%s error: killer %s logged off before credit given",
this.account, temp.attacker));
}
}
public function playerKillCredit(victim)
{
temp.player = findPlayer(temp.victim);
if (temp.player != NULL)
{
this.clientr.kills ++;
this.clientr.lastkilled = temp.victim;
}
else
{
echo(format("%s error: victim %s logged off before credit given",
this.account, temp.attacker));
}
}