Raised This Month: $ Target: $400
 0% 

[CS:GO] PrivateForward vs. GlobalForward


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Screeaam..
Senior Member
Join Date: Jun 2010
Location: Poland
Old 06-08-2014 , 13:43   [CS:GO] Private Forward
Reply With Quote #1

Hello! I'm trying to make Private Forwards for my plugins:

Code:
public OnPluginStart()
{	
	g_ClassState = CreateForward(ET_Event, Param_Cell, Param_Cell)
}

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
	CreateNative("DB_ClassChangeState", Native_DB_ChangeStateClass);
	return APLRes_Success;
}

public Native_DB_ChangeStateClass(Handle:plugin, numParams)
{
	AddToForward(g_ClassState, plugin, Function:GetNativeCell(1));
}

public db_SetClass(client)
{
	Call_StartForward(g_ClassState);
	Call_PushCell(client);
	Call_PushCell(gClass[client]);
	Call_Finish();
}
And second plugin with initialize that forward:

Code:
functag DB_ClassChangeStateFunc Action:public(client, class);
native DB_ClassChangeState(DB_ClassChangeStateFunc:func);

public DB_ClassChangeState(client, class)
{
	if(class == 1)
		PrintToChat(client, "Class one!");
	else
		PrintToChat(client, "Class two!");
}

Function db_SetClass(client) is running when player picks class..

Second plugin won't compile... http://screenshooter.net/99997328/hahoxwo Where is mistake?

Last edited by Screeaam..; 06-08-2014 at 13:46.
Screeaam.. is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-08-2014 , 13:56   Re: [CS:GO] Private Forward
Reply With Quote #2

When typing "native DB_ClassChangeState(DB_ClassChangeStateFunc:f unc);"

You're saying "a function named 'DB_ClassChangeState' exist and can be called (it is the equivalent of a "forward declaration" in C, at least in my mind).

Then you're declaring a function with the same name --> name clash --> can't compile, which is what the compiler told you...

[...](4) : error 021: symbol already defined: "DB_ClassChangeState"

edit : and yeah as P-P-P-P-P-owerLord said, you're also missing a return, since you're saying you have an "Action" function, this mean you should return an "Action" value.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 06-08-2014 at 14:00.
RedSword is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-08-2014 , 13:56   Re: [CS:GO] Private Forward
Reply With Quote #3

  1. You have a native and public function defined with the same name, which is causing a name conflict. Rename the public function to something else.
  2. The public function is missing the Action return type and thus doesn't match the functag.
  3. Your function hasn't registered the other plugin as a dependency. This is usually done by writing an include file for the plugin whose natives you want to use. Example.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Screeaam..
Senior Member
Join Date: Jun 2010
Location: Poland
Old 06-08-2014 , 14:17   Re: [CS:GO] Private Forward
Reply With Quote #4

Can You show me how it should be? I can't understand this. :/

In AMXX it was simply not like this..

EDIT:

I've got this..

Code:
functag DB_ChangeStateClassFunc Action:public(client, class);
native DB_ClassChangeState(DB_ChangeStateClassFunc:func);
Code:
public Action:DB_ClassChangeState(client, class)
{
	if(class == 1)
		PrintToChat(client, "One!");
	else
		PrintToChat(client, "Two!");
		
	return 1;
}
What should be in return? And still errors...

http://screenshooter.net/99997328/mfijdhb

Last edited by Screeaam..; 06-08-2014 at 16:17.
Screeaam.. is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-08-2014 , 22:15   Re: [CS:GO] Private Forward
Reply With Quote #5

I found SM to be simpler than AMXX.

Quote:
What should be in return?
Code:
enum Action
{
	Plugin_Continue = 0,	/**< Continue with the original action */
	Plugin_Changed = 1,		/**< Inputs or outputs have been overridden with new values */
	Plugin_Handled = 3,		/**< Handle the action at the end (don't call it) */
	Plugin_Stop = 4,		/**< Immediately stop the hook chain and handle the original */
};
Taken from core.inc

And there is a tutorial about private forwards on the wiki : https://wiki.alliedmods.net/Function...ivate_Forwards
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 06-09-2014 at 14:41. Reason: typo D:
RedSword is offline
Screeaam..
Senior Member
Join Date: Jun 2010
Location: Poland
Old 06-09-2014 , 10:33   [CS:GO] PrivateForward vs. GlobalForward
Reply With Quote #6

Hello, I have plugins that requires forwards.. And which forward will be better?

Better will be when I use GlobalForwards or PrivateForwards? What's the difference?
Screeaam.. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-09-2014 , 11:36   Re: [CS:GO] Private Forward
Reply With Quote #7

Are you sure you want this registered as an ET_Event type forward? If you're not expecting a return value, just make it an ET_Ignore forward and remove the Action: return type from its functag.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-09-2014 at 11:37.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-09-2014 , 11:46   Re: [CS:GO] PrivateForward vs. GlobalForward
Reply With Quote #8

I'll be using examples from SDKHooks here.

A global forward registers a name globally that any plugin can implement. They are specified via the "forward" key-word in a plugin's include file and registered in your plugin that owns the Forward via CreateGlobalForward.
An example of a global forward is SDKHooks public OnEntityCreated(entity, const String:classname[]) , which is called on any plugin that makes a public function with that name and signature.

A private forward requires a plugin to manually register with you plugin to be added to the forward. You can manage the forward list manually in this situation. You create them in your plugin using CreateForward. You will also need to create a functag or funcenum (multiple functags that can be used for the same function) to specify what the function should look like that other plugins register for your forward.
An example of a private forward is the SDKHooks system... any SDKHook you register with the SDKHook function is a private forward and the function you pass to it has to match one of the function signatures in the SDKHookCB funcenum.

A funcenum is just several functags that can be used for the same function.

Note: SDKHooks is an extension, but extensions can also register forwards for plugins to use. In fact, you rarely run into funcenums for plugins, only for extensions.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-09-2014 at 11:53.
Powerlord is offline
Screeaam..
Senior Member
Join Date: Jun 2010
Location: Poland
Old 06-09-2014 , 12:12   Re: [CS:GO] PrivateForward vs. GlobalForward
Reply With Quote #9

Thanks! Which should I use to gain greater optimization?
Screeaam.. is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-12-2014 , 00:31   Re: [CS:GO] PrivateForward vs. GlobalForward
Reply With Quote #10

Since no one replied, I won't answer directly. But know that when using a forward, if the forward callback is in another plugin, there will be a context switch (n+1 I'd guess); so the cost is - I'd guess - far from over a simple variable affectation. I've seen, however, war3 servers with 200+ plugins (war3 has a forwards; i.e. to calculate damage) run fine; meaning you shouldn't be worried about that.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword 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 09:40.


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