Raised This Month: $ Target: $400
 0% 

CreateMultiForward questions.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PreDominance
Member
Join Date: Jul 2014
Old 08-14-2014 , 01:49   CreateMultiForward questions.
Reply With Quote #1

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?

Last edited by PreDominance; 08-14-2014 at 02:15.
PreDominance is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-14-2014 , 06:49   Re: CreateMultiForward questions.
Reply With Quote #2

It is perfectly fine not to have it in your plugin.
klippy is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 08-14-2014 , 08:37   Re: CreateMultiForward questions.
Reply With Quote #3

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.
__________________
In Flames we trust!
Nextra is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-14-2014 , 15:21   Re: CreateMultiForward questions.
Reply With Quote #4

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.
__________________

Last edited by fysiks; 08-14-2014 at 15:21.
fysiks is offline
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 -4. The time now is 13:05.


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