AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hud Messages... (https://forums.alliedmods.net/showthread.php?t=12755)

BioHazardousWaste 04-23-2005 20:29

Hud Messages...
 
Hey guys, i'm just wondering if anyone has an idea why this hud message won't show when teh debug under it does show?

Code:
        if (PlayerExp[id] >= ExperienceForLevel[PlayerLevel[id]+1])         {             PlayerLevel[id] += 1                         set_hudmessage(255, 255, 255, 2.0, 1.0, 1, 6.0, 15.0, 0.1, 0.2, 4)             show_hudmessage(0, "Congratulations on achieving level #%i", PlayerLevel[id])//doesn't show             PlayerMaxFocus[id] = PlayerLevel[id] +10             PlayerFocus[id] = PlayerMaxFocus[id]             //debug             client_print(id, print_console, "Player #%i reached level #%i", id, PlayerLevel[id])//shows             CheckLevel(id)         }

v3x 04-23-2005 21:03

Try using format(), see if that helps.

xeroblood 04-23-2005 21:57

Yes, v3x is right, the show_hudmessage() function doesn't accept (and parse) variable arguments after the string (like format() does), so you will have to format your string first, and then pass the end-result string to show_hudmessage()

BioHazardousWaste 04-23-2005 22:02

Ok.. so here's what confuses me the most:

When I play alone, it works fine... when I play with someone else, it's all screwey. Now I found the problem with my write message thing. It was because I was sending it to people who didn't exists. I had it in a for loop 1 - 32. I added the check is_user_alive to all my code, so that should a) cut out unnecessary code, and b) hopefully fix this problem too.

teame06 04-23-2005 22:10

Quote:

Originally Posted by BioHazardousWaste
Ok.. so here's what confuses me the most:

When I play alone, it works fine... when I play with someone else, it's all screwey. Now I found the problem with my write message thing. It was because I was sending it to people who didn't exists. I had it in a for loop 1 - 32. I added the check is_user_alive to all my code, so that should a) cut out unnecessary code, and b) hopefully fix this problem too.

Question.

what code are you using to loop 1 - 32? something similar?

Code:
new maxplayers = get_maxplayers() new j for(j=1; j <= maxplayers; j++) {     // Code Something here? }

BioHazardousWaste 04-23-2005 22:19

Ok.. wtf? I was just playing a lone and it worked fine, some random asshole (not really i'm just upset) joined then it doesn't work... Relevant code follows:

Code:
public DoNewRound() {         for(new i=1;i<=32;i++)         {       if(is_user_alive(i))             //debug             client_print(0, print_console, "Testing player #%i", i)                     RefreshExperience(i)             CheckLevel(i)             UpdateFocus(i)         } } public RefreshExperience(id) {     //kaput (gebroken) lol     new ExpMessage[128]     format(ExpMessage, 127, "Exp: %i / %i", PlayerExp[id], ExperienceForLevel[PlayerLevel[id] + 1])         message_begin(MSG_ONE, get_user_msgid("StatusText"), {0, 0, 0}, id);     write_byte(0);     write_string(ExpMessage);     message_end(); }//works fine public CheckLevel(id) {     //debug     client_print(0, print_console, "Checking player %i's level (%i) exp", id, PlayerExp[id])     if (PlayerLevel[id]<100)     {           if (PlayerExp[id] >= ExperienceForLevel[PlayerLevel[id]+1])         {             PlayerLevel[id] += 1                         set_hudmessage(255, 255, 255, 2.0, 1.0, 1, 6.0, 15.0, 0.1, 0.2, 4)             show_hudmessage(id, "Congratulations on achieving level #%i", PlayerLevel[id])//broken             PlayerMaxFocus[id] = PlayerLevel[id] +10             PlayerFocus[id] = PlayerMaxFocus[id]             //debug             client_print(id, print_console, "Player #%i reached level #%i", id, PlayerLevel[id])//works             CheckLevel(id)         }     }         if (PlayerLevel[id]>0)     {         if (PlayerExp[id] < ExperienceForLevel[PlayerLevel[id]])         {             PlayerLevel[id] -= 1                     set_hudmessage(255, 255, 255, 2.0, 1.0, 1, 6.0, 15.0, 0.1, 0.2, 4)             show_hudmessage(id, "You've lost a level! You are now level #%i", PlayerLevel[id])//broken             //debug             client_print(id, print_console, "Player #%i lost a level. They are now level #%i", id, PlayerLevel[id])//works             PlayerMaxFocus[id] = PlayerLevel[id] +10             PlayerFocus[id] = PlayerMaxFocus[id]             CheckLevel(id)         }     }     } public UpdateFocus(id) {     if(is_user_alive(id))     {         PlayerMaxFocus[id] = PlayerLevel[id] + 10//check required for admin set exp command         PlayerFocus[id] = PlayerFocus[id] + 2         //debug         client_print(id, print_console, "Setting maxfocus to Level(%i) + 10 (=%i)", PlayerLevel[id], PlayerMaxFocus[id])         if (PlayerFocus[id] > PlayerMaxFocus[id])         {             PlayerFocus[id] = PlayerMaxFocus[id]         }                 //debug         //client_print(i, print_chat, "set focus to: %i", PlayerFocus[id])             new Message[128] = ""         format(Message, 127, "FOCUS: %i/%i", PlayerFocus[id], PlayerMaxFocus[id])             set_hudmessage(255, 255, 255, 0.05, 0.75, 2, 0.02, 3.0, 0.01, 0.1, 2)         show_hudmessage(id, Message)     }     new ident[1]     ident[0] = id     set_task(1.0, "RefreshFocus", 451+id, ident, 1) } //for timed function only public RefreshFocus(ident[],TaskID) {     new id = ident[0]     UpdateFocus(id) } There we go, that's done at the begining of every round, now please tell me why the messages only work when there is only 1 person in the server (game is not officialy started).  And why in God's name does the focus update for only me, and never anyone else?

v3x 04-23-2005 22:24

Well.. When you're doing a loop like that.. Use something like this.

Code:
public myFunc() {     new players[32]     new player,num,i     get_players(players,num,"a")     // Doesn't return dead players     for(i=0;i<num;i++) {         player = players[i]         // Do something with player     }     return PLUGIN_HANDLED }

teame06 04-23-2005 22:27

Code:
show_hudmessage(id, "Congratulations on achieving level #%i", PlayerLevel[id])//broken to format(cong, 63, ""Congratulations on achieving level #%i", PlayerLevel[id]) show_hudmessage(id, cong)

Code:
show_hudmessage(id, "You've lost a level! You are now level #%i", PlayerLevel[id])//broken to format(lost, 63, "You've lost a level! You are now level #%i", PlayerLevel[id]) show_hudmessage(id, lost)

BioHazardousWaste 04-23-2005 22:27

ok thanx, but i don't think that's going to help solve the problem lol

xeroblood 04-23-2005 22:27

Quote:

Originally Posted by BioHazardousWaste
Code:
    message_begin(MSG_ONE, get_user_msgid("StatusText"), {0, 0, 0}, id);

Please replace MSG_ONE with MSG_ONE_UNRELIABLE so that people's servers don't randomly crash..

It doesn't mean your message won't be sent, it just means that HL won't crash if it can't be sent.. Even if it is not crashing for you now, it could in the future for anyone, if the message simply can't be sent for any number of reasons..


All times are GMT -4. The time now is 09:51.

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