Raised This Month: $32 Target: $400
 8% 

[L4D2] Little Help with Cookies and Color Players Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
diorfo
Member
Join Date: Dec 2013
Old 09-21-2017 , 23:53   [L4D2] Little Help with Cookies and Color Players Plugin
Reply With Quote #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_SmColourADMFLAG_CUSTOM2"sm_color <name or #userid> <RED> <GREEN> <BLUE>.");
    
RegAdminCmd("sm_render"Command_SmRenderADMFLAG_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,true0.0true1.0);
}

public 
OnClientPutInServer(client)
{
    if(
IsClientConnected(client) && !IsFakeClient(client) && convarCookies && (GetClientFrags(client) & ADMFLAG_CUSTOM2))
    {
        
CreateTimer(5.0Timer_LoadCookieGetClientUserId(client));
    }    
}

public 
Action Timer_LoadCookie(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);
    
char sModel1[32]; char sModel2[32]; char sModel3[32];

    if(
IsClientConnected(client) && !IsFakeClient(client) && convarCookies)
    {
        
GetClientCookie(clientg_hClientModel1sModel1sizeof(sModel1));
        
GetClientCookie(clientg_hClientModel2sModel2sizeof(sModel2));
        
GetClientCookie(clientg_hClientModel3sModel3sizeof(sModel3));
        
        if(
strlen(sModel1) && strlen(sModel2) && strlen(sModel3))
        {
            
SetEntityRenderColor(clientStringToInt(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(clientargs)
{
    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(2arg2sizeof(arg2));
    if (
StringToIntEx(arg2red) == 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(adminAdmin_Unban))  
        {
            
red 255;
            
red 0;
        }
        else
        {
            
red 255;
        }        
    }    

// #3 Green
    
new green 0;
    
decl String:arg3[20];
    
GetCmdArg(3arg3sizeof(arg3));
    if (
StringToIntEx(arg3green) == 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(adminAdmin_Unban))  
        {
            
green 255;
            
green 0;
        }
        else
        {
            
green 255;
        }        
    }    

// #4 Blue
    
new blue 0;
    
decl String:arg4[20];
    
GetCmdArg(4arg4sizeof(arg4));
    if (
StringToIntEx(arg4blue) == 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(adminAdmin_Unban))  
        {
            
blue 255;
            
blue0;
        }
        else
        {
            
blue 255;
        }        
    }    
        if (
client)
        
SetEntityRenderColor(clientredgreenblue);
        
PrintToChat(client"\x04[SM Colour] \x03You set the color %d %d %d"redgreenblue);
        if (
convarCookies)
        {                
            
char sprop1[32]; IntToString(redsprop132);
            
SetClientCookie(clientg_hClientModel1sprop1);
            
char sprop2[32]; IntToString(greensprop232);
            
SetClientCookie(clientg_hClientModel2sprop2);
            
char sprop3[32]; IntToString(bluesprop332);
            
SetClientCookie(clientg_hClientModel3sprop3);
            
PrintToChat(client"\x04[SM Colour] \x03You stored the colors %d %d %d"g_hClientModel1g_hClientModel2g_hClientModel3);
        }

    return 
Plugin_Handled;
}


////////////////////////////////////////////////////////////////////////
// sm_render
////////////////////////////////////////////////////////////////////////

public Action:Command_SmRender(clientargs)
{
    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(1argsizeof(arg));

        new 
amount 0;
        
decl String:arg2[20];
        
GetCmdArg(2arg2sizeof(arg2));
        if (
StringToIntEx(arg2amount) == 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_countbool: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(clienttarget_count);
        return 
Plugin_Handled;
    }
    
    for (new 
0target_counti++)
    {
        
SetEntityRenderFx(target_list[i], amount);
    }

    if (
tn_is_ml)
    {
        
ShowActivity2(client"\x04[SM Colour]\x03 ""%t""Set render on target"clienttarget_nameamount);
    }
    else
    {
        
ShowActivity2(client"\x04[SM Colour]\x03 ""%t""Set render on target""_s"clienttarget_nameamount);
    }

    return 
Plugin_Handled;



Last edited by diorfo; 09-21-2017 at 23:55.
diorfo is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 09-22-2017 , 07:54   Re: [L4D2] Little Help with Cookies and Color Players Plugin
Reply With Quote #2

I didn't look very closely at your code, but you're printing the value of the cookie handle. This is not the value you store into the cookie. You should be printing your sprop1-3.
Fyren is offline
diorfo
Member
Join Date: Dec 2013
Old 09-22-2017 , 10:58   Re: [L4D2] Little Help with Cookies and Color Players Plugin
Reply With Quote #3

Quote:
Originally Posted by Fyren View Post
I didn't look very closely at your code, but you're printing the value of the cookie handle. This is not the value you store into the cookie. You should be printing your sprop1-3.
I'm not good in cookies but until I understand, the value that is stored in g_hClientModel1-3 is the cookie value that each player read on connect to server (OnClientPutInServer).

The problem until I understand, is that to store a value in cookie I need convert it to string, and after that, I need convert it again in int var to player read it on connect.

Looks like the original value is lost on these conversions.

Anyone good with cookies can give me a clue to solve it?
diorfo is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 09-22-2017 , 19:56   Re: [L4D2] Little Help with Cookies and Color Players Plugin
Reply With Quote #4

Code:
SetClientCookie(client, g_hClientModel1, "1");
PrintToServer("%d", g_hClientModel1);
PrintToServer("%s", g_hClientModel1);
In this example, neither print will (or should) show "1". The handle itself is not the value of the cookie. The only way to get the value stored in the cookie is with GetClientCookie.
Fyren is offline
Reply


Thread Tools
Display Modes

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 09:13.


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