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

Add shop credits


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
szogun
Senior Member
Join Date: Apr 2016
Old 08-07-2019 , 10:20   Add shop credits
Reply With Quote #1

Hey, I have a little problem to add the number of displayed credits in hud

Code:
#include <sourcemod>
#include <cstrike> 
#include <sdktools>
#include <clientprefs>
#include <store>


public Plugin myinfo = 
{
	name = "HUDv2",
	author = "xSLOW",
	description = "Server Hud",
	version = "1.4"
};

enum {
	RED = 0,
	GREEN,
	BLUE
}

ConVar g_cvarMessage1;
ConVar g_cvarMessage2;
ConVar g_cvarMessage3;
ConVar g_cvarSlots;
ConVar g_cvarHUDColors;

Handle g_hHUDv2Cookie;
bool g_bIsHudEnabled[MAXPLAYERS + 1];
int g_iHUDColors[3];


public void OnPluginStart()
{
	g_hHUDv2Cookie = RegClientCookie("HudCookie_V2", "HudCookie_V2", CookieAccess_Protected);

	g_cvarMessage1 = CreateConVar("sm_hud_message1", "Forum: OneFrag.pl", "Top-Left first message", FCVAR_NOTIFY);
	g_cvarMessage2 = CreateConVar("sm_hud_message2", "TS3: OneFrag.pl", "Top-Left second message", FCVAR_NOTIFY);
	g_cvarMessage3 = CreateConVar("sm_hud_message3", "[Wpisz /sklepsms aby kupic Vipa]", "Top-Mid third message", FCVAR_NOTIFY);
	g_cvarSlots = CreateConVar("sm_hud_slots", "32", "Number of server's slots", FCVAR_NOTIFY);
	g_cvarHUDColors = CreateConVar("sm_hud_rgb", "230,57,0", "RGB of the text. You can get more colors from https://www.hexcolortool.com/", FCVAR_NOTIFY);

	AutoExecConfig(true, "HUDv2");

	UpdateHUDColor();
	g_cvarHUDColors.AddChangeHook(cvarChanged_HUDColor);

	CreateTimer(1.0, TIMER, _, TIMER_REPEAT);

	RegConsoleCmd("hud", Command_hud);
}

public void OnClientPutInServer(int client)
{
	g_bIsHudEnabled[client] = true;
	char buffer[64];
	GetClientCookie(client, g_hHUDv2Cookie, buffer, sizeof(buffer));
	if(StrEqual(buffer,"0"))
		g_bIsHudEnabled[client] = false;
}

public void cvarChanged_HUDColor(ConVar convar, const char[] oldValue, const char[] newValue) {
	UpdateHUDColor();
}

public Action Command_hud(int client, int args) 
{
	if(g_bIsHudEnabled[client])
	{
		PrintToChat(client, " ★ \x02HUD is now off");
		g_bIsHudEnabled[client] = false;
		SetClientCookie(client, g_hHUDv2Cookie, "0");
	}
	else
	{
		PrintToChat(client, " ★ \x04HUD is now on");
		g_bIsHudEnabled[client] = true;
		SetClientCookie(client, g_hHUDv2Cookie, "1");
	}
}


public Action TIMER(Handle timer, any client)
{
	int clientCount = 0, iTimeleft;
    int credits = Store_GetClientCredits(client);
	char sTime[64], credits[128], szTime[30], iMessage1[32], iMessage2[32], iMessage3[32], MapTimeLeft[128];

	for (int i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && !IsFakeClient(i))
			++clientCount;
	}

	g_cvarMessage1.GetString(iMessage1, sizeof(iMessage1));
	g_cvarMessage2.GetString(iMessage2, sizeof(iMessage2));
	g_cvarMessage3.GetString(iMessage3, sizeof(iMessage3));

	GetMapTimeLeft(iTimeleft);
	FormatTime(szTime, sizeof(szTime), "%H:%M:%S", GetTime());
	FormatTime(sTime, sizeof(sTime), "%M:%S", iTimeleft);

	for(int i = 1; i <= MaxClients; i++)
	{
		if(g_bIsHudEnabled[i] && IsClientValid(i))
		{
			char iBuffer[1024];
			if(!(iTimeleft > 0))
				Format(MapTimeLeft,sizeof(MapTimeLeft), "Last Round");
			else
				Format(MapTimeLeft,sizeof(MapTimeLeft), "%s", sTime);

			Format(iBuffer, sizeof(iBuffer),"%s\n%s\nGraczy: %d/%d\nGodzina: %s \nKredyty: %d\nDo konca mapy: %s",iMessage1, iMessage2, clientCount, g_cvarSlots.IntValue, credits, MapTimeLeft, szTime);
			SetHudTextParams(0.0, 0.0, 1.02, g_iHUDColors[RED], g_iHUDColors[GREEN], g_iHUDColors[BLUE], 255, 0, 0.0, 0.0, 0.0);  
			ShowHudText(i, -1, iBuffer);  

			SetHudTextParams(-1.0, 0.075, 1.02, g_iHUDColors[RED], g_iHUDColors[GREEN], g_iHUDColors[BLUE], 255, 0, 0.0, 0.0, 0.0);  
			ShowHudText(i, -1, iMessage3);  
		}
	}
}

bool IsClientValid(int client)
{
    return (0 < client <= MaxClients) && IsClientInGame(client) && !IsFakeClient(client);
}

void UpdateHUDColor() {
	char buffer[16];
	g_cvarHUDColors.GetString(buffer, sizeof(buffer));

	char buffer2[3][4];
	ExplodeString(buffer, ",", buffer2, sizeof(buffer2), sizeof(buffer2[]));
	
	for (int i = 0; i < 3; i++) {
		g_iHUDColors[i] = StringToInt(buffer2[i]);
	}
}
HTML Code:
//// hud_message.sp
//
// hud_message.sp(88) : warning 217: loose indentation
// hud_message.sp(89) : warning 217: loose indentation
// hud_message.sp(89) : error 021: symbol already defined: "credits"
// hud_message.sp(88) : warning 204: symbol is assigned a value that is never us
ed: "credits"
// hud_message.sp(6) : warning 203: symbol is never used: "g_cvarChatTag"
//
// 1 Error.
//
// Compilation Time: 0,36 sec
// ----------------------------------------
szogun is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 08-07-2019 , 10:40   Re: Add shop credits
Reply With Quote #2

the both int and char have same name "credits". change one.
farawayf is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 08-07-2019 , 12:52   Re: Add shop credits
Reply With Quote #3

you trying to get char value from int on format. change %s to %i.
farawayf is offline
szogun
Senior Member
Join Date: Apr 2016
Old 08-07-2019 , 13:36   Re: Add shop credits
Reply With Quote #4

It's possible, but I've solved this problem. Now, when the correct number of points appears, I have another problem because the number -1 under the points appears

https://steamcommunity.com/sharedfil...?id=1827918819
https://steamcommunity.com/sharedfil...?id=1827908143

Code:
#pragma semicolon 1

#include <sourcemod>
#include <cstrike> 
#include <sdktools>
#include <clientprefs>
#include <store>

public Plugin myinfo = 
{
	name = "HUDv2",
	author = "xSLOW",
	description = "Server Hud",
	version = "1.4"
};

enum {
	RED = 0,
	GREEN,
	BLUE
}

ConVar g_cvarMessage1;
ConVar g_cvarMessage2;
ConVar g_cvarMessage3;
ConVar g_cvarSlots;
ConVar g_cvarHUDColors;

Handle g_hHUDv2Cookie;
bool g_bIsHudEnabled[MAXPLAYERS + 1];
int g_iHUDColors[3];


public void OnPluginStart()
{
	g_hHUDv2Cookie = RegClientCookie("HudCookie_V2", "HudCookie_V2", CookieAccess_Protected);

	g_cvarMessage1 = CreateConVar("sm_hud_message1", "Forum: OneFrag.pl", "Top-Left first message", FCVAR_NOTIFY);
	g_cvarMessage2 = CreateConVar("sm_hud_message2", "TS3: OneFrag.pl", "Top-Left second message", FCVAR_NOTIFY);
	g_cvarMessage3 = CreateConVar("sm_hud_message3", "Wpisz /sklepsms aby kupic Vipa", "Top-Mid third message", FCVAR_NOTIFY);
	g_cvarSlots = CreateConVar("sm_hud_slots", "13", "Number of server's slots", FCVAR_NOTIFY);
	g_cvarHUDColors = CreateConVar("sm_hud_rgb", "230,57,0", "RGB of the text. You can get more colors from https://www.hexcolortool.com/", FCVAR_NOTIFY);

	AutoExecConfig(true, "HUDv2");

	UpdateHUDColor();
	g_cvarHUDColors.AddChangeHook(cvarChanged_HUDColor);
	RegConsoleCmd("hud", Command_hud);
}

public void OnClientPutInServer(int client)
{
	g_bIsHudEnabled[client] = true;
	char buffer[64];
	GetClientCookie(client, g_hHUDv2Cookie, buffer, sizeof(buffer));
	if(StrEqual(buffer,"0"))
		g_bIsHudEnabled[client] = false;

	CreateTimer(1.0, CreditsTimer, GetClientUserId(client), TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}

public void cvarChanged_HUDColor(ConVar convar, const char[] oldValue, const char[] newValue) {
	UpdateHUDColor();
}

public Action Command_hud(int client, int args) 
{
	if(g_bIsHudEnabled[client])
	{
		PrintToChat(client, " ★ \x02HUD pomyslnie wylaczony");
		g_bIsHudEnabled[client] = false;
		SetClientCookie(client, g_hHUDv2Cookie, "0");
	}
	else
	{
		PrintToChat(client, " ★ \x04HUD pomyslnie wlaczony");
		g_bIsHudEnabled[client] = true;
		SetClientCookie(client, g_hHUDv2Cookie, "1");
	}
}

public Action CreditsTimer(Handle timer, any userid)
{
	int client = GetClientOfUserId(userid);
	int credits = Store_GetClientCredits(client);
	int clientCount = 0, iTimeleft;
	char sTime[64], szTime[30], iMessage1[32], iMessage2[32], iMessage3[32], MapTimeLeft[128];

	for (int i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && !IsFakeClient(i))
			++clientCount;
	}

	g_cvarMessage1.GetString(iMessage1, sizeof(iMessage1));
	g_cvarMessage2.GetString(iMessage2, sizeof(iMessage2));
	g_cvarMessage3.GetString(iMessage3, sizeof(iMessage3));

	GetMapTimeLeft(iTimeleft);
	FormatTime(szTime, sizeof(szTime), "%H:%M:%S", GetTime());
	FormatTime(sTime, sizeof(sTime), "%M:%S", iTimeleft);

	for(int i = 1; i <= MaxClients; i++)
	{
		if(g_bIsHudEnabled[i] && IsValidClient(i))
		{
			char iBuffer[1024];
			if(!(iTimeleft > 0))
				Format(MapTimeLeft,sizeof(MapTimeLeft), "Last Round");
			else
				Format(MapTimeLeft,sizeof(MapTimeLeft), "%s", sTime);

			Format(iBuffer, sizeof(iBuffer),"%s\n%s\nGraczy: %d/%d\nPozostalo: %s\nGodzina: %s\nKredyty: %i",iMessage1, iMessage2, clientCount, g_cvarSlots.IntValue, MapTimeLeft, szTime, credits);
			SetHudTextParams(0.0, 0.0, 0.9, g_iHUDColors[RED], g_iHUDColors[GREEN], g_iHUDColors[BLUE], 255, 0, 0.0, 0.0, 0.0);  
			ShowHudText(i, -1, iBuffer);  

			SetHudTextParams(-1.0, 0.075, 0.9, g_iHUDColors[RED], g_iHUDColors[GREEN], g_iHUDColors[BLUE], 255, 0, 0.0, 0.0, 0.0);  
			ShowHudText(i, -1, iMessage3);  
		}
	}
}

stock bool IsValidClient(client, bool nobots = true)
{ 
    if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
    {
        return false; 
    }
    return IsClientInGame(client); 
}

void UpdateHUDColor() {
	char buffer[16];
	g_cvarHUDColors.GetString(buffer, sizeof(buffer));

	char buffer2[3][4];
	ExplodeString(buffer, ",", buffer2, sizeof(buffer2), sizeof(buffer2[]));
	
	for (int i = 0; i < 3; i++) {
		g_iHUDColors[i] = StringToInt(buffer2[i]);
	}
}
szogun is offline
Reply



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 12:23.


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