Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Plugin class (https://forums.graalonline.com/forums/showthread.php?t=73486)

Novo 04-14-2007 08:07 PM

Plugin class
 
PHP Code:

/****
This allows codes to be added to a weapon without
any further editing of the code itself.

(+) addPlugin( pluginType, pluginName, object, function )
  - Adds plugin to system
  - returns data from object.function( default )

(+) remPlugin( pluginType, pluginName )
  - removes plugin

(-) getPlugin( pluginType, default, pluginName )
  - Get the value from a plugin
  - If pluginName is set, from a specific Name

(-) getPlugins( pType )
  - returns Plugin with data
  - if pType is empty, return all plugins

example:
NPC1:
function onCreated()
  {
  NPC2.addPlugin( "listen", "hello", this, "sayHello" );
  }

public function sayHello( pDefault )
  {
  return "Hello";
  }

NPC2:
function listen()
  {
  temp.messages = plugin::getPlugin( "listen" );
  echo( m ); // Returns "Hello"
  }
****/

public function addPluginpTypepNameobjfunc )
  {
  if ( 
remPluginpTypepName ) )
    { 
// Removed old!
    
this.plugins.add( {pTypepNameobjfunc } );
    }

  return 
true;
  }

public function 
remPluginpTypepName )
  {
  for ( 
0this.plugins.size(); ++ )
    {
    if ( 
this.plugins[i][0] != pType )
      continue;
    if ( 
this.plugins[i][1] != pName )
      continue;
    
    
this.plugins.delete-- ); // deletes this index, next is same.
    
return true// Shouldn't have two copies...
    
}
  return 
true;
  }

function 
getPluginpTypepDefaultpName)
  {
  for ( 
pthis.plugins )
    {
    if ( 
pType != p[0] )
      continue;
    if ( 
pName != null && pName != p[1] )
      continue;

    
pDefault p[2].(@ p[3] )( pDefault );
    }

  return 
pDefault;
  }

function 
getPluginspType )
  {
  if ( 
pType == null )
    return 
this.plugins;

  for ( 
pthis.plugins )
    {
    if ( 
pType != p[0] )
      continue;
    
temp.plugins.add);
    }

  return 
temp.plugins;
  } 


Inverness 04-14-2007 09:11 PM

I'm confused as to how this could be used...

Rapidwolve 04-14-2007 09:20 PM

Quote:

Originally Posted by Inverness (Post 1299965)
I'm confused as to how this could be used...

Same here...

Novo 04-14-2007 10:13 PM

Quote:

Originally Posted by Inverness (Post 1299965)
I'm confused as to how this could be used...

For modular scripts. A plugin would add on to the script itself in a specific part of the code. This could be used for data compilation, or event-catching as well.

Gambet 04-14-2007 11:32 PM

Quote:

Originally Posted by Novo (Post 1299983)
For modular scripts. A plugin would add on to the script itself in a specific part of the code. This could be used for data compilation, or event-catching as well.


What? Couldn't you use scheduleevent to catch events?


I don't really understand the point of this. :confused:

Chandler 04-14-2007 11:54 PM

What isn't there to understand? Novo has excelled himself again! Nice work

Novo 04-15-2007 12:05 AM

Quote:

Originally Posted by Gambet (Post 1299995)
What? Couldn't you use scheduleevent to catch events?


I don't really understand the point of this. :confused:

scheduleevent and catch event are two DIFFERENT things.

Gambet 04-15-2007 12:09 AM

Quote:

Originally Posted by Novo (Post 1300001)
scheduleevent and catch event are two DIFFERENT things.


Yes, but there is a catchevent function already, though.

Novo 04-15-2007 12:54 AM

Quote:

Originally Posted by Gambet (Post 1300002)
Yes, but there is a catchevent function already, though.

From my recollection of catchevent, it catches GUI events only.

Look, Gambet...

If you don't appreciate, or know how to deploy the plugins, than that is very well: I have not, in any way or form, obliged you to use my class.

If you have problems with such, then I suggest you to just find another thread to argue with.

This is one way to skin a cat. YES THERE ARE OTHERS. But any given environment may incite that a particular way is better. This is only another way to do something.

Chompy 04-15-2007 01:34 AM

Looks interesting Novo! :D

Gambet 04-15-2007 02:01 AM

Quote:

Originally Posted by Novo (Post 1300014)
From my recollection of catchevent, it catches GUI events only.

Look, Gambet...

If you don't appreciate, or know how to deploy the plugins, than that is very well: I have not, in any way or form, obliged you to use my class.

If you have problems with such, then I suggest you to just find another thread to argue with.

This is one way to skin a cat. YES THERE ARE OTHERS. But any given environment may incite that a particular way is better. This is only another way to do something.


I'm only trying to understand how your system works. Apparently, asking you questions will only lead you to have a defensive attack against the person asking. I never even mentioned that your system was bad or anything of the sort for you to grow so defensive when I'm merely asking questions.


As for catchevent, I havn't bothered using it outside of GUIs to know whether they only work in GUIs or not but I'm sure you could easily use it outside a GUI function and find out if it works.

Inverness 04-15-2007 02:03 AM

Oh I think I did something like this before. I made an EventServer class and objects could use ObjectWithClass.register(Object); and when someone used triggerEvent() it would trigger the event on all objects registered.

Novo 04-15-2007 02:35 AM

Quote:

Originally Posted by Inverness (Post 1300039)
Oh I think I did something like this before. I made an EventServer class and objects could use ObjectWithClass.register(Object); and when someone used triggerEvent() it would trigger the event on all objects registered.

Yea... :) But it's slightly different.

You see, the 'event' sends the current value. It then takes the value it returns.

So lets say you want to calculate the level's brightness...

brightness = plugin::getPlugin("brightness", 1 );

The plugin will go and check if any other NPCs plug in... Let's say it is in a house, and our house controller plugged in... The house controller could do return brightness - 0.6; ( thus 1 - 0.6)... Now -- If there are lamps and they plugged in too... return brightness + 0.1; ... If there are three lamps, the total brightness would be 1 - 0.6 + 0.1 + 0.1 + 0.1... Or 0.9.

Using this, you could calculate things, not merely send an event. But, obviously enough, if the value isn't important, it acts as an event.

Quote:

Originally Posted by Gambet
... you to grow so defensive ...

Gambet... You always go around doing unsupported arguments when you truly don't understand. You have been excessively offensive lately on the forums. It is of my nature to be defensive when someone offensive comes.

cbk1994 04-15-2007 02:11 PM

VERY nice, thanks for the release!

Quote:

Originally Posted by Novo (Post 1300014)
skin a cat.

I HATE YOU! :(

j/k <3

but no more skinning cats.


All times are GMT +2. The time now is 09:38 PM.

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