Senior Member
|
07-21-2019
, 15:03
Re: [L4D2] [Req/Pay] I Need Plugin Like This
|
#2
|
Maybe someone can fix this - on the "Auto Change Bot Name" request I got as far as this but it looks like it won't change the client's name. I verified the check right before the attempted name change gets fired (if (GetTrieString(g_hTrie_botnames, sName, sTmp, sizeof(sTmp)))) with the correct string value (e.g. "Ellis" "tesla").
Was going to do some more work to get this working and optimize the code a bit but lost interest.
Spoiler
PHP Code:
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1
#pragma newdecls required
StringMap g_hTrie_botnames;
public Plugin myinfo = {
name = "Bot name changer",
author = "dustin",
description = "",
version = "1.0",
url = "https://forums.alliedmods.net/showthread.php?t=317598"
};
public void OnPluginStart()
{
g_hTrie_botnames = CreateTrie();
}
public void OnClientPostAdminCheck(int client)
{
// client's name isn't available immediately if it's a fake client for some reason
if (0 < client && IsClientInGame(client) && IsFakeClient(client))
{
CreateTimer(3.0, Timer_NameCheck, GetClientUserId(client));
}
}
public Action Timer_NameCheck(Handle timer, any data)
{
int client = GetClientOfUserId(data);
if (client && GetClientTeam(client) == 2)
{
char sName[32], sTmp[32];
GetClientName(client, sName, sizeof(sName));
// check to see if the name exists in the string map.
if (GetTrieString(g_hTrie_botnames, sName, sTmp, sizeof(sTmp)))
{
//SetClientName(client, sTmp); // not working on fake clients
SetClientInfo(client, "name", sTmp);
SetEntPropString(client, Prop_Data, "m_szNetname", sTmp);
Handle event = CreateEvent("player_changename");
if (event != INVALID_HANDLE)
{
SetEventInt(event, "userid", GetClientUserId(client));
SetEventString(event, "oldname", sName);
SetEventString(event, "newname", sTmp);
FireEvent(event);
}
delete event; // manually firing the event doesn't work either.
}
}
return Plugin_Handled;
}
public void OnConfigsExecuted()
{
ClearTrie(g_hTrie_botnames);
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/botnames.cfg");
KeyValues kv = CreateKeyValues("botnames");
if (FileToKeyValues(kv, sPath) && KvGotoFirstSubKey(kv, false))
{
do
{
char sName[32], sChagedName[32];
KvGetSectionName(kv, sName, sizeof(sName));
KvGetString(kv, NULL_STRING, sChagedName, sizeof(sChagedName));
SetTrieString(g_hTrie_botnames, sName, sChagedName);
}
while (KvGotoNextKey(kv, false));
}
delete kv;
}
configs/botnames.cfg
Spoiler
PHP Code:
"botnames"
{
"Ellis" "tesla"
"Coach" "Axis"
}
|
|