PDA

View Full Version : [CS:GO] The HUD Works, but is it done correctly?


aexi0n
11-03-2014, 17:47
I've recently been developing my own bhop plugin, and recently I've came to the part where I'd like the users to have their own HUD. After research, I did the usual 'PrintHintText' method, and everything works really well. EXCEPT, I've began to second guess my code:


#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

#pragma semicolon 1

public Plugin:myinfo =
{
name = "Paradise BunnyHop Timer",
author = "Aexi0n",
description = "Official Bhop Timer for Paradise Servers",
version = "0.1",
url = ""
}
public OnClientPutInServer(client)
{
CreateTimer(0.5, HUD, client, TIMER_REPEAT);
}
public Action:HUD(Handle:timer, any:client)
{
if(IsClientConnected(client) && IsClientInGame(client))
{
PrintHintText(client, "[Lv. %d] %N XP: 0/100\n Time: 0:00:00 \n Speed: ", Level[client], client);
}
}

(Just ignore the % variables, this isn't the entire script.)
After further review, I think I may be creating a timer for every client, and if I'm right I don't think that is a good thing to do. Could somebody review my code, and see if this is a safe, and reliable way to create the HUD? If it is indeed a bad way to do it, I'd also appreciate any insight as to what changes need to be made for it to work safely. Thank you!

lingzhidiyu
11-04-2014, 03:48
i will use like this

public OnPluginStart()
{
CreateTimer(0.1, HUD, _, TIMER_REPEAT);
}

public Action:HUD(Handle:timer)
{
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(client) && IsPlayerAlive(client))
{
PrintHintText(client, "[Lv. %d] %N XP: 0/100\n Time: 0:00:00 \n Speed: ", Level[client], client);
}
}
}

iGANGNAM
11-04-2014, 10:20
When Hint didn't work anyway? Center text and right side text only don't work anymore on csgo.
Hint just have limitation to few lines. Look to this https://forums.alliedmods.net/showthread.php?t=242758

Safe or not... I think timers should be killed, for example on client disconnect?

aexi0n
11-05-2014, 00:26
lingzhidiyu, that does seem a lot more efficient as it is only using a single timer, but upon compiling the code it doesn't recognize client as being a defined symbol.

Both of these lines reference the client, but I'm not sure why the for loop isn't defining one:

if (IsClientInGame(client) && IsPlayerAlive(client))

and

PrintHintText(client, "[Lv. %d] %N XP: 0/100\n Time: 0:00:00 \n Speed: ", Level[client], client);

Neuro Toxin
11-05-2014, 01:16
Change client to i

aexi0n
11-05-2014, 10:36
Change client to i

Awesome! Thanks! For readability sake, would it be a good practice to change i to client instead of vice versa? I know using 'i' comes from the standard for loops in most languages, but is this the correct thing to do? Maybe using 'i' is more efficient since it's only a 1 character string? Really confused here :3


public Action:HUD(Handle:timer)
{
for (new client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client) && IsPlayerAlive(client))
{
PrintHintText(client, "[Lv. %d] %N XP: 0/100\n Time: 0:00:00 \n Speed: ", Level[client], client);
}
}
}

Neuro Toxin
11-05-2014, 15:20
I'm no expert. But I would agree about readability.

Stack variable names wont effect performance. I could be wrong.

Powerlord
11-05-2014, 17:14
The problem with naming it "client" is that commands usually look like this:

public Action:CommandHere(client, args)

...so client is the name of a variable already.