Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Skills, weapon or class? (https://forums.graalonline.com/forums/showthread.php?t=134260852)

Cubical 10-17-2010 09:58 PM

Skills, weapon or class?
 
What would be the best way to save your skills? In a weapon or class, I'm leaning twords class because I could use them without having to remake them for monsters.

Also I was wondering what would be the best way to call it if it were in a class?
weapon
PHP Code:

public function triggerSkill(skillname){
  
join(skillname);
  
onUseSkill("npc");
} 

class
PHP Code:

public function onUseSkill(attacker){
  
//do stuff
} 

or would there be a better way to do it?

xXziroXx 10-18-2010 02:37 PM

I use classes for skills and spells on Maloria, and call them from a weapon. I'm also using code that allows the same skill to be triggered both by players and NPCs. Here's an example of a skill:


PHP Code:

public function onUseSkill(target)
{
  
temp.var = (objecttype() == "TServerPlayer" ? "clientr" : "this");
  
temp.var2 = (objecttype() == "TServerPlayer" ? "client" : "this");
  
  
// Name of this skill
  
temp.skill = "melee";
  
// Skill data
  
temp.skill.copyFrom(this.skills.(@skill));
  
// What hand is the player attacking with (MainHand/OffHand)?
  //this.(@temp.skill @ "_hand") = (this.(@temp.skill @ "_hand") == "MainHand" ? "OffHand" : "MainHand");
  
this.(@temp.skill.indentifier @ "_hand") = "MainHand";
  
// What is equipped in that hand?
  
temp.identifier = this.equippedInSlot(this.(@temp.skill.indentifier @ "_hand"));
  
temp.identifier = this.getItemIdentifier(temp.identifier);
  
// Item data
  
temp.item_data = CACHE.query("items", temp.identifier);
  
  if (var == 
"this") {
    (@
var2).freezetimer = item_data.freezeTimer;
  
    
setCharAni(this.gani_idle, "");
    
setCharAni(this.gani_attack, "");
    
    if (
this.width == NULL && this.height == NULL)
      
temp.tarsize = { 2, 3 };
    else
      
temp.tarsize = { this.width, this.height };
    
    
this.dir = getdir((target.x + 1.5) - (this.x + temp.tarsize[0]/2), (target.y + 2) - (this.y + temp.tarsize[1]/2));
  }
  
target.trigger("WeaponAttack", this, (@var).equipped_MainHand);
}

//#CLIENTSIDE
public function onUseSkill()
{
  
temp.var = (this.objecttype() == "TPlayer" ? "client" : "this");
  
  
// Is the player already busy?
  
if ((@var).freezetimer > 0)
    return;
  
  
// Name of this skill
  
temp.skill = "melee";
  
// Skill data
  
temp.skill.copyFrom(this.skills.(@skill));
  
// What hand is the player attacking with (MainHand/OffHand)?
  //this.(@temp.skill @ "_hand") = (this.(@temp.skill @ "_hand") == "MainHand" ? "OffHand" : "MainHand");
  
this.(@temp.skill @ "_hand") = "MainHand";
  
// What is equipped in that hand?
  
temp.identifier = player.equippedInSlot(this.(@temp.skill @ "_hand"));
  
temp.identifier = player.getItemIdentifier(temp.identifier);
  
// Item data
  
temp.item_data = CACHE.query("items", temp.identifier);
    
  (@var).
freezetimer = temp.item_data.freezeTimer;
    
  
setAni(client.gani_idle, "");
  
setAni(client.gani_attack, "");
} 

In this case, the Combat weapon triggers the clientsided part of the skills first (simply to make things look smooth, mainly animations) and then triggers it to call on serverside as well (after some hitdetection etc. have been handled) to do the actual damage and whatnot.

xXziroXx 10-19-2010 08:05 PM

Quote:

Originally Posted by Cubical (Post 1606995)
Also I was wondering what would be the best way to call it if it were in a class?

Forgot to answer this question. I do it like this:

PHP Code:

object.("skill_" @ identifier @ "::onUseSkill")() 

Assume identifier equals melee and that the class name is skill_melee.


All times are GMT +2. The time now is 01:21 AM.

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