Raised This Month: $433 Target: $400
 108% 

Solved Plugin won't load, doesn't appear in sm plugins.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LordHotPocketHomicide
Member
Join Date: Aug 2016
Location: Some VSH Map
Old 03-14-2020 , 00:33   Plugin won't load, doesn't appear in sm plugins.
Reply With Quote #1

Hello! I've (very) recently gotten into writing plugins, largely thanks to a friend of mine who generously agreed to teach me some of the basics, and even showed me to some incredibly useful resources such as the API reference. My end goal is to be able to write FF2 sub-plugins, though that's a story for another time.

The problem I'm currently having is as such: for some odd reason, this plugin, and this plugin alone, won't load on my test server, and it doesn't appear in the sm plugins menu. Just to make sure it wasn't an issue on the server's end, I wrote up a quick test program, which worked perfectly fine, so I wound up concluding that the issue is somewhere in my code. I've tried sm plugins load, I've restarted my server several times, and I've re-written my code in various ways, all to no avail, so I eventually wound up coming here for support. If somebody could point out what I did wrong, I would greatly appreciate it! Thanks in advance.

Code:
#include <sourcemod>
#include <tf2.inc>
#include <tf2_stocks.inc>
#include <tf2attributes.inc>
#include <sdkhooks.inc>
#include <clients.inc>

public Plugin myinfo =
{
	name		=	"TF2 Chaos Mod",
	description	=	"Applies a random perk to players when they call for medic. Future plans include applying a random perk whenever a player inputs anything, with no cooldown whatsoever.",
	author		=	"Lord ''Spookmaster'' Homicide",
	version		=	"0.5",
};
public OnPluginStart()
{
	HookEvent("teamplay_round_start", Event_InitiateChaos);
}
public Action Event_InitiateChaos(Event chaos, const char[] sEvName, bool bDontBroadcast)
{
	AddCommandListener(playerCalledForMedic, "voicemenu 0 0");
	return Plugin_Continue;
}

bool cooldownCheck = false; //Global variable. From what I know, these should typically be avoided, but my limited SourcePawn knowledge makes it hard to find a work-around for the time being.

public Action playerCalledForMedic(int client, const char[] voicemenu, int argc)
{
	if (!cooldownCheck)
	{
		if (!IsClientConnected(client) || !IsPlayerAlive(client))
		{
			return Plugin_Handled;
		}
		int perkSelector = GetRandomInt(0, 128);
		TF2_AddCondition(client, perkSelector, 5.0, 0);
		PrintToChatAll("%N just got a perk!", GetClientOfUserId(client));
		cooldownCheck = true;
		CreateTimer(5.0, cooldownReset);
	}
	else
	{
		PrintToChat(client, "Oops! You've gained a perk too recently. Try again in a few seconds.");
	}
	return Plugin_Continue;
}
public Action cooldownReset(Handle timer)
{
	cooldownCheck = false;
	return Plugin_Changed;
}

Last edited by LordHotPocketHomicide; 03-14-2020 at 13:47.
LordHotPocketHomicide is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 03-14-2020 , 01:49   Re: Plugin won't load, doesn't appear in sm plugins.
Reply With Quote #2

The "AddCommandListener" part should be put into "OnPluginStart" instead of hooking the event and adding there otherwise everytime that event fires (changing map etc) it will hook again and cause duplicate timers etc.

Theres nothing wrong with global variables, who recommends against that? They only take up a bit of RAM memory which really doesn't matter for these old games where servers probably have plenty excess memory available.

I suggest swapping "IsClientConnected" with "IsClientInGame" the latter checks the former. "IsClientConnected" is really only needed when you're checking that a clients connected but not yet in-game, for some operations this is useful but for most you want to make sure the client is ingame.

Aside from that I don't see anything wrong. I would suggest removing some of the #include lines because I doubt they are all required, if the plugin fails to compile then reinstate the line because some functions are obviously required from it.

You can also omit ".inc" from the include paths, this is assumed without specifying the extension.

Are you sure you copied the .smx to the server (I ask because this is a common silly mistake we've all made), and did you run "sm plugins refresh" and did that produce any errors while attempting to load your plugin? Otherwise it should be in "sm plugins list" (run from the server console or you don't get a full list because you have to write "sm plugins list 11" or whatever from clients to see the various pages of plugins. Changing map will also load any new plugins not yet loaded.

Shameless plug but I think it should help overall: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
__________________

Last edited by Silvers; 03-14-2020 at 01:53.
Silvers is offline
LordHotPocketHomicide
Member
Join Date: Aug 2016
Location: Some VSH Map
Old 03-14-2020 , 13:47   Re: Plugin won't load, doesn't appear in sm plugins.
Reply With Quote #3

Thank you, Silvers! As it turns out, the main problem was one of my includes, which for some odd reason wasn't even on my server lol. I also greatly appreciate your optimization pointers, as well as the tutorial you wrote and linked, which I will 100% be using in the future. Thanks again!
__________________
Most of my bosses are OCs. Whether or not you like them is up to you, but if you donít, feel free to explain why so that I can improve in the future. IMO, thereís no fun in making a boss that isnít even your own creation; at that point, itís just mindless work for some other dude/dudette.
LordHotPocketHomicide is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 03-14-2020 , 13:52   Re: Plugin won't load, doesn't appear in sm plugins.
Reply With Quote #4

Glad to hear it, happy scripting!
__________________
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 03-14-2020 , 15:00   Re: Plugin won't load, doesn't appear in sm plugins.
Reply With Quote #5

Includes are not required to be unploaded on server.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D1 fun (Bloody Witch)
[My plugins] [My tools] [GitHub] [Articles]
Dragokas is offline
Reply


Thread Tools
Display Modes

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 12:50.


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