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.