Member
|
09-21-2017
, 23:53
[L4D2] Little Help with Cookies and Color Players Plugin
|
#1
|
hello,
I'm trying to update the plugin below to store in cookies the players preference of color set.
But when i try to set the color stored in cookies via SetEntityRenderColor(client, StringToInt(sModel1), StringToInt(sModel2), StringToInt(sModel3), 255) the color stored in cookie doesn't come back.
I believe it's because when i store each RGB number in a char var, each value transform in an annoying value with 9 digits or something like that (i realized it via PrintToChat(client, "\x04[SM Colour] \x03You stored the colors %d %d %d", g_hClientModel1, g_hClientModel2, g_hClientModel3))
Anyone can tell me the trick to set back the RGB colors stored in char vars of cookies?
PHP Code:
////////////////////////////////////////////////////////////////// // SM COLOUR By MoggieX //////////////////////////////////////////////////////////////////
#include <sourcemod> #include <sdktools> #include <clients> #include <clientprefs> #define REQUIRE_EXTENSIONS #pragma semicolon 1 #define PLUGIN_VERSION "9.0" #define PLUGIN_PREFIX "[SM]"
ConVar convarCookies;
Handle g_hClientModel1; Handle g_hClientModel2; Handle g_hClientModel3;
////////////////////////////////////////////////////////////////// // Plugin Info //////////////////////////////////////////////////////////////////
public Plugin:myinfo = { name = "sm_colour", author = "MoggieX", description = "Set a Players Colour & Rendering", version = PLUGIN_VERSION, url = "http://www.afterbuy.co.uk" };
////////////////////////////////////////////////////////////////// // Start Plugin //////////////////////////////////////////////////////////////////
public OnPluginStart() { g_hClientModel1 = RegClientCookie("Player_Color_Red", "Player's default Red Color.", CookieAccess_Protected); g_hClientModel2 = RegClientCookie("Player_Color_Green", "Player's default Green Color.", CookieAccess_Protected); g_hClientModel3 = RegClientCookie("Player_Color_Blue", "Player's default Blue Color.", CookieAccess_Protected); LoadTranslations("common.phrases");
CreateConVar("sm_colour_version", PLUGIN_VERSION, "SM Colour Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY); RegAdminCmd("sm_color", Command_SmColour, ADMFLAG_CUSTOM2, "sm_color <name or #userid> <RED> <GREEN> <BLUE>."); RegAdminCmd("sm_render", Command_SmRender, ADMFLAG_ROOT, "sm_render <name or #userid or all/t/ct> <value> - Set target's render."); convarCookies = CreateConVar("l4d_color_cookies", "1", "Store player's color? 1:Enable, 0:Disable",FCVAR_NOTIFY,true, 0.0, true, 1.0); }
public OnClientPutInServer(client) { if(IsClientConnected(client) && !IsFakeClient(client) && convarCookies && (GetClientFrags(client) & ADMFLAG_CUSTOM2)) { CreateTimer(5.0, Timer_LoadCookie, GetClientUserId(client)); } }
public Action Timer_LoadCookie(Handle timer, int userid) { int client = GetClientOfUserId(userid); char sModel1[32]; char sModel2[32]; char sModel3[32];
if(IsClientConnected(client) && !IsFakeClient(client) && convarCookies) { GetClientCookie(client, g_hClientModel1, sModel1, sizeof(sModel1)); GetClientCookie(client, g_hClientModel2, sModel2, sizeof(sModel2)); GetClientCookie(client, g_hClientModel3, sModel3, sizeof(sModel3)); if(strlen(sModel1) && strlen(sModel2) && strlen(sModel3)) { SetEntityRenderColor(client, StringToInt(sModel1), StringToInt(sModel2), StringToInt(sModel3), 255); } } else if (client) { PrintToChat(client, "%s Couldn't load your default Color.", PLUGIN_PREFIX);} }
//////////////////////////////////////////////////////////////////////// // sm_colour //////////////////////////////////////////////////////////////////////// public Action:Command_SmColour(client, args) { if (args < 4) { ReplyToCommand(client, "[SM Colour] Usage: sm_colour <#userid|name|team|all> <RED 0-255> <GREEN 0-255> <BLUE 0-255>"); return Plugin_Handled; }
// Error trapping for R G B O
// #2 Red new red = 0; decl String:arg2[20]; GetCmdArg(2, arg2, sizeof(arg2)); if (StringToIntEx(arg2, red) == 0) { ReplyToCommand(client, "\x04[SM Colour]\x01 %t", "Invalid Amount For Red"); return Plugin_Handled; } if (red < 0) { red = 0; } if (red > 255) { red = 255; } if (GetClientTeam(client) == 3) { new AdminId:admin = GetUserAdmin(client); if (GetAdminFlag(admin, Admin_Unban)) { red < 255; red > 0; } else { red = 255; } }
// #3 Green new green = 0; decl String:arg3[20]; GetCmdArg(3, arg3, sizeof(arg3)); if (StringToIntEx(arg3, green) == 0) { ReplyToCommand(client, "\x04[SM Colour]\x01 %t", "Invalid Amount For Green"); return Plugin_Handled; } if (green < 0) { green = 0; } if (green > 255) { green = 255; } if (GetClientTeam(client) == 3) { new AdminId:admin = GetUserAdmin(client); if (GetAdminFlag(admin, Admin_Unban)) { green < 255; green > 0; } else { green = 255; } }
// #4 Blue new blue = 0; decl String:arg4[20]; GetCmdArg(4, arg4, sizeof(arg4)); if (StringToIntEx(arg4, blue) == 0) { ReplyToCommand(client, "\x04[SM Colour]\x01 %t", "Invalid Amount For Blue"); return Plugin_Handled; } if (blue < 0) { blue = 0; } if (blue > 255) { blue = 255; } if (GetClientTeam(client) == 3) { new AdminId:admin = GetUserAdmin(client); if (GetAdminFlag(admin, Admin_Unban)) { blue < 255; blue> 0; } else { blue = 255; } } if (client) SetEntityRenderColor(client, red, green, blue); PrintToChat(client, "\x04[SM Colour] \x03You set the color %d %d %d", red, green, blue); if (convarCookies) { char sprop1[32]; IntToString(red, sprop1, 32); SetClientCookie(client, g_hClientModel1, sprop1); char sprop2[32]; IntToString(green, sprop2, 32); SetClientCookie(client, g_hClientModel2, sprop2); char sprop3[32]; IntToString(blue, sprop3, 32); SetClientCookie(client, g_hClientModel3, sprop3); PrintToChat(client, "\x04[SM Colour] \x03You stored the colors %d %d %d", g_hClientModel1, g_hClientModel2, g_hClientModel3); }
return Plugin_Handled; }
//////////////////////////////////////////////////////////////////////// // sm_render ////////////////////////////////////////////////////////////////////////
public Action:Command_SmRender(client, args) { if (args < 1) { ReplyToCommand(client, "[SM Render] Usage: sm_render <#userid|name|team|all> <RENDER 0-26>"); return Plugin_Handled; }
// get their name decl String:arg[65]; GetCmdArg(1, arg, sizeof(arg));
new amount = 0; decl String:arg2[20]; GetCmdArg(2, arg2, sizeof(arg2)); if (StringToIntEx(arg2, amount) == 0) { ReplyToCommand(client, "[SM] %t", "Invalid Amount"); return Plugin_Handled; } if (amount < 0) { amount = 0; } if (amount > 26) { amount = 26; }
//////// Find and Set
decl String:target_name[MAX_TARGET_LENGTH]; decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; if ((target_count = ProcessTargetString( arg, client, target_list, MAXPLAYERS, COMMAND_FILTER_ALIVE, target_name, sizeof(target_name), tn_is_ml)) <= 0) { ReplyToTargetError(client, target_count); return Plugin_Handled; } for (new i = 0; i < target_count; i++) { SetEntityRenderFx(target_list[i], amount); }
if (tn_is_ml) { ShowActivity2(client, "\x04[SM Colour]\x03 ", "%t", "Set render on target", client, target_name, amount); } else { ShowActivity2(client, "\x04[SM Colour]\x03 ", "%t", "Set render on target", "_s", client, target_name, amount); }
return Plugin_Handled;
}
Last edited by diorfo; 09-21-2017 at 23:55.
|
|