Raised This Month: $32 Target: $400
 8% 

Help Me With Hud For Spectator


Post New Thread Reply   
 
Thread Tools Display Modes
thEsp
BANNED
Join Date: Aug 2017
Old 05-20-2020 , 16:47   Re: Help Me With Hud For Spectator
Reply With Quote #11

Quote:
Originally Posted by OciXCrom View Post
I mentioned both things in my first comment, so please don't manipulate my words. Like I said - this has been discussed multiple times, feel free to search why it is better.

From what I can see, you used the exact same words a while ago:
I did words manipulation? Can you point out where exactly?
Quote:
Originally Posted by OciXCrom View Post
Using natives is faster.
Quote:
Originally Posted by OciXCrom View Post
Better and faster machines doesn't mean we should use bad scripting practices.
You clearly surfed from an argument to another one. While little did I knew how the native worked back then, I now know one thing: both ways are fine. Do I have to repeat my words, if somehow you didn't get my point? This time I didn't say either way is better or worse. If you want to check for certain flags without having messy code, sure, do it with get_players native, but for something rather inexpensive and pointless to bother about, choose your own. I am 100% sure the OP found his acquired code to be working all fine, even without your (and my) comment. Speaking of comments, making "just-to-exist" comments which are oftentimes neglecting is not something a wise man would do.
thEsp is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 06-03-2020 , 17:29   Re: Help Me With Hud For Spectator
Reply With Quote #12

Quote:
Originally Posted by Gabe Iggy View Post
If the first parameter of ShowSyncHudMsg is 0 it will show to all players.

Loop through all players and check if they're spectator with cs_get_user_team()

Code:
public show() {     if(!c4pl)     {         remove_task(652450)         return     }     if(c4cd>=0.0)     {         temp=c4cd/c4max         if(temp>=0.5)         {             r=510*(1.0-temp)             g=255.0         }         if(temp<0.5)         {             r=255.0             g=510*temp         }             for(new i = 1; i <= get_maxplayers();i++)     {         if(is_user_connected(i) && cs_get_user_team(i) == CS_TEAM_SPECTATOR)         {             set_hudmessage(floatround(r),floatround(g),0,-1.0,0.80,0,_,1.0,_,_,4)             ShowSyncHudMsg(i,msg,"Anda a Defusear la bomba!!! Faltan %d segundos antes de que explote.",floatround(c4cd))         }     }     c4cd-=1.0 }

Untested
Hi! I have another question, because the hud is still in the next round if there is mp_freezetime? and how could that be arranged?
Arje is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-03-2020 , 21:20   Re: Help Me With Hud For Spectator
Reply With Quote #13

@op
PHP Code:
//Try
register_event("HLTV""nr""a""1=0""2=0")  //Fired at new round, before freeze-time start
//instead of
register_logevent("nr",2,"1=Round_Start"//Fired at the end of freeze time (your current code) 
I'd personally go with get_players() because it does the work for you with less code/native calls.

There is theoretically nothing wrong with the code and I know it isn't going to make someones CPU blow smoke, there's just a few things can be improved to be more ideal.
  • get_maxplayers() will be called 32 times per execution; at a minimum, the get_maxplayers() value should be stored in a variable instead of being placed within the for-loop condition block.
  • The loop will iterate max_players/32 times, every time, instead of only a handful of times for those in spectator.
PHP Code:
    for(new 1<= get_maxplayers();i++)
    {
        if(
is_user_connected(i) && cs_get_user_team(i) == CS_TEAM_SPECTATOR)
        {

        }
    } 
vs.
PHP Code:
    new iPlayers32 ] , iNum;
    
get_playersiPlayers iNum "e" "SPECTATOR" );
    
    for ( new 
iNum i++ )
    {

    } 
__________________

Last edited by Bugsy; 06-03-2020 at 21:29.
Bugsy is online now
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 17:21.


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