Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-14-2007, 08:07 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
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;
  } 
Reply With Quote
  #2  
Old 04-14-2007, 09:11 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I'm confused as to how this could be used...
__________________
Reply With Quote
  #3  
Old 04-14-2007, 09:20 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by Inverness View Post
I'm confused as to how this could be used...
Same here...
Reply With Quote
  #4  
Old 04-14-2007, 10:13 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Inverness View Post
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.
Reply With Quote
  #5  
Old 04-14-2007, 11:32 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Novo View Post
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.
Reply With Quote
  #6  
Old 04-14-2007, 11:54 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
What isn't there to understand? Novo has excelled himself again! Nice work
Reply With Quote
  #7  
Old 04-15-2007, 12:05 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Gambet View Post
What? Couldn't you use scheduleevent to catch events?


I don't really understand the point of this.
scheduleevent and catch event are two DIFFERENT things.
Reply With Quote
  #8  
Old 04-15-2007, 12:09 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Novo View Post
scheduleevent and catch event are two DIFFERENT things.

Yes, but there is a catchevent function already, though.
Reply With Quote
  #9  
Old 04-15-2007, 12:54 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Gambet View Post
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.
Reply With Quote
  #10  
Old 04-15-2007, 01:34 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Looks interesting Novo!
__________________
Reply With Quote
  #11  
Old 04-15-2007, 02:01 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Novo View Post
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.
Reply With Quote
  #12  
Old 04-15-2007, 02:03 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
Reply With Quote
  #13  
Old 04-15-2007, 02:35 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Inverness View Post
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.
Reply With Quote
  #14  
Old 04-15-2007, 02:11 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
VERY nice, thanks for the release!

Quote:
Originally Posted by Novo View Post
skin a cat.
I HATE YOU!

j/k <3

but no more skinning cats.
__________________
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 07:45 PM.


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