AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CS:GO] Server crashes if I "spam" a command (https://forums.alliedmods.net/showthread.php?t=321401)

awyx 02-08-2020 21:29

[CS:GO] Server crashes if I "spam" a command
 
So i've did a simple plugin which you can choose what hitmarker you want.
But if you use it too many times it crashes the sv ( only sometimes (with more than 1 player))
Any ideas?

Code:
Code:

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <clientprefs>

public Plugin myinfo =
{
        name = "Hitmarker menu",
        author = "roby & zauni",
        description = "",
        version = "",
        url = ""
};

#define TAG "\x01[\x10ERA\x01]"

int hm = 1; // hitmarker, default (1) = erawings,    2 = evil
int sv_clients[MAXPLAYERS + 1]; // client array (each client will have X hitmarker, default = 1)
Handle hitmarkerCookie;

public OnPluginStart()
{
        RegConsoleCmd("sm_hitmarker",  MenuHM);
        RegConsoleCmd("sm_hitmarkers", MenuHM);
        RegConsoleCmd("sm_hitmark",    MenuHM);
       
        HookEvent("player_death",      EnDamage);
       
        hitmarkerCookie = RegClientCookie("hitmarker", "Hitmarker Choice", CookieAccess_Protected);
}

public void OnClientCookiesCached(int client)
{
        if (IsFakeClient(client))
                return;
               
        if(IsClientConnected(client))
        {
                char buffer[32];
               
                GetClientCookie(client, hitmarkerCookie, buffer, sizeof(buffer));
               
                if (StrEqual(buffer, "0"))        sv_clients[client] = 0;
                if (StrEqual(buffer, "1"))        sv_clients[client] = 1;
                if (StrEqual(buffer, "2"))        sv_clients[client] = 2;
                if (StrEqual(buffer, "3"))        sv_clients[client] = 3;
                if (StrEqual(buffer, "4"))        sv_clients[client] = 4;
                if (StrEqual(buffer, "5"))        sv_clients[client] = 5;
                if (StrEqual(buffer, "6"))        sv_clients[client] = 6;
        }
}


public Action MenuHM(int client, int args)
{
        Menu menu = new Menu(MenuHM_CB);
        menu.SetTitle("Choose your hitmarker!");
        menu.AddItem("1", "E");
        menu.AddItem("2", "E");
        menu.AddItem("3", "C");
        menu.AddItem("4", "C");
        menu.AddItem("5", "K");
        menu.AddItem("6", "K");
        menu.Display(client, MENU_TIME_FOREVER);
        return Plugin_Handled;
}

public int MenuHM_CB(Menu menu, MenuAction action, int param1, int param2)
{
        switch (action)
        {
                case MenuAction_Select:
                {
                        char item[32], hm_name[16];
                        menu.GetItem(param2, item, sizeof(item), _, hm_name, sizeof(hm_name));
                       
                        hm = StringToInt(item);
                        sv_clients[param1] = hm;
                       
                        PrintToChat(param1, "%s \x04You chose \x0F%s\x04 hitmarker.", TAG, hm_name);
                       
                        SetClientCookie(param1, hitmarkerCookie, item);
                }
               
                case MenuAction_End:        {        sv_clients[param1] = 1;            delete menu; }
                case MenuAction_Cancel: {        sv_clients[param1] = 1;        delete menu; }
        }
}


Ilusion9 02-09-2020 05:20

Re: [CS:GO] Server crashes if I "spam" a command
 
PHP Code:

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <clientprefs>

public Plugin myinfo 
{
    
name "Hitmarker menu",
    
author "roby & zauni",
    
description "",
    
version "",
    
url ""
};

#define TAG "\x01[\x10ERA\x01]"

int g_HitMarker[MAXPLAYERS 1];
Handle hitmarkerCookie;

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_hitmarker"MenuHM);
    
RegConsoleCmd("sm_hitmarkers"MenuHM);
    
RegConsoleCmd("sm_hitmark"MenuHM);
    
HookEvent("player_death"EnDamage);
    
hitmarkerCookie RegClientCookie("hitmarker""Hitmarker Choice"CookieAccess_Protected);
}

public 
void OnClientCookiesCached(int client
{
    if (
IsFakeClient(client))
    {
        return;
    }
    
    if (
IsClientConnected(client))
    {
        
char buffer[32];
        
GetClientCookie(clienthitmarkerCookiebuffersizeof(buffer));
        
g_HitMarker[client] = StringToInt(buffer);
    }
}

public 
Action MenuHM(int clientint args)
{
    
Menu menu = new Menu(MenuHM_CB);
    
menu.SetTitle("Choose your hitmarker!");
    
menu.AddItem("1""Era wings");
    
menu.AddItem("2""Evil");
    
menu.AddItem("3""Cod");
    
menu.AddItem("4""Cod 2");
    
menu.AddItem("5""Karma 1");
    
menu.AddItem("6""Karma 2");
    
menu.Display(clientMENU_TIME_FOREVER);
    return 
Plugin_Handled;
}

public 
int MenuHM_CB(Menu menuMenuAction actionint param1int param2)
{
    switch (
action
    {
        case 
MenuAction_End:
        {
            
g_HitMarker[param1] = 1;
            
delete menu;
        }
        
        case 
MenuAction_Cancel:
        {
            
g_HitMarker[param1] = 1;
        } 
        
        case 
MenuAction_Select:
        {
            
char item[32], hm_name[16];
            
menu.GetItem(param2itemsizeof(item), _hm_namesizeof(hm_name));
            
            
int option StringToInt(item);
            
g_HitMarker[param1] = option;
            
            
PrintToChat(param1"%s \x04You chose \x0F%s\x04 hitmarker."TAGhm_name);
        }
    }
}

public 
void OnClientDisconnect(int client)
{
    
char option[64];
    
Format(optionsizeof(option), "%d"g_HitMarker[client]);
    
SetClientCookie(clienthitmarkerCookieoption);
}

public 
OnConfigsExecuted()
{
    
// 1, def
    
PrecacheDecal("overlays/wingsmarkerv2.vtf"true);
    
PrecacheDecal("overlays/wingsmarkerv2.vmt"true);

    
// 2 evil
    
PrecacheDecal("overlays/crosshair_evil_v2.vtf"true);
    
PrecacheDecal("overlays/crosshair_evil_v2.vmt"true);
    
    
// cod 3 4
    
PrecacheDecal("iex/hit01.vtf"true);
    
PrecacheDecal("iex/hit01.vmt"true);
    
PrecacheDecal("iex/hit02.vtf"true);
    
PrecacheDecal("iex/hit02.vmt"true);
    
    
// 5 6 karma
    
PrecacheDecal("backwards/hitmarker.vtf"true);
    
PrecacheDecal("backwards/hitmarker.vmt"true);
    
PrecacheDecal("backwards/hitmarker_2.vtf"true);
    
PrecacheDecal("backwards/hitmarker_2.vmt"true);
}

ShowOverlayToClient(client, const char[] overlaypath)
{
    
ClientCommand(client"r_screenoverlay \"%s\""overlaypath);
}

public 
void EnDamage(Event event, const char[] namebool dontBroadcast)
{
    
int attackerId event.GetInt("attacker");
    
int attacker GetClientOfUserId(attackerId);
    if (!
attacker)
        return;
    
    switch (
g_HitMarker[attacker])
    {
        case 
0: {
            
ShowOverlayToClient(attacker"overlays/wingsmarkerv2");
        }
        case 
1: {
            
ShowOverlayToClient(attacker"overlays/wingsmarkerv2");
        }
        case 
2: {    
            
ShowOverlayToClient(attacker"overlays/crosshair_evil_v2");
        }
        case 
3: {    
            
ShowOverlayToClient(attacker"iex/hit01");
        }
        case 
4: {    
            
ShowOverlayToClient(attacker"iex/hit02");
        }
        case 
5: {
            
ShowOverlayToClient(attacker"backwards/hitmarker");
        }
        case 
6: {    
            
ShowOverlayToClient(attacker"backwards/hitmarker_2");
        }
    }
    
    
CreateTimer(1.0NoOverlayattackerId);
}

public 
Action NoOverlay(Handle timerany data)
{
    
int client GetClientOfUserId(data);
    if (
client)
    {
        
ShowOverlayToClient(client"");
    }




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

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