Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Script: Player HP functions (https://forums.graalonline.com/forums/showthread.php?t=68271)

Skyld 08-21-2006 10:14 PM

Script: Player HP functions
 
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(41);
  }
}

//#CLIENTSIDE

function onWeaponFired()
{
  
triggeraction(00"serverside"this.name"activate");


And finally the class. Enjoy.

PHP Code:

// Scripted by Skyld

public function attackNearestPlayers(damageradius)
{
  for (
temp.playerfindNearestPlayers(this.xthis.y))
  {
    if (
temp.player == this)
    {
      continue;
    }
    
    
temp.dx temp.player.1.5 - (this.1.5 vecx(this.dir) * 2);
    
temp.dy temp.player.- (this.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.1.5temp.player.1.5) ||
          
temp.player.ani != "swim")
      {
        
temp.player.onPlayerDamage(player.accounttemp.damage);
      }
    }
  }
}

public function 
playerRevive()
{
  if (
this.clientr.dead)
  {
    
this.clientr.dead 0;
    
this.clientr.hp this.clientr.maxhp;
    
    
this.setAni("idle""");
  }
}

public function 
onPlayerDamage(attackerdamage)
{
  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.accounttemp.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.accounttemp.attacker));
  }



Angel_Light 08-21-2006 10:21 PM

wow thank-you so much ^-^ this will help me with my exp system ^_^

Jesusxd96 04-09-2012 12:34 AM

Wow awesome for my server :D Thanks


All times are GMT +2. The time now is 02:37 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.