AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CreateMultiForward questions. (https://forums.alliedmods.net/showthread.php?t=246226)

PreDominance 08-14-2014 01:49

CreateMultiForward questions.
 
Greetings,

I'm looking into making my Warcraft plugin more of an API style (after being told, quite literally, that using callfunc was shit), where each race is an entirely new plugin.

Each race needs to have several event-based actions. Many races will contain code that needs to be executed on a spawn event, for instance.

In order to execute a public function in every plugin at once (a function called, for instance, "event_spawn"), can I do something like...
neowarcraft.sma
PHP Code:

new spawnEvent;

public 
plugin_init()
{
    
register_plugin("MF Test""1.0""PreDominance");
    
RegisterHam("Ham_Spawn""player""event_spawn""1");
    
spawnEvent CreateMultiForward("event_spawn"ET_IGNOREFP_CELL);
}

public 
event_spawn(id
{
    new 
ret;
    if (!
ExecuteForward(spawnEventretid))
        return 
log_amx("Spawn forward execute error.");
    return 
ret;
}

public 
plugin_end()
{
    
DestroyForward(spawnEvent);


Undead Scourge.sma
PHP Code:

public plugin_init()
{
    
register_plugin("Race: Undead Scourge""1.0""PreDominance");
}

public 
event_spawn(id)
{
    
//Stuff
    
return PLUGIN_CONTINUE;


My next question is, what happens to those plugins that do not have a public event_spawn (i.e. races that do not need a spawn event)? That's fine to not have, right?

klippy 08-14-2014 06:49

Re: CreateMultiForward questions.
 
It is perfectly fine not to have it in your plugin.

Nextra 08-14-2014 08:37

Re: CreateMultiForward questions.
 
If you need to use byref parameters you have to resort to callfuncs, they have a purpose. Otherwise OneForwards are better, and MultiForwards certainly are better than callfuncs if your use case allows for them to be used. With OneForwards and especially MultiForwards the AMXX core does more and more work that your plugin can't do as efficiently with callfuncs.

fysiks 08-14-2014 15:21

Re: CreateMultiForward questions.
 
The only good use that I've seen for callfunc is when you don't have control over the plugin for which you are making your plugin compatible. So, for example, the original gungame by Avalanche required their use because he had no control over the map chooser plugins that might be used on the servers that are trying to run GunGame.

There are probably other good uses but in your case, you shouldn't be using them.


All times are GMT -4. The time now is 13:05.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.