Thread: Plugin class
View Single Post
  #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