Raised This Month: $32 Target: $400
 8% 

callfunc_begin vs Multiforward which is better?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 05-26-2021 , 04:08   callfunc_begin vs Multiforward which is better?
Reply With Quote #1

I used MultiForward for my Weapon Menu System and notice some time it cause crash on server or really huge lag spike if a lot of player try to buy weapons at the same time.

I thought it was because of it have to go though 20+ plugins using that forward and executed too many time (3 execute per player in < 1 second + chance of 10+ players press buy and execute at short period of time)

So did some research and found callfunc_begin function which directly call function from specific plugins. With PluginID and FunctionID can be sent via "Weapon Register Native"(like ZP Class Register), in theory, it would be great for Weapon Menu System.

But still, it is my own assumption. I am not sure which one is better to use in this situation so I want to hear veteran opinion on this.

P/S: Some said that callfunc_begin is basically native so why not use native?
- Between replacing 2 parameters getting from Info Param of the menu item and have to create a .inc file, register_native, making a switch between menu item that lead to each native for each specific weapon? the first one definitely cleaner.
__________________
My plugin:
Celena Luna is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-26-2021 , 07:59   Re: callfunc_begin vs Multiforward which is better?
Reply With Quote #2

Quote:
Originally Posted by Celena Luna View Post
I used MultiForward for my Weapon Menu System and notice some time it cause crash on server or really huge lag spike if a lot of player try to buy weapons at the same time.

I thought it was because of it have to go though 20+ plugins using that forward and executed too many time (3 execute per player in < 1 second + chance of 10+ players press buy and execute at short period of time)
I assume it has some parameters, so it doesn't matter, it is called with different parameters, every time, per player, or per action, client_putinserver it's a forward too.
It doesn't matter if it's called in 1 plugin, 10 plugins and so on, it's executed once by a module or a plugin, so, passed params will be the same for every plugin in that moment.


Quote:
Originally Posted by Celena Luna View Post
So did some research and found callfunc_begin function which directly call function from specific plugins. With PluginID and FunctionID can be sent via "Weapon Register Native"(like ZP Class Register), in theory, it would be great for Weapon Menu System.

But still, it is my own assumption. I am not sure which one is better to use in this situation so I want to hear veteran opinion on this.

P/S: Some said that callfunc_begin is basically native so why not use native?
- Between replacing 2 parameters getting from Info Param of the menu item and have to create a .inc file, register_native, making a switch between menu item that lead to each native for each specific weapon? the first one definitely cleaner.
You should use a direct native, because it's faster to acces the native directly through a function than using a native to search for a function in certain plugin. it is not mandatory to create a include file, you can declare that you are using a native or forward in header's plugin ( this only if you're not registering a custom library ).

This code:
PHP Code:
/* Sublime AMXX Editor v4.2 */

#include <amxmodx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0.0-1"
#define AUTHOR  "Author"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

does the same thing like this code:
PHP Code:
/* Sublime AMXX Editor v4.2 */

// Not included the library
//#include <amxmodx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0.0-1"
#define AUTHOR  "Author"

forward plugin_init()
native register_plugin(const plugin_name[], const version[], const author[])

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 05-27-2021 , 00:52   Re: callfunc_begin vs Multiforward which is better?
Reply With Quote #3

Quote:
Originally Posted by Shadows Adi View Post
I assume it has some parameters, so it doesn't matter, it is called with different parameters, every time, per player, or per action, client_putinserver it's a forward too.
It doesn't matter if it's called in 1 plugin, 10 plugins and so on, it's executed once by a module or a plugin, so, passed params will be the same for every plugin in that moment.
Some said to me that using MultiForward with have 2 check:
- Check if the plugins have a the forward
- Check the weaponid according to parameter sent

While using callfunc only need to check weaponid only.

Which argued with him that "is 1 or 2 check really that matter? While something like takedamage even have to check class, team,... at the same time"

He said that it was not about more or less if, it is about the performance. If you could reduced any useless "if" then it would boost the performance specially on something like Pawn.
That why every Zombie server was lagged, he said

The weapon system I wrote was similar to the Extra Item from ZP


Quote:
Originally Posted by Shadows Adi View Post
You should use a direct native, because it's faster to acces the native directly through a function than using a native to search for a function in certain plugin. it is not mandatory to create a include file, you can declare that you are using a native or forward in header's plugin ( this only if you're not registering a custom library ).
If there are multiple plugins register the same native, will it call all of them?
__________________
My plugin:

Last edited by Celena Luna; 05-27-2021 at 03:51.
Celena Luna is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-27-2021 , 08:35   Re: callfunc_begin vs Multiforward which is better?
Reply With Quote #4

Quote:
Originally Posted by Celena Luna View Post
If there are multiple plugins register the same native, will it call all of them?
So, a native is unique, it is registered only once and . It won't be a problem if is used by multiple plugins, because it will pass same parameters in that point, but I would recommend you to use a MultiForward, because it will be easier for getting the params needed when it is executed.

The natives have 2 checks too:
- if the given native exists
- parameters passed through function.

You can perform a profile to see how much times a function is being called.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi 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 05:54.


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