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

Solved [CS:GO] Plugin Crashing Server - Need help!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Di3Z1E
Member
Join Date: May 2018
Old 12-27-2018 , 14:30   [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #1

Hey,
I made a plugin that supposed to allow players to make a vote for Headshots only in-game.
Code compiled with 1 warning, but crashing the server...

disclaimer:
i'm not pro, just a dude who plays around and sometimes make tiny cool stuff

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <colors_csgo>

public Plugin myinfo =
{
    
name "HS Mode Only Via Vote",
    
author "Di3Z1E",
    
description "Allowing the players to initiate a vote for Headshots Only.",
    
version "1.00",
    
url ""
};

bool votedone=false;
int countyes=0;
int countno=0;



public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_hso"Command_HSonly"Start Vote For Head Shot Mode Only");
}

public 
Action Command_HSonly(int clientint args)
{
     
    
PrintToChat(client" \x10[המחתרת]\x01 Launched HS Mode Only Vote!")
    return 
Plugin_Handled;
}  

public 
Action votemenu(int clientint args)
{
    
char menuinfo[255];
    
Format(menuinfosizeof(menuinfo), "Activate Only Headshots mode?"client);
    
Menu hsonly = new Menu(votemenuhs);
    
hsonly.SetTitle(menuinfo);
    
    
Format(menuinfosizeof(menuinfo), "Yes"client);
    
hsonly.AddItem("yes"menuinfo);
    
    
Format(menuinfosizeof(menuinfo), "No"client);
    
hsonly.AddItem("no"menuinfo);
    
    
hsonly.ExitButton true;
    
hsonly.Display(clientMENU_TIME_FOREVER);
    return 
Plugin_Handled;
}


public 
int votemenuhs(Menu hsonlyMenuAction actionint clientint selection)
{
    
char info[32];
    
hsonly.GetItem(selectioninfosizeof(info));
    
    if (
strcmp(info"yes") == 0)
    {
        
countyes++;
    }
    
    else if (
strcmp(info"no") == 0)
    {
        
countno++;
    }
    else if (
action == MenuAction_End)
    {
        
delete hsonly;
    }
    
    if (
countyes>(countno+countyes)/2)
    {
        
ServerCommand("sm_rcon mp_damage_headshot_only 1");
        
votedone=true;
    }
    else if (
countno>(countno+countyes/2))
    {
        
ServerCommand("sm_rcon mp_damage_headshot_only 0");
        
votedone=true;
    }
}


public 
void OnMapStart()
{
    
votedone=false;
    
countno=0;
    
countyes=0;

edit:
set it to php instead of code

Last edited by Di3Z1E; 12-30-2018 at 07:22.
Di3Z1E is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-27-2018 , 17:31   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #2

And what makes you think it was this plugin that crashes the server?
__________________
8guawong is offline
Di3Z1E
Member
Join Date: May 2018
Old 12-27-2018 , 17:53   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
And what makes you think it was this plugin that crashes the server?
When i put it in the server it crash, when i put it out back the server works fine...
Di3Z1E is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 12-27-2018 , 19:31   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #4

PHP Code:
    Format(menuinfosizeof(menuinfo), "Yes"client); 
PHP Code:
    Format(menuinfosizeof(menuinfo), "No"client); 
I think these are not valid use... but i also don't think it crashed server
__________________

Last edited by Starbish; 12-27-2018 at 19:31.
Starbish is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-27-2018 , 20:30   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #5

You are creating normal menu instead vote menu.

However, when you create menu, you make it work with default menu actions.
(MenuAction_Select|MenuAction_Cancel|MenuActi on_End)

So, menu Handler is called on those menu actions, Handle will work more than once, remember.

And in each menu action, param1 and param2 have own meaning.
param1 is not always client index, param2 is not everytime selection.
https://sm.alliedmods.net/new-api/menus/__raw

That is your problem, you are using param1 and param2 wrong.



Here wiki to create vote
https://wiki.alliedmods.net/Menu_API...d)#Simple_Vote
__________________
Do not Private Message @me
Bacardi is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-28-2018 , 03:12   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #6

Quote:
Originally Posted by Di3Z1E View Post
When i put it in the server it crash, when i put it out back the server works fine...
so does the server crash when you load the plugin?

step to test it

1. put your plugin in the disabled folder
2. after server starts do sm plugins load disabled/blah.smx
__________________

Last edited by 8guawong; 12-28-2018 at 03:14.
8guawong is offline
Di3Z1E
Member
Join Date: May 2018
Old 12-29-2018 , 20:27   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #7

Quote:
Originally Posted by Bacardi View Post
You are creating normal menu instead vote menu.

However, when you create menu, you make it work with default menu actions.
(MenuAction_Select|MenuAction_Cancel|MenuActi on_End)

So, menu Handler is called on those menu actions, Handle will work more than once, remember.

And in each menu action, param1 and param2 have own meaning.
param1 is not always client index, param2 is not everytime selection.
https://sm.alliedmods.net/new-api/menus/__raw

That is your problem, you are using param1 and param2 wrong.



Here wiki to create vote
https://wiki.alliedmods.net/Menu_API...d)#Simple_Vote
So i created this:
PHP Code:
#pragma semicolon 1

#define PLUGIN_AUTHOR "Di3Z1E"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <sdktools>
#include <cstrike>


public Plugin myinfo 
{
    
name "Headshot Only"
    
author PLUGIN_AUTHOR
    
description "Allowing Players To Vote For Only Headshot Mode."
    
version PLUGIN_VERSION
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_hs"Command_HS"Run vote for Headshot only mode.");
}

    
void DoVoteMenu(args)
{
        if (
IsVoteInProgress())
    {
        return;
    }    
    
Menu menu = new Menu(Command_HS);
    
menu.SetTitle("Activate only Headshots mode?");
    
menu.AddItem("yes""Yes"param1);
    
menu.AddItem("no""No"param2);
    
menu.ExitButton false;
    
menu.DisplayVoteToAll(60);
}     
    
public 
int Command_HS(Menu menuMenuAction actionint param1int param2)
{
        if (
action == MenuAction_End)
        {
            
            
delete menu;
        }
        else if (
action == MenuAction_VoteEnd)
        {
            
            if (
param1 == 0)
            {
                
menu.GetItem(param1);
                
ServerCommand("sm_rcon mp_damage_headshot_only 1");
            }
            if (
param2 == 1)
            {
                
menu.GetItem(param2);
                
ServerCommand("sm_rcon mp_damage_headshot_only 0");
            }
        }

And i got this:
PHP Code:
// E:\Counter Strike Global Offenisve\_Di3Z1E Plugins\Headshot Only Mode.sp(22) : error 100: function prototypes do not match
// E:\Counter Strike Global Offenisve\_Di3Z1E Plugins\Headshot Only Mode.sp(52) : error 092: number of arguments does not match definition
// E:\Counter Strike Global Offenisve\_Di3Z1E Plugins\Headshot Only Mode.sp(57) : error 092: number of arguments does not match definition
// E:\Counter Strike Global Offenisve\_Di3Z1E Plugins\Headshot Only Mode.sp(26) : warning 203: symbol is never used: "DoVoteMenu" 
any help ?
Di3Z1E is offline
Cruze
Veteran Member
Join Date: May 2017
Old 12-30-2018 , 01:09   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #8

PHP Code:
#pragma semicolon 1 
#pragma newdecls required

#define PLUGIN_AUTHOR "Di3Z1E" 
#define PLUGIN_VERSION "1.01" 

#include <sourcemod>

#define SERVERTAG " [SM]"

public Plugin myinfo =  

    
name "Headshot Only",  
    
author PLUGIN_AUTHOR,  
    
description "Allowing Players To Vote For Only Headshot Mode.",  
    
version PLUGIN_VERSION,  
    
url "" 
}; 

public 
void OnPluginStart() 

    
RegConsoleCmd("sm_hs"Command_HS"Run vote for Headshot only mode."); 


public 
Action Command_HS(int clientint args)
{
    if (
IsVoteInProgress()) 
    { 
        
PrintToChat(client"%s Retry when to no vote is on progress!"SERVERTAG);
        return 
Plugin_Handled;
    } 
    
DoVoteMenu();
    return 
Plugin_Handled;
}

void DoVoteMenu() 
{     
    
Menu menu = new Menu(Handle_HS); 
    
menu.SetTitle("Activate only Headshots mode?"); 
    
menu.AddItem("""Yes"); 
    
menu.AddItem("""No"); 
    
menu.ExitButton false
    
menu.DisplayVoteToAll(60); 
}      

public 
int Handle_HS(Menu menuMenuAction actionint param1int param2)

    if (
action == MenuAction_End)
    {
        
delete menu;
    }
    else if (
action == MenuAction_VoteEnd)
    {
        if (
param1 == 0)
        {
            if(
GetConVarBool(FindConVar("mp_damage_headshot_only")) == false)
            {
                
SetConVarBool(FindConVar("mp_damage_headshot_only"), true);
                
PrintToChatAll("%s Headshot only mode is turned\x04ON.\x01"SERVERTAG);
            }
            else
            {
                
PrintToChatAll("%s Headshot only mode is already turned \x04ON.\x01"SERVERTAG);
            }
        }
        else
        {
            if(
GetConVarBool(FindConVar("mp_damage_headshot_only")) == true)
            {
                
SetConVarBool(FindConVar("mp_damage_headshot_only"), false);
                
PrintToChatAll("%s Headshot only mode is turned \x07OFF.\x01"SERVERTAG);
            }
            else
            {
                
PrintToChatAll("%s Headshot only mode is already turned \x07OFF.\x01"SERVERTAG);
            }
        }
    }

Try this
__________________
Taking paid private requests! Contact me

Last edited by Cruze; 12-30-2018 at 07:35. Reason: Removed unnecessary includes, made chat coloful and updated version.
Cruze is offline
Di3Z1E
Member
Join Date: May 2018
Old 12-30-2018 , 07:22   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #9

Quote:
Originally Posted by Cruze View Post
PHP Code:
#pragma semicolon 1 

#define PLUGIN_AUTHOR "Di3Z1E" 
#define PLUGIN_VERSION "1.00" 

#include <sourcemod> 
#include <sdktools> 
#include <cstrike>

#pragma newdecls required

public Plugin myinfo =  

    
name "Headshot Only",  
    
author PLUGIN_AUTHOR,  
    
description "Allowing Players To Vote For Only Headshot Mode.",  
    
version PLUGIN_VERSION,  
    
url "" 
}; 

public 
void OnPluginStart() 

    
RegConsoleCmd("sm_hs"Command_HS"Run vote for Headshot only mode."); 


public 
Action Command_HS(int clientint args)
{
    if (
IsVoteInProgress()) 
    { 
        
PrintToChat(client"[SM] Retry when no vote is on progress!");
        return 
Plugin_Handled;
    } 
    
DoVoteMenu();
    return 
Plugin_Handled;
}

void DoVoteMenu() 
{     
    
Menu menu = new Menu(Handle_HS); 
    
menu.SetTitle("Activate only Headshots mode?"); 
    
menu.AddItem("""Yes"); 
    
menu.AddItem("""No"); 
    
menu.ExitButton false
    
menu.DisplayVoteToAll(60); 
}      
     
public 
int Handle_HS(Menu menuMenuAction actionint param1int param2)

    if (
action == MenuAction_End)
    {
        
delete menu;
    }
    else if (
action == MenuAction_VoteEnd)
    {
        if (
param1 == 0)
        {
            if(
GetConVarBool(FindConVar("mp_damage_headshot_only")) == false)
            {
                
SetConVarBool(FindConVar("mp_damage_headshot_only"), true);
                
PrintToChatAll("[SM] HS ONLY MODE ENABLED.");
            }
            else
            {
                
PrintToChatAll("[SM] HS ONLY MODE IS ALREADY ENABLED.");
            }
        }
        else
        {
            if(
GetConVarBool(FindConVar("mp_damage_headshot_only")) == true)
            {
                
SetConVarBool(FindConVar("mp_damage_headshot_only"), false);
                
PrintToChatAll("[SM] HS ONLY MODE DISABLED.");
            }
            else
            {
                
PrintToChatAll("[SM] HS ONLY MODE IS ALREADY DISABLED.");
            }
        }
    }

Try this

Thank you, it works!
Di3Z1E is offline
Cruze
Veteran Member
Join Date: May 2017
Old 12-30-2018 , 07:36   Re: [CS:GO] Plugin Crashing Server - Need help!
Reply With Quote #10

Quote:
Originally Posted by Di3Z1E View Post
Thank you, it works!
No Probs . Edited my comment. Check edit reason to know what all I changed.
__________________
Taking paid private requests! Contact me
Cruze 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 15:32.


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