Raised This Month: $51 Target: $400
 12% 

Modular plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AceNice
New Member
Join Date: Aug 2019
Old 08-10-2019 , 07:08   Modular plugin
Reply With Quote #1

Hi!
I have plugin with next structure:
main_plugin
child_plugin
child_plugin2
And i need to follow function OnVipMenuCreated from main plugin in child plugins.
Global forward gives an error: OnVipMenuCreated already defined
How can i make it?

Sorry for bad english
AceNice is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 08-10-2019 , 12:58   Re: Modular plugin
Reply With Quote #2

https://wiki.alliedmods.net/Creating...Mod_Scripting)

also it would be nice to provide us some code
__________________

Last edited by Fyren; 08-13-2019 at 16:08. Reason: fix link
kratoss1812 is offline
AceNice
New Member
Join Date: Aug 2019
Old 08-10-2019 , 16:21   Re: Modular plugin
Reply With Quote #3

Quote:
Originally Posted by kratoss1812 View Post
https://wiki.alliedmods.net/Creating...eMod_Scripting)

also it would be nice to provide us some code
Sure.

This is main plugin:
Code:
#include "gf_effects.sp"
#include "gf_revive.sp"

Handle forward_OnVipMenuCreated;

public OnPluginStart() {
	forward_OnVipMenuCreated = CreateGlobalForward("OnVipMenuCreated", ET_Ignore, Param_Cell, Param_Cell);
}


public Action VipMenu(int client, int args) {

	int playerLevel = global_playerLvl[client];
	PrepareOnMenuForward(client, playerLvl);
	
}
void PrepareOnMenuForward(int playerID, int playerLvl) {
	Call_StartForward(forward_OnVipMenuCreated);
	Call_PushCell(playerID);
	Call_PushCell(playerLvl);
	Call_Finish();
}
First child plugin gf_effects
Code:
public OnVipMenuCreated(int playerID, int playerLvl) {
	*some code*
}
And second child plugin gf_revive
Code:
public OnVipMenuCreated(int playerID, int playerLvl) {
	*some code*
}
AceNice is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-13-2019 , 16:19   Re: Modular plugin
Reply With Quote #4

#include is basically the same as copying and pasting. Your example code is one plugin, just split up into multiple files. That's why you're getting an error about defining the same function multiple times.

If you actually make them separate plugins, you can use a global forward like in the code you gave. You'll probably have to make natives (like in the article linked by the previous reply) since you can't directly call another plugin's functions.

The simplest change would be to give them different names like OnVipMenuEffects and OnVipMenuRevive and manually call them instead of using a forward. If you add new files, you'll have to remember to update the functions you call.

Another way is to use a private forward (see https://wiki.alliedmods.net/Function...Mod_Scripting)) to have each file register its own callbacks. This isn't very different from the previous suggestion, though, since you'll still have to manually do that registration/call some initialization function per file.
Fyren is offline
AceNice
New Member
Join Date: Aug 2019
Old 08-14-2019 , 03:41   Re: Modular plugin
Reply With Quote #5

Quote:
Originally Posted by Fyren View Post
#include is basically the same as copying and pasting. Your example code is one plugin, just split up into multiple files. That's why you're getting an error about defining the same function multiple times.

If you actually make them separate plugins, you can use a global forward like in the code you gave. You'll probably have to make natives (like in the article linked by the previous reply) since you can't directly call another plugin's functions.

The simplest change would be to give them different names like OnVipMenuEffects and OnVipMenuRevive and manually call them instead of using a forward. If you add new files, you'll have to remember to update the functions you call.

Another way is to use a private forward (see https://wiki.alliedmods.net/Function...Mod_Scripting)) to have each file register its own callbacks. This isn't very different from the previous suggestion, though, since you'll still have to manually do that registration/call some initialization function per file.

Thank you! I'm already using different names and write them names into array. Then when i need, i using this array to calling the functions

Code:
char global_menucalls[][] = {
	{"Vip_ReviveRowAction"},
	{"Vip_EffectsRowAction"}
};

int VipMenu_Handler(Menu vipMenu, MenuAction action, int param1, int param2) {	
	if (action == MenuAction_Select) {
		char selectedPos[32];
		GetMenuItem(vipMenu, param2, selectedPos, sizeof(selectedPos));
		
		if(strcmp(selectedPos, "trade", false) == 0) {
			Menu_SelectPlayer(param1);
		}
		
		for (int i = 0; i < sizeof(global_menucalls); i++) {
			
			Function func = GetFunctionByName(INVALID_HANDLE, global_menucalls[i][0]);
			Call_StartFunction(null, func);
			Call_PushCell(vipMenu);
			Call_PushCell(action);
			Call_PushCell(param1);
			Call_PushCell(param2);
			Call_PushCell(global_playerLvl[param1]);
			Call_Finish();
		}
	}
	
	if (action == MenuAction_End) {
		delete vipMenu;
	}
}
AceNice 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 14:12.


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