Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-17-2010, 09:58 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
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?
Reply With Quote
  #2  
Old 10-18-2010, 02:37 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 10-19-2010, 08:05 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Cubical View Post
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
Reply


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 01:21 AM.


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