Senior Member
|
07-26-2019
, 14:07
Re: [L4D2] [Req/Pay] I Need Plugin Like This
|
#7
|
Honestly that plugin wasn't working for me, and the only reason I included manually firing the name changing event in the code is to show I tried that, as well as the 'SetClientName' method.
Manually checking to see if the handle != INVALID_HANDLE before deleting it still doesn't fix the error. Weird. Maybe someone with more experience can post a suggestion.
snippet
Spoiler
PHP Code:
Handle event = CreateEvent("player_changename"); if (event != INVALID_HANDLE) { SetEventInt(event, "userid", GetClientUserId(client)); SetEventString(event, "oldname", sName); SetEventString(event, "newname", sTmp); FireEvent(event); // only deleting it if it wasn't invalid in the first place.. delete event; }
errors.log
Spoiler
L 07/26/2019 - 17:54 4: [SM] Exception reported: Handle c4007e is invalid (error 3)
L 07/26/2019 - 17:54 4: [SM] Blaming: plugin.smx
L 07/26/2019 - 17:54 4: [SM] Call stack trace:
L 07/26/2019 - 17:54 4: [SM] [0] CloseHandle
L 07/26/2019 - 17:54 4: [SM] [1] Line 57, plugin.sp::Timer_NameCheck
edit:
This should work for you I think. For some reason renaming bots on my test server (which only has the default sourcemod plugins installed) doesn't work for me, but since it works for you I think the plugin will work fine without manually firing that name event.
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))) { SetClientInfo(client, "name", sTmp); SetEntPropString(client, Prop_Data, "m_szNetname", sTmp); } } 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; }
For some reason my test server doesn't allow renaming bots but does allow for renaming human players so that's odd. Tried the default !rename command that comes with sourcemod and even wrote out a test script to confirm it doesn't work..
https://imgur.com/wuwdbLg
Spoiler
PHP Code:
#include <sourcemod> #include <sdktools>
#pragma semicolon 1 #pragma newdecls required
public Plugin myinfo = { name = "test", author = "dustin", description = "", version = "0.0.0", url = "" };
public void OnPluginStart() { RegConsoleCmd("sm_testtt", Command_Test); }
public Action Command_Test(int client, int args) { for (int i = 1; i <= MaxClients; i++) { if (!IsClientInGame(i)) continue; if (IsFakeClient(i) && GetClientTeam(i) == 2) { PrintToChatAll("Renaming %N", i); SetClientInfo(i, "name", "sdfsfdsf"); SetEntPropString(i, Prop_Data, "m_szNetname", "sdfsfdsf"); break; } } return Plugin_Handled; }
Last edited by dustinandband; 07-27-2019 at 11:45.
|
|