Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-21-2006, 10:14 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
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));
  }

Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:27 PM.


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