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

Only load plugin once?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-17-2015 , 12:02   Only load plugin once?
Reply With Quote #1

This is sort of a problem I'm facing. I want to make sure that a plugin can not be run twice concomitantly.

How would I do this? Can I make the plugin create a variable or something, and check in plugin_init if that variable exists or not? If exists then set fail state?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 05-17-2015 , 12:18   Re: Only load plugin once?
Reply With Quote #2

see xvars

Last edited by FromTheFuture; 05-17-2015 at 12:18.
FromTheFuture is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-17-2015 , 12:29   Re: Only load plugin once?
Reply With Quote #3

Quote:
Originally Posted by FromTheFuture View Post
see xvars
thanks bruh

edit::
I tried doing it like this, but both plugins still run.
PHP Code:
public iamrunning
public plugin_init()
{
    new 
g_piamrunning get_xvar_id"iamrunning" );
    
// check if the XVar is valid
    
if( g_piamrunning == )
    {
        
set_fail_state"There is an instance of this plugin already running!" );
    }
    else
    {
        
iamrunning=1
    

__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 05-17-2015 at 12:38.
aron9forever is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-17-2015 , 13:26   Re: Only load plugin once?
Reply With Quote #4

How are you getting it to run twice? Do they have different names?

It might be something you have to leave to the end-user.
__________________
fysiks is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-17-2015 , 13:38   Re: Only load plugin once?
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
How are you getting it to run twice? Do they have different names?

It might be something you have to leave to the end-user.
yes, renaming binary and writing both inside plugins.ini

the thing is I would like to leave it up to the user but the truth is many of them are too dumb to do it by themselves

the plugin that needs this addition must be on top of the plugins.ini list to avoid conflicts
because of so many people contacting me with problems then figuring out "they thought that meant on top but under the default plugins" and other crap like that, I made the plugin place itself on top automatically.

Now I need to deal with people who renamed the binary, since the script I wrote to place itself on top only removes the default name from the list, after placing itself on 1st line



If this can not be done, then I will just leave it as is, but I think this should work with simple cvars instead of xvars.

Can you please tell me what happens when you try to get the value of a cvar that does not exist? Or is there a way to check if a cvar is registered?
I'm thinking of doing this inside plugin_init():
check cvar,
if it exists then set fail state
else register cvar
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-17-2015 , 13:42   Re: Only load plugin once?
Reply With Quote #6

You can check for the existence of a cvar with get_cvar_pointer(). If non-zero, it exists.
__________________
fysiks is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-17-2015 , 13:53   Re: Only load plugin once?
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
You can check for the existence of a cvar with get_cvar_pointer(). If non-zero, it exists.
so it's working properly but now I ran into another issue (this is funny as hell)
it seems that calling set_fail_state from plugin #2 will stop both #2 and #1 since they're the same plugin
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-17-2015 , 13:56   Re: Only load plugin once?
Reply With Quote #8

Quote:
Originally Posted by aron9forever View Post
so it's working properly but now I ran into another issue (this is funny as hell)
it seems that calling set_fail_state from plugin #2 will stop both #2 and #1 since they're the same plugin
Interesting.
__________________
fysiks is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-17-2015 , 13:58   Re: Only load plugin once?
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
Interesting.
can a plugin somehow get it's own filename?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 05-17-2015 , 14:04   Re: Only load plugin once?
Reply With Quote #10

Has cvar_exists native, try it.
FromTheFuture 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 19:29.


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