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 addPlugin( pType, pName, obj, func )
{
if ( remPlugin( pType, pName ) )
{ // Removed old!
this.plugins.add( {pType, pName, obj, func } );
}
return true;
}
public function remPlugin( pType, pName )
{
for ( i = 0; i < this.plugins.size(); i ++ )
{
if ( this.plugins[i][0] != pType )
continue;
if ( this.plugins[i][1] != pName )
continue;
this.plugins.delete( i -- ); // deletes this index, next is same.
return true; // Shouldn't have two copies...
}
return true;
}
function getPlugin( pType, pDefault, pName)
{
for ( p: this.plugins )
{
if ( pType != p[0] )
continue;
if ( pName != null && pName != p[1] )
continue;
pDefault = p[2].(@ p[3] )( pDefault );
}
return pDefault;
}
function getPlugins( pType )
{
if ( pType == null )
return this.plugins;
for ( p: this.plugins )
{
if ( pType != p[0] )
continue;
temp.plugins.add( p );
}
return temp.plugins;
}