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

[L4D2] get userid of person calling the vote


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
canadianjeff
BANNED
Join Date: Sep 2016
Old 03-12-2021 , 18:00   [L4D2] get userid of person calling the vote
#1

in console if you type status you get a list of players connected for example

# userid name uniqueid connected ping loss state rate
# 3626 1 "Foo" STEAM_1:1:XXXXXXXX 15:32 83 0 active 10000
# 3609 2 "Bar" STEAM_1:1:XXXXXXX 26:54 86 0 active 30000
# 3642 3 "Baz" STEAM_1:0:XXXXXXXX 00:28 106 0 active 30000

now lets say player "Foo" calls a kick vote against "Baz" how would a plugin get player "Foo" userid (3626)

this is what I have so far.....

Code:
public Action:callvoteListener(client, const String:cmd[], argc)
{
	//PrintToChatAll("A Vote Has Been Called");
	if (argc < 2)
		return Plugin_Continue;
	
	decl String:votereason[16];
	GetCmdArg(1, votereason, sizeof(votereason));
	decl String:initiatorName[MAX_NAME_LENGTH];
	GetClientName(client, initiatorName, sizeof(initiatorName));
	
	if ((StrEqual(votereason, "kick", false)) ||
	(StrEqual(votereason, "kickid", false)) ||
	(StrEqual(votereason, "ban", false)) ||
	(StrEqual(votereason, "banid", false)))
	{
		//PrintToChatAll("A Kick/Ban Vote Has Been Called");
		decl String:strName[256];
		GetCmdArg(2, strName, sizeof(strName));
		
		//Format(strName, sizeof(strName), "#%s", strName);
		//int target = FindTarget(client, strName, true, false);
		new target = GetClientOfUserId(StringToInt(strName));
		new target2 = GetClientUserId(client);
		if(target < 1)
		{
			PrintToChat(client, "Invalid Kick Target");
			return Plugin_Continue;
		}

		PrintToChatAll("Vote Start: issue: \"%s\", real targetid: \"%s\", real targetname: %N", votereason, strName, target);
		PrintToChatAll("Vote Start: issue: \"%s\", fake targetid: \"%d\", fake targetname: %N", votereason, target2, initiatorName);
		
		//new AdminId:clientAdmin = GetUserAdmin(client);
		//new AdminId:targetAdmin = GetUserAdmin(target);
		
		//if(clientAdmin == INVALID_ADMIN_ID && targetAdmin == INVALID_ADMIN_ID)
		//{
			//return Plugin_Continue;
		//}
		
		//if(CanAdminTarget(clientAdmin, targetAdmin))
		//{
			//return Plugin_Continue;
		//}
		
		//PrintToChat(client, "\x01\x0759b0f9[=F|A=]\x01 You are not allowed to vote this player/admin!");
		
		return Plugin_Handled;
	}
	
	PrintToChatAll("End Of Plugin Reached");
	return Plugin_Continue;
}

Last edited by asherkin; 03-07-2022 at 04:04. Reason: Restore to previous version.
canadianjeff is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 03-12-2021 , 19:02   Re: [L4D2] get userid of person calling the vote
#2

You're on the right track. Here's how you get the userid of the caller:

PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
AddCommandListener(cmdCallVote"callvote");
}

public 
Action cmdCallVote(int client, const char[] commandint argc)
{
    if (!(
client <= MaxClients && IsClientInGame(client)))
    {
        return 
Plugin_Continue;
    }

    
int iCallerID GetClientUserId(client);
    
char sType[32];
    
GetCmdArg(1sTypesizeof sType);
    if (
StrEqual(sType"kick"false))
    {
        
char sTarget[10];
        
GetCmdArg(2sTargetsizeof sTarget);
        
int iTarget GetClientOfUserId(StringToInt(sTarget));
        if (
iTarget <= MaxClients && IsClientInGame(iTarget))
        {
            
// Example: "[SM] canadianjeff (325) called a kick vote against Crasher_3637 (326)"
            
PrintToChatAll("[SM] %N (%i) called a %s vote against %N (%s)"clientiCallerIDsTypeiTargetsTarget);
        }
    }

    return 
Plugin_Continue;

__________________
Psyk0tik is offline
canadianjeff
BANNED
Join Date: Sep 2016
Old 03-12-2021 , 21:59   Re: [L4D2] get userid of person calling the vote
#3

tried with this and I get a message I am command spamming hrmmmmm...

PHP Code:
#include <sourcemod>

#pragma semicolon 1

#define PLUGIN_VERSION "0.01"

public Plugin myinfo 
{
    
name "Kick The Kicker!",
    
author "Your name here!",
    
description "Make It So The Person Calling The Kick Gets Kicked!",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
/**
     * @note For the love of god, please stop using FCVAR_PLUGIN.
     * Console.inc even explains this above the entry for the FCVAR_PLUGIN define.
     * "No logic using this flag ever existed in a released game. It only ever appeared in the first hl2sdk."
     */
    
CreateConVar("sm_kickthekicker_version"PLUGIN_VERSION"Standard plugin version ConVar. Please don't change me!",    FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
decl String:game_name[64];
    
GetGameFolderName(game_namesizeof(game_name));
    if (!
StrEqual(game_name"left4dead2"false))
    {
        
SetFailState("Plugin supports Left 4 Dead 2 only.");
    }    
    
AddCommandListener(callvoteListener"callvote");
}

public 
Action:callvoteListener(int client, const char[] commandint argc)
{
    if (!(
client <= MaxClients && IsClientInGame(client)))
    {
        return 
Plugin_Continue;
    }

    
int iCallerID GetClientUserId(client);
    
char sType[32];
    
GetCmdArg(1sTypesizeof sType);
    if (
StrEqual(sType"kick"false))
    {
        
char sTarget[10];
        
GetCmdArg(2sTargetsizeof sTarget);
        
int iTarget GetClientOfUserId(StringToInt(sTarget));
        if (
iTarget <= MaxClients && IsClientInGame(iTarget))
        {
            
FakeClientCommandEx(client"callvote kick %i"iCallerID);
            
// Example: "[SM] canadianjeff (325) called a kick vote against Crasher_3637 (326)"
            //PrintToChatAll("[SM] %N (%i) called a %s vote against %N (%s)", client, iCallerID, sType, iTarget, sTarget);
        
}
    }

    return 
Plugin_Handled;

canadianjeff is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 03-13-2021 , 03:39   Re: [L4D2] get userid of person calling the vote
#4

Quote:
Originally Posted by canadianjeff View Post
[...]
The code is almost right. Here is the fixed one:
PHP Code:
#include <sourcemod>
#pragma semicolon 1

#define PLUGIN_VERSION "0.01"

public APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    if (
GetEngineVersion() != Engine_Left4Dead2)
    {
        
strcopy(errorerr_max"Plugin supports Left 4 Dead 2 only.");
        return 
APLRes_SilentFailure;
    }
    
    return 
APLRes_Success;
}

public 
Plugin myinfo 
{
    
name "Kick The Kicker!",
    
author "Your name here!",
    
description "Make It So The Person Calling The Kick Gets Kicked!",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
/**
     * @note For the love of god, please stop using FCVAR_PLUGIN.
     * Console.inc even explains this above the entry for the FCVAR_PLUGIN define.
     * "No logic using this flag ever existed in a released game. It only ever appeared in the first hl2sdk."
     */
    
CreateConVar("sm_kickthekicker_version"PLUGIN_VERSION"Standard plugin version ConVar. Please don't change me!",    FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
    
AddCommandListener(callvoteListener"callvote");
}

public 
Action callvoteListener(int client, const char[] commandint argc)
{
    if (!(
client <= MaxClients && IsClientInGame(client)))
    {
        return 
Plugin_Continue;
    }
    
    
int iCallerID GetClientUserId(client);
    
    
char sType[32];
    
GetCmdArg(1sTypesizeof sType);
    if (
strcmp(sType"Kick"false) == 0)
    {
        
char sTarget[10];
        
GetCmdArg(2sTargetsizeof sTarget);
        
        
int iTarget GetClientOfUserId(StringToInt(sTarget));
        if (
iTarget <= MaxClients && IsClientInGame(iTarget))
        {
            
FakeClientCommandEx(client"callvote kick %i"iCallerID);
            
// Example: "[SM] canadianjeff (325) called a kick vote against Crasher_3637 (326)"
            //PrintToChatAll("[SM] %N (%i) called a %s vote against %N (%s)", client, iCallerID, sType, iTarget, sTarget);
            
return Plugin_Handled;
        }
    }
    
    return 
Plugin_Continue;


Last edited by cravenge; 03-13-2021 at 03:41.
cravenge is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 03-13-2021 , 12:38   Re: [L4D2] get userid of person calling the vote
#5

The problem here is that you are creating an infinite loop, hence the "spamming commands" message.

Every time a player calls a vote, you are making the player call another vote. Even if you block the original vote, you are still creating an endless loop.

Since you are forcing the caller to call a vote to kick him/herself instead, you must check that the caller is not the target, like this:
PHP Code:
if (iTarget <= MaxClients && IsClientInGame(iTarget) && iTarget != client
But this only works BECAUSE of your line:
PHP Code:
FakeClientCommandEx(client"callvote kick %i"iCallerID); 
If you were to pass the target instead of the caller into FakeClientCommandEx it would still create an infinite loop.
__________________
Psyk0tik is offline
Closed Thread



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


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