AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Plugin won't load, doesn't appear in sm plugins. (https://forums.alliedmods.net/showthread.php?t=322054)

LordHotPocketHomicide 03-14-2020 00:33

Plugin won't load, doesn't appear in sm plugins.
 
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;
}


Silvers 03-14-2020 01:49

Re: Plugin won't load, doesn't appear in sm plugins.
 
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

LordHotPocketHomicide 03-14-2020 13:47

Re: Plugin won't load, doesn't appear in sm plugins.
 
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!

Silvers 03-14-2020 13:52

Re: Plugin won't load, doesn't appear in sm plugins.
 
Glad to hear it, happy scripting!

Dragokas 03-14-2020 15:00

Re: Plugin won't load, doesn't appear in sm plugins.
 
Includes are not required to be unploaded on server.


All times are GMT -4. The time now is 00:21.

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