Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Joining and leaving classes (https://forums.graalonline.com/forums/showthread.php?t=134268658)

Cubical 08-23-2013 06:09 PM

Joining and leaving classes
 
is there an event called when joining and/or leaving classes? Something along the lines of onJoinedClass(); and onLeaveClass();.

I'm at work right now so I cannot provide an exact example of what I'm currently doing but it's something along the lines of the following.

PHP Code:

functions loadClassData(temp.objtemp.classlist) {
  for (
temp.classnametemp.classlist) {
    if (
temp.classname in temp.obj.joinedclasses) {
      
temp.obj.(temp.classname "::onJoined")();
    } else {
      
temp.obj.join(temp.classname);
      
temp.obj.(temp.classname "::onJoined")();
    }
  }


I did a quick search and didn't see anything that stuck out.

baseman101 08-23-2013 06:17 PM

Yes, there does happen to be an event that happens when you join a class. I'm certain about onClassJoined() but not too certain about onClassLeaves (or something similar).

Cubical 08-23-2013 06:45 PM

Quote:

Originally Posted by baseman101 (Post 1721948)
Yes, there does happen to be an event that happens when you join a class. I'm certain about onClassJoined() but not too certain about onClassLeaves (or something similar).

Could not find any documentation on it and a forum search yielded no relevant post.

xXziroXx 08-23-2013 06:51 PM

PHP Code:

onClassLoaded(strevent class script has been updatedname of the class 

That's about it. What are you trying to achieve?

Cubical 08-23-2013 06:53 PM

Quote:

Originally Posted by xXziroXx (Post 1721951)
PHP Code:

onClassLoaded(strevent class script has been updatedname of the class 

That's about it. What are you trying to achieve?

Ah, was looking for 'join' not 'class' when i was searching scriptfuctions

Cubical 08-23-2013 07:03 PM

Double post since you wanted to know what i was trying to achieve.

For certain classes such as skills I want to load all the data such as names, icons and descriptions when it's initially loaded. It's more for the benefit of tool tips than anything else. I don't feel the need to make a database with descriptions and such of each. I only have 4 skills per class that i can load in a single array for each of them so it's not like i'm setting 50 flags with a huge amount of data in them. I didn't feel like it requires an SQLite table. I'll see if this resolves my issue when i get off work.

xXziroXx 08-23-2013 07:19 PM

I have a similar approach on Maloria, although instead I make sure to load all the important classes upon login before proceeding with adding any weapons.

PHP Code:

function onActionServerSide(temp.command)
{
  if (
temp.command == "initialized") {
    
player.triggerAllWeapons("onPlayerInitialized");
    
    
player.removeWeapon(this.name);
  }
}

public function 
loadClasses()
{
  if (
player.classesLoaded)
    return echo(
format("[%s]: Classes already loaded for player %s, aborting..."this.nameplayer.communityName));
  
  
temp.classList = { // Array with the classes you want to preload
  
};
  
  for (
temp.classNametemp.classList)
    
player.join(temp.className);
  
  
player.classesLoaded true;
  
triggerClient("gui"this.name"loadClasses"temp.classList);
}

function 
onPlayerLogout(temp.playerObject)
  
temp.playerObject.classesLoaded false;

//#CLIENTSIDE
const DEBUG_MODE true;

function 
onActionClientSide(temp.command)
{
  
// Return if it's not the trigger sent from loadClasses()
  
if (temp.command != "loadClasses")
    return;
  
// Return if classes has already been loaded this session
  
if (player.classesLoaded)
    return;
  
  
temp.classList.copyFrom(params[1]);
  
  for (
temp.classNametemp.classList) {
    
// Load the class to the player
    
if (!player.isInClass(temp.className)) {
      
player.join(temp.className);
      
debug(format("[%s]: Joining class '%s'..."this.nametemp.className));
    }
    
    
// Maybe the class is loaded already?
    
if (isClassLoaded(temp.className)) {
      continue;
    }
    
    
loadClass(temp.className);
    
debug(format("[%s]: Class '%s' not loaded yet, loading..."this.nametemp.className));
    
    while (!
isClassLoaded(temp.className))
      
sleep(0.05);
  }
  
  
player.classesLoaded true;
  
debug(format("[%s]: All classes loaded!"this.name));
  
  
triggerServer("gui"this.name"initialized");
}




function 
debug(temp.text)
{
  if (
DEBUG_MODE)
    echo(
temp.text);



Cubical 08-23-2013 07:25 PM

I'm actually doing something more similar to your post than my original but sometimes joining clientside classes is touchy and unreliable as they don't load right away. I might need to add a sleep such as you have and that would probably resolve those issues.

Cubical 08-23-2013 11:57 PM

onClassLoaded doesn't do anything it appears.

fowlplay4 08-24-2013 12:44 AM

Are you giving your skills their own weapon script?

If so just store a 'this.description' flag for your other scripts to read from.

Cubical 08-24-2013 12:49 AM

Quote:

Originally Posted by fowlplay4 (Post 1721967)
Are you giving your skills their own weapon script?

If so just store a 'this.description' flag for your other scripts to read from.

I'm creating them all in classes so I can easily use the same skills with NPCs such as baddies or friendly quest NPCs without rescripting them.

xXziroXx 08-24-2013 05:58 AM

Quote:

Originally Posted by fowlplay4 (Post 1721967)
Are you giving your skills their own weapon script?

I'm not. Each skill has it's own class code. At some point, I made all skills useable by both players and NPC baddies, which was quite messy but worked quite nicely for spells and such that you'd want NPC baddies to be able to use. Old example of it:

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};
    else
      
temp.tarsize = { this.widththis.height };
    
    
this.dir getdir((target.1.5) - (this.temp.tarsize[0]/2), (target.2) - (this.temp.tarsize[1]/2));
  }
  
  
target.trigger("WeaponAttack"this, (@var).equipped_MainHand);
}

//#CLIENTSIDE
public function onUseSkill()
{
  
temp.var = (this.objecttype() == "TPlayer" "player" "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"));
  
//echo(this.(@temp.skill @ "_hand") @ ":" SPC temp.identifier);
  
temp.identifier player.getItemIdentifier(temp.identifier);
  
// Item data
  
temp.item_data CACHE.query("items"temp.identifier);
    
  (@var).
freezetimer temp.item_data.freezeTimer;
    
  
onSetAni(client.gani_idle);
  
onSetAni(client.gani_attack);
}

function 
onSetAni(gani)
{
  if (
player != NULL)
    
setAni(gani"");
  else
    
setCharAni(gani"");


(it's old, messy and made with poor styling - I haven't actually been using it since 2010)


All times are GMT +2. The time now is 06:28 AM.

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