Forum

> > CS2D > Scripts > Hudtxt unexpected behavior
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hudtxt unexpected behavior

15 replies
To the start Previous 1 Next To the start

old Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
This function is running in a loop (hook second).

Can someone point out why it shows hud like this:


I expect everyone to see the same HUD but half of it is missing in guest client. Where did I make a mistake?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local vert = 0
local hudnr = 0
for i = 1, 30 do parse('hudtxt '..i) end
for i = 1, 32 do
    if player(i,'exists') then
        parse('hudtxt2 '..i..' 35 "©255255255[FLAGS] 1.Game Started[©100255100'..flag[1]..'©255255255]' .. ' 2.Break[©100255100'..flag[2]..'©255255255]' .. ' 3.Lock Sv[©100255100'..flag[3]..'©255255255]' .. ' 4.Voting Active[©100255100'..flag[4]..'©255255255]' .. ' 5.Ready for MM[©100255100'..flag[5]..'©255255255]" 10 15 0 0 12')
        parse('hudtxt2 '..i..' 36 "©255255255[INFO-6] 1.Half[©100255100'..info[1]..'©255255255]' .. ' 2.TeamA Score[©100255100'..info[2]..'©255255255]' .. ' 3.TeamB score[©100255100'..info[3]..'©255255255]' .. ' 4.Match Format[©100255100'..info[4]..'©255255255]' .. ' 5.Max Rounds[©100255100'..info[5]..'©255255255]' .. ' 6.Match Winner[©100255100'..info[6]..'©255255255]" 10 30 0 0 12')
        parse('hudtxt2 '..i..' 37 "©255255255[INFO-13] 7.Active Voters[©100255100'..info[7]..'©255255255]' .. ' 8.Required Votes[©100255100'..info[8]..'©255255255]' .. ' 9.Voting Result[©100255100'..info[9]..'©255255255]' .. ' 10.Leaver PID[©100255100'..info[10]..'©255255255]' .. ' 11.Leaver Rank[©100255100'..info[11]..'©255255255]' .. ' 12.Leaver Kills[©100255100'..info[12]..'©255255255]' .. ' 13.Leaver Deaths[©100255100'..info[13]..'©255255255]" 10 45 0 0 12')
        parse('hudtxt2 '..i..' 38 "©255255255[GLOBAL] min_rank[©100255100'..min_rank..'©255255255]' .. ' SvPrepared[©100255100'..SERVER_READY_FOR_ACTION..'©255255255]' .. ' countdown[©100255100'..countdown..'©255255255]' .. ' player1[©100255100'..player1..'©255255255]' .. ' player2[©100255100'..player2..'©255255255]' .. ' team_a[©100255100'..team_a..'©255255255]' .. ' team_b[©100255100'..team_b..'©255255255]" 10 60 0 0 12')
        

        vert = 80
        hudnr = 1
        for k = 1, 32 do
            if player(k,'exists') then
                parse('hudtxt2 '..i..' '..hudnr..' "©255255255['..player(k,'name')..'] PID[©100255100'..PID[k]..'©255255255]' .. ' Rating[©100255100'..rating[k]..'©255255255]' .. ' New Rating[©100255100'..new_rating[k]..'©255255255]' .. ' Admin[©100255100'..admin[k]..'©255255255]' .. ' ban[©100255100'..ban[k]..'©255255255]' .. ' Vote[©100255100'..vote[k]..'©255255255]" 10 '..vert..' 0 0 12')
                vert = vert + 15 hudnr = hudnr + 1
                parse('hudtxt2 '..i..' '..hudnr..' "©255255255['..player(k,'name')..'] Team[©100255100'..participant[k]..'©255255255]' .. ' Kills[©100255100'..kills[k]..'©255255255]' .. ' Assists[©100255100'..assists[k]..'©255255255]' .. ' Deaths[©100255100'..deaths[k]..'©255255255]' .. ' Performance[©100255100'..performance[k]..'©255255255]' .. ' Total_DMG[©100255100'..total_damage[k]..'©255255255] /////' .. ' BG1[©100255100'..BG1[k]..'©255255255]' .. ' BG2[©100255100'..BG2[k]..'©255255255]' .. ' BG3[©100255100'..BG3[k]..'©255255255]' .. ' BG4[©100255100'..BG4[k]..'©255255255]' .. ' BG5[©100255100'..BG5[k]..'©255255255]" 10 '..vert..' 0 0 12')
                vert = vert + 20 hudnr = hudnr + 1
            end
        end
    end
end

old Re: Hudtxt unexpected behavior

Yates
Reviewer Off Offline

Quote
You're a big fan of loops.

All of these hud's have no information specific to one player only. Make them all cs2d cmd hudtxt instead. Then all you need to do is loop over the players to get their information and share it with others.

By the way:
1
2
3
4
local playerlist=player(0,"table")
for _,id in pairs(playerlist) do
   print(player(id,"name"))
end
As shown in cs2d lua cmd player at the bottom. Stop using
for i = x, y do
for players

old Re: Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
Thanks for the insight but I tried everything you mentioned except players table, which would improve performance I guess.

If you check my screenshot, you will notice that half of hudtxt disappears just like hudtxt2. What causes that behavior?

old Re: Hudtxt unexpected behavior

Yates
Reviewer Off Offline

Quote
It's probably because your loop takes so long that a second passes and the next loop is triggered removing a portion of the already set hud's or the ID's are used where you would expect them not to.

Show me your new code that only uses cs2d cmd hudtxt

old Re: Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
I was testing with huge loops covering whole screen with full 49 limit and an image on top of that running in ms100 mode so this little debug screen can not give me trouble because of performance... Maybe it treats hudnr as global var or something?

1
2
3
4
5
6
7
8
9
10
local vert = 95
    local hudnr = 1
    for k = 1, 32 do
        if player(k,'exists') then
            parse('hudtxt '..hudnr..' "©255255255['..player(k,'name')..'] PID[©100255100'..PID[k]..'©255255255]' .. ' Rating[©100255100'..rating[k]..'©255255255]' .. ' New Rating[©100255100'..new_rating[k]..'©255255255]' .. ' Admin[©100255100'..admin[k]..'©255255255]' .. ' ban[©100255100'..ban[k]..'©255255255]' .. ' Vote[©100255100'..vote[k]..'©255255255]" 10 '..vert..' 0 0 12')
            vert = vert + 15 hudnr = hudnr + 1
            parse('hudtxt '..hudnr..' "©255255255['..player(k,'name')..'] Team[©100255100'..participant[k]..'©255255255]' .. ' Kills[©100255100'..kills[k]..'©255255255]' .. ' Assists[©100255100'..assists[k]..'©255255255]' .. ' Deaths[©100255100'..deaths[k]..'©255255255]' .. ' Performance[©100255100'..performance[k]..'©255255255]' .. ' DMG[©100255100'..dmg[k]..'©255255255]' .. ' Total_DMG[©100255100'..total_damage[k]..'©255255255] /////' .. ' BG1[©100255100'..BG1[k]..'©255255255]' .. ' BG2[©100255100'..BG2[k]..'©255255255]' .. ' BG3[©100255100'..BG3[k]..'©255255255]' .. ' BG4[©100255100'..BG4[k]..'©255255255]' .. ' BG5[©100255100'..BG5[k]..'©255255255]" 10 '..vert..' 0 0 12')
            vert = vert + 20 hudnr = hudnr + 1
        end
    end

old Re: Hudtxt unexpected behavior

Yates
Reviewer Off Offline

Quote
What if you try updating the hud only once per minute. Just to see if it goes wrong or not?

If something goes wrong; it's in the function. If it works correctly; it's an outside source (or the same function being triggered too fast).

old Re: Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
We are both overthinking lol.
I started narrowing down the cause and it seems it is one of the colors, although I can not find which one exactly.

Here, I removed all colors form 37th hud, which was hidden for guests and now it is working correctly:
1
2
3
4
parse('hudtxt 37 "[INFO-13] 7.Active Voters['..info[7]..'] 8.Required Votes['..info[8]..'] 9.Voting Result['..info[9]..'] 10.Leaver PID['..info[10]..'] 11.Leaver Rank['..info[11]..'] 12.Leaver Kills['..info[12]..'] 13.Leaver Deaths['..info[13]..']" 10 45 0 0 12')

Broken HUD:
parse('hudtxt2 '..i..' 37 "©255255255[INFO-13] 7.Active Voters[©100255100'..info[7]..'©255255255]' .. ' 8.Required Votes[©100255100'..info[8]..'©255255255]' .. ' 9.Voting Result[©100255100'..info[9]..'©255255255]' .. ' 10.Leaver PID[©100255100'..info[10]..'©255255255]' .. ' 11.Leaver Rank[©100255100'..info[11]..'©255255255]' .. ' 12.Leaver Kills[©100255100'..info[12]..'©255255255]' .. ' 13.Leaver Deaths[©100255100'..info[13]..'©255255255]" 10 45 0 0 12')


But no matter how much I look into it, all color codes seem fine. And it is fine for the player who hosts server

Edit: I added colors back and it is invisible again for guests


Edis2: Ok we need DC to confirm this, I think there is a limit of text in parse command... I noticed that only the longest lines are not showing up so I did this:
1
parse('hudtxt 43 "©255255255[INFO-13] 7.Active Voters[©100255100'..info[7]..'©255255255] 8.Required Votes[©100255100'..info[8]..'©255255255] 9.Voting Result[©100255100'..info[9]..'©255255255] 10.Leaver PID[©100255100'..info[10]..'©255255255] 11.Leaver Rank[©100255100'..info[11]..'] 12.Leaver Kills['..info[12]..'] 13.Leaver Deaths['..info[13]..']" 10 45 0 0 12')

And now it works for everyone. WTF
edited 1×, last 28.06.18 03:36:19 pm

old Re: Hudtxt unexpected behavior

Yates
Reviewer Off Offline

Quote
Lol. May be a long shot, but change all the block brackets to normal brackets and see if it is still broken.

You should also be using
\169
instead of the copyright sign.

Edit: Lol you've got
' .. '
everywhere in that hud.

old Re: Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
It is just a debug HUD so I made little markers for adding new values easier

Look at this, I remade all huds to be shorter ... And changing nick name to longer affects the shortest line



Code:
Spoiler >

old Re: Hudtxt unexpected behavior

Yates
Reviewer Off Offline

Quote
Hud 41 to 46 don't need to be in the loop as far as I can see. Your
hudnr
could also amount up to above 40 so resetting just those won't do. In fact your
hudnr
could go up to 96, which is 46 above the limit

But if it's just debugging, meh. Whatever

old Re: Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
Yeah I can see such simple things, gonna fix them after I'm sure what is the limit of parse line because it can make troubles when creating a colorful text - I will see everything correctly but when the time comes to upload script to dedicated sv people will get errors

old Re: Hudtxt unexpected behavior

DC
Admin Off Offline

Quote
cs2d lua cmd parse has no length limitation. At least I couldn't find one in the code. There probably is one at some point in Lua etc. but it should be waaay higher.

There are however some other limitations:
• parse stops at the first semicolon (unless you tell it not to with the second parameter)
• CS2D parses max 9 commands per invocation of parse and then cancels even if there's more
• some commands may cancel parsing to avoid exploits/spam

When executing a single cs2d cmd hudtxt or cs2d cmd hudtxt2 per parse none of this shouldn't be a problem. Expect for the semicolon thing. Make sure that you either have no semicolons or that you set the second parameter of parse to false. Be aware that ignoring the semicolon is a security risk, especially when displaying any string values which have been entered by users.

Do the long lines work if you execute them on their own, not together with the other ones?

Also a line which exceeds the MTU (~1024 bytes in most environments/setups MINUS bytes for IP & UDP & CS2D header data which should be way less than 100 bytes) will also cause issues as CS2D has no packet splitting (see "Network Library Progress" at http://stranded3.com/index.php?entry=77 for details). Your lines don't look like they should hit that limit though.

old Re: Hudtxt unexpected behavior

Quattro
GAME BANNED Off Offline

Quote
1
parse('hudtxt 1 "©100255100['..flag[1]..'©255255255]©100255100['..flag[1]..'©255255255]©100255100['..flag[1]..'©255255255]©100255100['..flag[1]..'©255255255]//////©255255255[FLAGS] 1.Game Started[©100255100'..flag[1]..'©255255255] 2.Break[©100255100'..flag[2]..'©255255255] 3.Lock Sv[©100255100'..flag[3]..'©255255255] 4.Voting Active[©100255100'..flag[4]..'©255255255] 5.Ready for MM[©100255100'..flag[5]..'©255255255]" 10 15 0 0 12')

Here, if I delete text in front until ////// it works.
If you just use this full line with flag[nr] variables containing 0 it will didapear on guest clients

old Re: Hudtxt unexpected behavior

VADemon
User Off Offline

Quote
First of all, your loops make no sense. Line 3: no need to force-clear hudtxts because you rewrite them in the loop anyway from what I see.
2nd: You don't need to write global hudtxts in loop per player (line 6-11). It should be outside of loop
Lines 18,20,22: very bad coding style; to increase to variables in one line without visually separating them at least with a semi-colon ;

As to why the hudtxt is missing: user DC was very close to the answer: It's not MTU I think, your text for the hudtxt is longer than 255 chars (1-byte) that is used for messages in cs2d. Yes, color codes eat up text space.
Haven't you ever noticed truncated chat messages?

old Re: Hudtxt unexpected behavior

DC
Admin Off Offline

Quote
Actually texts in CS2D are sometimes encoded with a byte for the length and sometimes with a short. A short would mean - in theory - max 65,535 chars. I thought that hudtxt(2) is using a short for length encoding but maybe I'm wrong.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview