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

Detect if a plugin is running or not!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 07-25-2018 , 02:53   Detect if a plugin is running or not!
Reply With Quote #1

I've found this one:
https://forums.alliedmods.net/showthread.php?t=233791

Basically the solution for a plugin called "saxtonhale" is to use the following:
Code:
#include <saxtonhale>

new bool:bIsVSHRunning;

public OnAllPluginsLoaded()
{
    bIsVSHRunning = LibraryExists("saxtonhale");
}
But the plugin I am pointing at is not having a .inc-file. Is there another way to do this? Or do I have to do an .inc file for that plugin? What do I have to care about while doing this?
fragnichtnach is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 07-25-2018 , 03:12   Re: Detect if a plugin is running or not!
Reply With Quote #2

Use ServerCommandEx for sm plugins list Then use StrContains
ESK0 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-25-2018 , 03:30   Re: Detect if a plugin is running or not!
Reply With Quote #3

Quote:
Originally Posted by ESK0 View Post
Use ServerCommandEx for sm plugins list Then use StrContains
No.

https://sm.alliedmods.net/new-api/he...ndPluginByFile
or, if you're concerned about filename changes, and you know the "Name" of the plugin:
https://sm.alliedmods.net/new-api/so...PluginIterator
__________________

Last edited by ddhoward; 07-25-2018 at 03:33.
ddhoward is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 07-25-2018 , 15:42   Re: Detect if a plugin is running or not!
Reply With Quote #4

Thanks to both of you.
Choosed the second method and it seems to work.
fragnichtnach is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 07-27-2018 , 10:49   Re: Detect if a plugin is running or not!
Reply With Quote #5

Quote:
Originally Posted by ESK0 View Post
Use ServerCommandEx for sm plugins list Then use StrContains
Looks like I will try this. the solution of ddhoward isn't detecting if a plugin just failed to load.
fragnichtnach is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-27-2018 , 16:02   Re: Detect if a plugin is running or not!
Reply With Quote #6

Quote:
Originally Posted by fragnichtnach View Post
Looks like I will try this. the solution of ddhoward isn't detecting if a plugin just failed to load.
I didn't post a solution, I posted a method by which you would create your own solution.

You'd use the Handles given to you by the previously mentioned functions in this function:
https://sm.alliedmods.net/new-api/so...etPluginStatus
__________________

Last edited by ddhoward; 07-27-2018 at 16:08.
ddhoward is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-28-2018 , 07:11   Re: Detect if a plugin is running or not!
Reply With Quote #7

I highly recommend looking into the method that ddhoward brought up. Don't use ServerCommandEx to check for the plugin listed in sm plugins list output...

PHP Code:
public void OnAllPluginsLoaded()
{
    
bool bPluginExists;
    if (
FindPluginByFile("myplugin.smx") != null)
    {
        
bPluginExists true;
    }
}

void MyFunction()
{
    if (
bPluginExists)
    {
        
// Code here
    
}

About GetPluginInterator: https://forums.alliedmods.net/showpo...58&postcount=4
About FindPluginByFile: https://forums.alliedmods.net/showthread.php?t=255569
__________________
Psyk0tik is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-28-2018 , 17:25   Re: Detect if a plugin is running or not!
Reply With Quote #8

PHP Code:
bool bPluginRunning;

public 
void OnAllPluginsLoaded()
{
    
IsMyPluginRunning();
}

bool IsMyPluginRunning()
{
    
Handle hMyPlugin FindPluginByFile("myplugin.smx");
    if (
hMyPlugin != null && GetPluginStatus(hMyPlugin) == Plugin_Running)
    {
        
bPluginRunning true;
        return 
true;
    }
    else
    {
        
bPluginRunningfalse;
        return 
false;
    }
}

void MyFunction()
{
    
//do this one if you want a quick, cheap check
    
if (bPluginExists)
    {
        
// Code here
    
}

    
//do this one if you want to make sure the plugin is STILL running
    
if (IsMyPluginRunning())
    {
        
// Code here
    
}

I'd maybe do something like this.
__________________
ddhoward is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-31-2018 , 13:19   Re: Detect if a plugin is running or not!
Reply With Quote #9

Something I made.

Code:
stock bool:FindPluginByName(const String:PluginName[], bool:Sensitivity=true, bool:Contains=false)
{
	new Handle:iterator = GetPluginIterator();
	
	new Handle:PluginID;
	
	new String:curName[PLATFORM_MAX_PATH];
	
	while(MorePlugins(iterator))
	{
		PluginID = ReadPlugin(iterator)
		GetPluginInfo(PluginID, PlInfo_Name, curName, sizeof(curName));

		if(StrEqual(PluginName, curName, Sensitivity) || (Contains && StrContains(PluginName, curName, Sensitivity) != -1))
		{
			CloseHandle(iterator);
			return true;
		}
	}
	
	CloseHandle(iterator);
	return false;
}
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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 11:34.


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