[TUT] HUD Position and Coloring Configuration Menu
Jun 22, 2018 18:55:36 GMT
zmd94 and lindi like this
Post by ZinoZack47 on Jun 22, 2018 18:55:36 GMT
Hello and Welcome to this tutorial which is about how to add hud configuration to your main zp43 script.
First I want to thank Game Over Leecho because he is the main reason that I made this tutorial.
Let's get strated:
first you must go search for
and put this under it
this is very important because when your client configs his hud, it needs to be saved otherwise every time he connects to the server he will have to edit the hud over and over again and this ain't cool.
fvault is more effecient for saving data and it only requires the .inc file
fvault.inc (12.81 KB)
second under
Add
After that search for
and put this in the next line
Ok Now Search for
and on the next line put
Nice, Now Part one Over. Now For part two
First search for
and add these two lines
Second search for
and put this after its line
So far so good Part two is Over, Let's move on to the main part which is three
Now Search for Search for
find this line
and add this
After that Search for
now add the following function to make sure it looks like this
Alright, now search for
and put the following two functions to make sure it looks like kinda this
OK We are close now, so now search for
and add the following functions to make it look like this
For for the Last Step Search for
it looks like kinda this
and replace this
with this
so it can look like this
Questions
Why my favourite colour isn't on the menu?
Because it ain't compatible with the hud.
Why am I getting warnings?
Because you didnt indent you goddamn code.
How Can I disable the Coloring?
find this #define COLOR and make it look like this //#define COLOR
How can I make my hud refresh instantly?
first go here
and make it look like this
then go here
and change 1.1 to 0.2
I am Getting Compiling Errors. What should I do?
Post your sma and error log in this thread and tag Zino
How can I show some gratitude?
Just give a karma
Can I ask other questions other than in this topic?
No, Make a thread or Use Google
First I want to thank Game Over Leecho because he is the main reason that I made this tutorial.
Let's get strated:
Most important thing to do is to follow this tutorial very carefully, make a backup for your sma and don't modify a damn thing until it is over.
Remember to indent your code so you cannot fall in warnings
#include <xs>
and put this under it
#include <fvault>
this is very important because when your client configs his hud, it needs to be saved otherwise every time he connects to the server he will have to edit the hud over and over again and this ain't cool.
fvault is more effecient for saving data and it only requires the .inc file
fvault.inc (12.81 KB)
second under
#include <fvault>
Add
#define CHOICE 0 //SAVING Method 0 For Name, 1 for STEAM_ID and 2 for IP Adress
#define COLOR //If you dont want to add the color menu just add // before the #define
After that search for
new const PLUGIN_VERSION[]
and put this in the next line
#if defined COLOR
new const g_vault_name[] = "HUDConfigColor"
#else
new const g_vault_name[] = "HUDConfig"
#endif
Ok Now Search for
new Float:g_buytime[33]
and on the next line put
new Float:g_HUD[33][2] //for Hud Positioning
#if defined COLOR
new g_HUDCOLOR[33][3] //for Hud Coloring
#endif
Nice, Now Part one Over. Now For part two
First search for
register_clcmd("jointeam", "clcmd_changeteam")
and add these two lines
register_clcmd("say hud", "clcmd_sayhud")
register_clcmd("say /hud", "clcmd_sayhud")
Second search for
register_menu("Admin Modes Menu", KEYSMENU, "menu_modes_admin")
and put this after its line
register_menu("Hud Menu", KEYSMENU, "menu_hud") //Use old menu Style no problem, let's play along with it
#if defined COLOR
register_menu("HudColor Menu", KEYSMENU, "menu_hud_color")
#endif
So far so good Part two is Over, Let's move on to the main part which is three
Now Search for Search for
public client_putinserver(id)
find this line
set_task(5.0, "disable_minmodels", id)
and add this
//Load The Hud Config Data
vault_loaddata(id)
After that Search for
public clcmd_changeteam(id)
now add the following function to make sure it looks like this
public clcmd_changeteam(id)
{
static team
team = fm_cs_get_user_team(id)
// Unless it's a spectator joining the game
if (team == FM_CS_TEAM_SPECTATOR || team == FM_CS_TEAM_UNASSIGNED)
return PLUGIN_CONTINUE;
// Pressing 'M' (chooseteam) ingame should show the main menu instead
show_menu_game(id)
return PLUGIN_HANDLED;
}
public clcmd_sayhud(id)
{
show_menu_hud(id)
}
Alright, now search for
public menu_game(id, key)
and put the following two functions to make sure it looks like kinda this
show_menu_hud(id)
{
if(!g_isconnected[id])
return
static menu[512], len
len = 0
// Title
len += formatex(menu[len], charsmax(menu) - len, "\y-=[\rZP\y]-=\w Welcome to the \yHUD\r Adjustment\w Menu^nConfigure \rHUD \w: ^n^n")
//1. Move the hud up
len += formatex(menu[len], charsmax(menu) - len, "\y|\r1\y|\w.\r UP^n")
//2. Move the hud down
len += formatex(menu[len], charsmax(menu) - len, "\y|\r2\y|\w.\r DOWN^n")
//3. Move the hud to center between up and down
len += formatex(menu[len], charsmax(menu) - len, "\y|\r3\y|\w.\r Center \y(between UP and Down)^n")
//4. Move the hud left
len += formatex(menu[len], charsmax(menu) - len, "\y|\r4\y|\w.\r LEFT^n")
//5. Move the hud Right
len += formatex(menu[len], charsmax(menu) - len, "\y|\r5\y|\w.\r RIGHT^n")
//6. Move the hud to center between right and left
len += formatex(menu[len], charsmax(menu) - len, "\y|\r6\y|\w.\r Center \y(between Right and Left)^n")
#if defined COLOR
//7. Change Hud Color
len += formatex(menu[len], charsmax(menu) - len, "\y|\r7\y|\w.\r Color \yConfiguration^n")
#endif
// 0. Exit
len += formatex(menu[len], charsmax(menu) - len, "^n^n\r|\y0\y|\r. %L", id, "MENU_EXIT")
// Fix for AMXX custom menus
if (pev_valid(id) == PDATA_SAFE)
set_pdata_int(id, OFFSET_CSMENUCODE, 0, OFFSET_LINUX)
show_menu(id, KEYSMENU, menu, -1, "Hud Menu")
}
#if defined COLOR
show_menu_color(id)
{
if(!g_isconnected[id])
return
static menu[512], len
len = 0
// Title
len += formatex(menu[len], charsmax(menu) - len, "\y-=[\rZP\y]-=\w Welcome to the \yHUD\r Adjustment\w Menu^nConfigure \rHUD \yColor\w: ^n^n")
//1. Change Color to white
len += formatex(menu[len], charsmax(menu) - len, "\y|\r1\y|\w.\y White^n")
//2. Change Color to blue
len += formatex(menu[len], charsmax(menu) - len, "\y|\r2\y|\w.\y Blue^n")
//3. Change Color to green
len += formatex(menu[len], charsmax(menu) - len, "\y|\r3\y|\w.\y Green^n")
//4. Change Color to red
len += formatex(menu[len], charsmax(menu) - len, "\y|\r4\y|\w.\y Red^n")
//5. Change Color to yellow
len += formatex(menu[len], charsmax(menu) - len, "\y|\r5\y|\w.\y Yellow^n")
//6. Change Color to Pink
len += formatex(menu[len], charsmax(menu) - len, "\y|\r6\y|\w.\y Pink^n")
//7. Change Color to PoolBlue
len += formatex(menu[len], charsmax(menu) - len, "\y|\r7\y|\w.\y PoolBlue^n")
//8. Generate a Color
len += formatex(menu[len], charsmax(menu) - len, "\y|\r9\y|\w.\r Random Coloring^n")
// 0. Exit
len += formatex(menu[len], charsmax(menu) - len, "^n^n\r|\y0\y|\r. %L", id, "MENU_EXIT")
// Fix for AMXX custom menus
if (pev_valid(id) == PDATA_SAFE)
set_pdata_int(id, OFFSET_CSMENUCODE, 0, OFFSET_LINUX)
show_menu(id, KEYSMENU, menu, -1, "HudColor Menu")
}
#endif
/*================================================================================
[Menu Handlers]
=================================================================================*/
// Game Menu
public menu_game(id, key)
{
....
OK We are close now, so now search for
public menu_cs_buy(id, key)
and add the following functions to make it look like this
// CS Buy Menus
public menu_cs_buy(id, key)
{
// Prevent buying if zombie/survivor (bugfix)
if (g_zombie[id] || g_survivor[id] || g_sniper[id])
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public menu_hud(id, key)
{
if(!is_user_connected(id))
return PLUGIN_HANDLED
new Float:g_border = 0.5 //The Bigger your hud the smaller this value should be. adjust this so whenever you keep moving the hud right until it reachs the border it goes left automatically
switch(key)
{
case 0:
{
if(g_HUD[id][1] <= 0.0)
g_HUD[id][1] = 1.0
else
g_HUD[id][1] -= 0.01
show_menu_hud(id)
}
case 1:
{
if(g_HUD[id][1] >= 1.0 || g_HUD[id][1] <= -1.0)
g_HUD[id][1] = 0.0
else
g_HUD[id][1] += 0.01
show_menu_hud(id)
}
case 2:
{
g_HUD[id][1] = -1.0
show_menu_hud(id)
}
case 3:
{
if(g_HUD[id][0] <= 0.0)
g_HUD[id][0] = g_border
else
g_HUD[id][0] -= 0.01
show_menu_hud(id)
}
case 4:
{
if(g_HUD[id][0] >= g_border || g_HUD[id][1] <= -1.0)
g_HUD[id][0] = 0.0
else
g_HUD[id][0] += 0.01
show_menu_hud(id)
}
case 5:
{
g_HUD[id][0] = -1.0
show_menu_hud(id)
}
#if defined COLOR
case 6: show_menu_color(id)
#endif
}
vault_savedata(id)
return PLUGIN_HANDLED
}
#if defined COLOR
public menu_hud_color(id, key)
{
if(!is_user_connected(id))
return PLUGIN_HANDLED
switch(key)
{
case 0: g_HUDCOLOR[id][0] = 255, g_HUDCOLOR[id][1] = 255, g_HUDCOLOR[id][2] = 255
case 1: g_HUDCOLOR[id][0] = 0, g_HUDCOLOR[id][1] = 0, g_HUDCOLOR[id][2] = 255
case 2: g_HUDCOLOR[id][0] = 0, g_HUDCOLOR[id][1] = 255, g_HUDCOLOR[id][2] = 0
case 3: g_HUDCOLOR[id][0] = 255, g_HUDCOLOR[id][1] = 0, g_HUDCOLOR[id][2] = 0
case 4: g_HUDCOLOR[id][0] = 255, g_HUDCOLOR[id][1] = 255, g_HUDCOLOR[id][2] = 0
case 5: g_HUDCOLOR[id][0] = 255, g_HUDCOLOR[id][1] = 0, g_HUDCOLOR[id][2] = 255
case 6: g_HUDCOLOR[id][0] = 0, g_HUDCOLOR[id][1] = 255, g_HUDCOLOR[id][2] = 255
case 7: g_HUDCOLOR[id][0] = random(255), g_HUDCOLOR[id][1] = random(255), g_HUDCOLOR[id][2] = random(255), show_menu_color(id)
}
vault_savedata(id)
return PLUGIN_HANDLED
}
#endif
vault_loaddata(id)
{
new info[64], data[64], HUDX[4], HUDY[4]
switch(CHOICE)
{
case 0: get_user_name(id, info, charsmax(info))
case 1: get_user_authid(id, info, charsmax(info))
case 2: get_user_ip(id, info, charsmax(info))
}
if(!fvault_get_data(g_vault_name, info, data, charsmax(data)))
{
g_HUD[id][0] = HUD_STATS_X
g_HUD[id][1] = HUD_STATS_Y
#if defined COLOR
g_HUDCOLOR[id][0] = 255
g_HUDCOLOR[id][1] = 255
g_HUDCOLOR[id][2] = 255
#endif
return
}
#if defined COLOR
new red[4], green[4], blue[4]
parse(data, HUDX, charsmax(HUDX), HUDY, charsmax(HUDY), red, charsmax(red), green, charsmax(green), blue, charsmax(blue))
g_HUDCOLOR[id][0] = str_to_num(red)
g_HUDCOLOR[id][1] = str_to_num(green)
g_HUDCOLOR[id][0] = str_to_num(blue)
#else
parse(data, HUDX, charsmax(HUDX), HUDY, charsmax(HUDY))
#endif
g_HUD[id][0] = str_to_float(HUDX)
g_HUD[id][1] = str_to_float(HUDY)
}
vault_savedata(id)
{
new info[64], data[64]
switch(CHOICE)
{
case 0: get_user_name(id, info, charsmax(info))
case 1: get_user_authid(id, info, charsmax(info))
case 2: get_user_ip(id, info, charsmax(info))
}
#if defined COLOR
formatex(data, charsmax(data), "%f %f %d %d %d", g_HUD[id][0], g_HUD[id][1], g_HUDCOLOR[id][0], g_HUDCOLOR[id][1], g_HUDCOLOR[id][2])
#else
formatex(data, charsmax(data), "%f %f", g_HUD[id][0], g_HUD[id][1])
#endif
fvault_set_data(g_vault_name, info, data)
}
For for the Last Step Search for
set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
it looks like kinda this
else
{
// Show health, class and ammo packs
set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync2, "%L: %d - %L %s - %L %d", id, "ZOMBIE_ATTRIB1", pev(ID_SHOWHUD, pev_health), ID_SHOWHUD, "CLASS_CLASS", class, ID_SHOWHUD, "AMMO_PACKS1", g_ammopacks[ID_SHOWHUD])
}
and replace this
set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
with this
#if defined COLOR
red = g_HUDCOLOR[id][0]
green = g_HUDCOLOR[id][1]
blue = g_HUDCOLOR[id][2]
#endif
set_hudmessage(red, green, blue, g_HUD[id][0], g_HUD[id][1], 0, 6.0, 1.1, 0.0, 0.0, -1)
so it can look like this
else
{
#if defined COLOR
red = g_HUDCOLOR[id][0]
green = g_HUDCOLOR[id][1]
blue = g_HUDCOLOR[id][2]
#else
set_hudmessage(red, green, blue, g_HUD[id][0], g_HUD[id][1], 0, 6.0, 1.1, 0.0, 0.0, -1)
#endif
ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync2, "%L: %d - %L %s - %L %d", id, "ZOMBIE_ATTRIB1", pev(ID_SHOWHUD, pev_health), ID_SHOWHUD, "CLASS_CLASS", class, ID_SHOWHUD, "AMMO_PACKS1", g_ammopacks[ID_SHOWHUD])
}
Questions
Why my favourite colour isn't on the menu?
Because it ain't compatible with the hud.
Why am I getting warnings?
Because you didnt indent you goddamn code.
How Can I disable the Coloring?
find this #define COLOR and make it look like this //#define COLOR
How can I make my hud refresh instantly?
first go here
set_task(1.0, "ShowHUD", id+TASK_SHOWHUD, _, _, "b")
and make it look like this
set_task(0.1, "ShowHUD", id+TASK_SHOWHUD, _, _, "b")
then go here
set_hudmessage(red, green, blue, g_HUD[id][0], g_HUD[id][1], 0, 6.0, 1.1, 0.0, 0.0, -1)
and change 1.1 to 0.2
I am Getting Compiling Errors. What should I do?
Post your sma and error log in this thread and tag Zino
How can I show some gratitude?
Just give a karma
Can I ask other questions other than in this topic?
No, Make a thread or Use Google