AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Show keys, doesn't show correctly (https://forums.alliedmods.net/showthread.php?t=85838)

refused 02-16-2009 20:27

Show keys, doesn't show correctly
 
Hi

I found this code in a old topic, however, it doesn't works correctly.
It shows the keys in wrong timing, could anyone check it out since I'm completely worthless at scipting.

Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define ADMIN_SPECHIDE    ADMIN_KICK

new g_HudSyncObj_List;
new g_HudSyncObj_Keys1;
new g_HudSyncObj_Keys2;
new bool:g_bSpecList[33];
new bool:g_bSpecKeys[33];
new bool:g_bSpecHide[33];

new bool:g_bConnected[33];
new bool:g_bAlive[33];
new bool:g_bBot[33];

new g_Keys[33];

new Float:g_fKeysDelay;

new g_MaxPlayers;

new const g_sKeys[6][] =
{
    "W",
    "A",
    "D",
    "S",
    "Duck",
    "Jump"
};
new const g_Buttons[6] =
{
    IN_FORWARD,
    IN_MOVELEFT,
    IN_MOVERIGHT,
    IN_BACK,
    IN_DUCK,
    IN_JUMP
};

public plugin_init()
{
    register_plugin("Spectator List", "0.1", "Exolent");
   
    register_clcmd("say", "clcmd_Say", -1, "");
    register_clcmd("say_team", "clcmd_Say", -1, "");
   
    register_forward(FM_PlayerPreThink, "fwd_FM_PlayerPreThink_pre", 0);
   
    RegisterHam(Ham_Spawn, "player", "fwd_Ham_Spawn_post", 1);
    RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_pre", 0);
   
    g_HudSyncObj_List = CreateHudSyncObj(0);
    g_HudSyncObj_Keys1 = CreateHudSyncObj(0);
    g_HudSyncObj_Keys2 = CreateHudSyncObj(0);
   
    g_MaxPlayers = get_maxplayers();
   
    return PLUGIN_CONTINUE;
}

public plugin_cfg()
{
    set_task(1.0, "task_SpectatorList", 0, "", 0, "b", 0);
    set_task(0.1, "task_SpectatorKeys", 0, "", 0, "b", 0);
   
    return PLUGIN_CONTINUE;
}

public client_connect(plr)
{
    g_bSpecList[plr] = true;
    g_bSpecKeys[plr] = true;
    g_bSpecHide[plr] = false;
   
    return PLUGIN_CONTINUE;
}

public client_putinserver(plr)
{
    g_bConnected[plr] = true;
    g_bBot[plr] = bool:is_user_bot(plr);
   
    return PLUGIN_CONTINUE;
}

public client_disconnect(plr)
{
    g_bConnected[plr] = false;
    g_bAlive[plr] = false;
   
    return PLUGIN_CONTINUE;
}

public clcmd_Say(id)
{
    static sMessage[192];
    read_args(sMessage, 191);
    remove_quotes(sMessage);
    if(equali(sMessage, "/speclist"))
    {
        g_bSpecList[id] = !g_bSpecList[id];
        client_print(id, print_chat, "[SPECLIST] You have turned o%s the spectator list.", g_bSpecList[id] ? "n" : "ff");
        return PLUGIN_HANDLED;
    }
    if(equali(sMessage, "/speckeys"))
    {
        g_bSpecKeys[id] = !g_bSpecKeys[id];
        client_print(id, print_chat, "[SPECLIST] You have turned o%s the spectator keys.", g_bSpecKeys[id] ? "n" : "ff");
        return PLUGIN_HANDLED;
    }
    if(equali(sMessage, "/spechide"))
    {
        if(get_user_flags(id) & ADMIN_SPECHIDE)
        {
            g_bSpecHide[id] = !g_bSpecHide[id];
            client_print(id, print_chat, "[SPECLIST] You have turned o%s spectator list hiding.", g_bSpecHide[id] ? "n" : "ff");
        }
        else
        {
            client_print(id, print_chat, "[SPECLIST] You have no access to spectator list hiding.");
        }
        return PLUGIN_HANDLED;
    }
    return PLUGIN_CONTINUE;
}

public fwd_Ham_Spawn_post(plr)
{
    if(is_user_alive(plr))
    {
        g_bAlive[plr] = true;
       
        return HAM_HANDLED;
    }
   
    return HAM_IGNORED;
}

public fwd_Ham_Killed_pre(plr, attacker, shouldgib)
{
    g_bAlive[plr] = false;
   
    return HAM_IGNORED;
}

public fwd_FM_PlayerPreThink_pre(plr)
{
    if(get_gametime() >= g_fKeysDelay && g_bAlive[plr])
    {
        g_Keys[plr] = 0;
       
        static button, i, temp;
        button = pev(plr, pev_button);
        for(i = 0; i < 6; i++)
        {
            temp = g_Buttons[i];
            if(button & temp)
            {
                g_Keys[plr] |= temp;
            }
        }
       
        return FMRES_HANDLED;
    }
   
    return FMRES_IGNORED;
}

public task_SpectatorKeys()
{
    for(new plr = 1; plr <= g_MaxPlayers; plr++)
    {
        if(!g_bConnected[plr])
        {
            continue;
        }
       
        static spec[33], id;
        for(id = 1; id <= g_MaxPlayers; id++)
        {
            if(g_bConnected[id] && !g_bAlive[id])
            {
                spec[id] = pev(id, pev_iuser2);
            }
        }
       
        static sMsg[6][16], i;
        for(i = 0; i < 6; i++)
        {
            if(g_Keys[plr] & g_Buttons[i])
            {
                copy(sMsg[i], 15, g_sKeys[i]);
            }
            else if(i > 3)
            {
                copy(sMsg[i], 15, "^n^n");
            }
            else
            {
                copy(sMsg[i], 15, "^t^t");
            }
           
            for(id = 1; id <= g_MaxPlayers; id++)
            {
                if(!g_bConnected[id] || g_bAlive[id] || g_bBot[id] || !g_bSpecKeys[id])
                {
                    continue;
                }
               
                if(spec[id] == plr)
                {
                    set_hudmessage(100, 100, 100, -1.0, -1.0, 0, 0.0, 0.3, 0.0, 0.0, -1);
                    ShowSyncHudMsg(id, g_HudSyncObj_Keys1,\
                        "%s^n^n%s^t^t^t^t^t^t^t^t^t^t%s^n^n%s",\
                        sMsg[0],\
                        sMsg[1],\
                        sMsg[2],\
                        sMsg[3]);
                   
                    set_hudmessage(100, 100, 100, -1.0, -1.0, 0, 0.0, 0.3, 0.0, 0.0, -1);
                    ShowSyncHudMsg(id, g_HudSyncObj_Keys2,\
                        "^n^n^n^n^n^n^n^n^n%s^n^n%s",\
                        sMsg[4],\
                        sMsg[5]);
                }
            }
        }
    }
   
    g_fKeysDelay = get_gametime() + 0.1;
   
    return FMRES_IGNORED;
}

public task_SpectatorList()
{
    static sTitle[46];
    static sMsg[1280];
   
    static sName[33][48];
   
    static bool:bHudExists;
   
    static spectators[32];
    static specNum;
    static totalSpecNum;
   
    static id, alive, dead, i, dead2, i2;
   
    for(id = 1; id <= g_MaxPlayers; id++)
    {
        if(!g_bConnected[id])
        {
            continue;
        }
       
        if(g_bSpecHide[id] && !(get_user_flags(id) & ADMIN_SPECHIDE))
        {
            g_bSpecHide[id] = false;
        }
    }
   
    for(alive = 1; alive <= g_MaxPlayers; alive++)
    {
        if(!g_bConnected[alive] || !g_bAlive[alive] || g_bBot[alive])
        {
            continue;
        }
       
        bHudExists = false;
        specNum = 0;
        arrayset(spectators, 0, 32);
       
        for(dead = 1; dead <= g_MaxPlayers; dead++)
        {
            if(!g_bConnected[dead] || g_bAlive[dead] || g_bBot[dead])
            {
                continue;
            }
           
            if(pev(dead, pev_iuser2) == alive)
            {
                spectators[specNum++] = dead;
                if(!bHudExists)
                {
                    get_user_name(alive, sName[alive], 31);
                    formatex(sTitle, 45, "Spectating %s^n", sName[alive]);
                    bHudExists = true;
                }
                get_user_name(dead, sName[dead], 31);
                format(sName[dead], 47, "              %s^n", sName[dead]);
            }
        }
       
        if(bHudExists && specNum > 0)
        {
            totalSpecNum = 0;
            formatex(sMsg, 1279, "%s", sTitle);
            if(g_bSpecList[alive])
            {
                for(i = 0; i < specNum; i++)
                {
                    dead =spectators[i];
                    if(!g_bSpecHide[dead])
                    {
                        add(sMsg, 1279, sName[dead]);
                        totalSpecNum++;
                    }
                }
               
                if(totalSpecNum > 0)
                {
                    format(sMsg, 1279, "(%d) %s", totalSpecNum, sMsg);
                   
                    ClearSyncHud(alive, g_HudSyncObj_List);
                    set_hudmessage(100, 100, 100, 0.75, 0.15, 0, 0.0, 1.1, 0.0, 0.0, -1);
                    ShowSyncHudMsg(alive, g_HudSyncObj_List, "%s", sMsg);
                }
            }
            for(i = 0; i < specNum; i++)
            {
                dead = spectators[i];
                if(!g_bSpecList[dead])
                {
                    continue;
                }
               
                totalSpecNum = 0;
                formatex(sMsg, 1279, "%s", sTitle);
                for(i2 = 0; i2 < specNum; i2++)
                {
                    dead2 = spectators[i2];
                    if(!g_bSpecHide[dead2])
                    {
                        add(sMsg, 1279, sName[dead2]);
                        totalSpecNum++;
                    }
                }
               
                if(totalSpecNum > 0)
                {
                    format(sMsg, 1279, "(%d) %s",totalSpecNum, sMsg);
                   
                    ClearSyncHud(dead, g_HudSyncObj_List);
                    set_hudmessage(100, 100, 100, 0.75, 0.15, 0, 0.0, 1.1, 0.0, 0.0, -1);
                    ShowSyncHudMsg(dead, g_HudSyncObj_List, "%s", sMsg);
                }
            }
        }
    }
   
    return PLUGIN_CONTINUE;
}


Exolent[jNr] 02-16-2009 20:33

Re: Show keys, doesn't show correctly
 
Please don't use that plugin of mine.
I do not feel that it is good enough for public use.
Use the one by ian or Fatalis.

refused 02-16-2009 21:37

Re: Show keys, doesn't show correctly
 
Quote:

Originally Posted by Exolent[jNr] (Post 762894)
Please don't use that plugin of mine.
I do not feel that it is good enough for public use.
Use the one by ian or Fatalis.

1. Ians speclist/showkeys isn't my style, this one looks alot better.
2. Fatalis haven't released anyone like this as far as I know, only a speclist which doesn't includes showkeys.
3. You made this plugin for me for a very long time ago when I made a request on it, however could anyone fix this? I'd really appreciete it. :)


All times are GMT -4. The time now is 17:02.

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