Raised This Month: $ Target: $400
 0% 

Call a function within a plugin from included file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-04-2014 , 12:32   Call a function within a plugin from included file
Reply With Quote #1

Hello there, I was wondering if it is possible to call a function in a plugin from included file. If you don't understand what I mean by that, here's an example.

myinclude.inc
PHP Code:
stock mystock()
{
       
// Do something
       
CallFuncInPlugin();

main plugin
PHP Code:
#include <amxmodx>
#include <myinclude>

public plugin_init()
{
       
register_plugin(whatever...);
       
       
mystock();
}

public 
CallFuncInPlugin()
{
       
server_print("Called!");

So, will CallFuncInPlugin() get executed after calling mystock()?

Last edited by klippy; 08-04-2014 at 12:33.
klippy is offline
bat
Veteran Member
Join Date: Jul 2012
Old 08-04-2014 , 12:38   Re: Call a function within a plugin from included file
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=41251 Same
__________________
bat is offline
Send a message via Skype™ to bat
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-04-2014 , 13:07   Re: Call a function within a plugin from included file
Reply With Quote #3

Quote:
Originally Posted by bat View Post
If I wanted to use them, I would. I just didn't want to create an .amxx file, just an include file, so I need a way to call a function from the included file. And this is more so I know if this is possible at all, just because I am curious.

Last edited by klippy; 08-04-2014 at 13:07.
klippy is offline
bat
Veteran Member
Join Date: Jul 2012
Old 08-04-2014 , 13:21   Re: Call a function within a plugin from included file
Reply With Quote #4

Try
PHP Code:
#include amxmodx
#include africanoamericano

public plugin_init(){
     
register_clcmd("say as" "justtest")
}

public 
justtest(){

   
JustTesting()

Code:
stock JustTesting(){
      server_print("HELLO WORLD")
}
__________________
bat is offline
Send a message via Skype™ to bat
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-04-2014 , 13:28   Re: Call a function within a plugin from included file
Reply With Quote #5

Quote:
Originally Posted by bat View Post
Try
PHP Code:
#include amxmodx
#include africanoamericano

public plugin_init(){
     
register_clcmd("say as" "justtest")
}

public 
justtest(){

   
JustTesting()

Code:
stock JustTesting(){
      server_print("HELLO WORLD")
}
I am sorry, but I think you don't really understand what am I willing to do. Thanks anyway. ;)
klippy is offline
bat
Veteran Member
Join Date: Jul 2012
Old 08-04-2014 , 13:32   Re: Call a function within a plugin from included file
Reply With Quote #6

Quote:
Originally Posted by KliPPy View Post
I am sorry, but I think you don't really understand what am I willing to do. Thanks anyway. ;)
You wanna with stock run a public function ?
__________________

Last edited by bat; 08-04-2014 at 13:33. Reason: edit some
bat is offline
Send a message via Skype™ to bat
PreDominance
Member
Join Date: Jul 2014
Old 08-04-2014 , 13:42   Re: Call a function within a plugin from included file
Reply With Quote #7

Why would you want to do that? An include file should never reference something that doesn't exist outside of the included file, because then you create a dependency that may not exist...this breaking the include file.
PreDominance is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-04-2014 , 13:43   Re: Call a function within a plugin from included file
Reply With Quote #8

Quote:
Originally Posted by bat View Post
You wanna with stock run a public function ?
No, not that. I actually forgot to mention that this should work like a forward. So, in my case, I want to call a function(which is in include file) which will do some sockets stuff, and call the function in main plugin that will say "Hey, I got a socket response, do some stuff!". If this is not possible(without any other sorcery than just simply calling functions), then what is the easiest way to register one forward for a calling plugin? Keep in mind, everything is done in include file, there is no plugin creating all the natives or such.

Last edited by klippy; 08-04-2014 at 13:44.
klippy is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 08-04-2014 , 14:15   Re: Call a function within a plugin from included file
Reply With Quote #9

In order to do that you have to register native in main plugin.
example
PHP Code:
register_native"test_thing""func_test")

public 
test_thing(param)
{


Now write inside of your .inc file:
PHP Code:
native test_thing(param)
stock do_something()
{
    
test_thing(5)

And no matter where you use your inc, main plugin test_thing func get called and param = 5.
Includes work exactly the same way as the rest of the things.

You can put public functions in inc. You can hook forwards like plugin_init in .inc, you can do anything.
.Dare Devil. is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-04-2014 , 14:21   Re: Call a function within a plugin from included file
Reply With Quote #10

As I said, there is no plugin interaction! All the functions are just found in one file(include file), so you don't have to put another plugin on server to get some functionality, all it takes is to include one file in you plugin which contains all of the functions, that's my goal. It all works perfectly, all it is left to do is to make forward functionality(calling a plugin function from inside the include file). I guess the best thing would be to create a forward with CreateOneForward().
klippy 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 16:45.


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