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

Help Me With Hud For Spectator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 05-19-2020 , 19:46   Help Me With Hud For Spectator
Reply With Quote #1

Hello! I wanted to know if it is possible to make this Hud from C4timer only show for spects, currently shown to all players.

PHP Code:
#include amxmodx
#include csx

new msg,sec
new Float:c4cd,Float:c4max
new Float:temp,Float:r,Float:g
new bool:c4pl=false

public plugin_init()
{
    
register_plugin("C4-Bomb Countdown HUD Timer","0.4","SAMURAI; Midnight Kid")
    
msg=CreateHudSyncObj()
    
sec=get_cvar_pointer("mp_c4timer")
    
register_logevent("nr",2,"1=Round_Start")
    
register_logevent("er",2,"1=Round_End")
    
register_logevent("er",2,"1&Restart_Round_")
}

public 
nr()
{
    
c4cd=-1.0
    remove_task
(652450)
    
c4pl=false
}

public 
er()
{
    
c4cd=-1.0
    remove_task
(652450)
}

public 
bomb_planted()
{
    
c4pl=true
    c4max
=get_pcvar_float(sec)
    
c4cd=c4max
    show
()
    
set_task(1.0,"show",652450,"",0,"b")
}

public 
bomb_defused()
{
    if(
c4pl)
    {
        
remove_task(652450)
        
c4pl=false
    
}
}

public 
bomb_explode()
{
    if(
c4pl)
    {
        
remove_task(652450)
        
c4pl=false
    
}
}

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
        
}
        
    
set_hudmessage(floatround(r),floatround(g),0,-1.0,0.80,0,_,1.0,_,_,4)
    
ShowSyncHudMsg(0,msg,"Anda a Defusear la bomba!!! Faltan %d segundos antes de que explote.",floatround(c4cd))
    
c4cd-=1.0
    
}

Arje is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 05-19-2020 , 20:21   Re: Help Me With Hud For Spectator
Reply With Quote #2

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
__________________

Last edited by gabuch2; 05-19-2020 at 20:24. Reason: Should set hudmessage only if player is valid. Fixed off by 1 error.
gabuch2 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-19-2020 , 21:53   Re: Help Me With Hud For Spectator
Reply With Quote #3

It's much better to do the loop with "get_players".
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
thEsp
BANNED
Join Date: Aug 2017
Old 05-20-2020 , 06:08   Re: Help Me With Hud For Spectator
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
It's much better to do the loop with "get_players".
Why don't you define why it's much better? That native does roughly the same process.
thEsp is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-20-2020 , 10:19   Re: Help Me With Hud For Spectator
Reply With Quote #5

Quote:
Originally Posted by thEsp View Post
Why don't you define why it's much better? That native does roughly the same process.
What is the point of looping through all player indexes manually, even the ones that aren't connected, instead of using a built in native that does the job for you and gives you an array of indexes that fit the criteria? It's 2020, we should stop using 2005 practices. This has been discussed many times. Using natives is faster.
__________________

Last edited by OciXCrom; 05-20-2020 at 10:20.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
thEsp
BANNED
Join Date: Aug 2017
Old 05-20-2020 , 10:51   Re: Help Me With Hud For Spectator
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
What is the point of looping through all player indexes manually, even the ones that aren't connected, instead of using a built in native that does the job for you and gives you an array of indexes that fit the criteria? It's 2020, we should stop using 2005 practices. This has been discussed many times. Using natives is faster.
That native does exactly what Gabe's code does, loop until the maximum number of players is reached and check if players are connected, plus some other checks. Natives are faster but not superior, we're dealing with small chunks of data and the performance is absolutely unnoticeable. Also, if you realize we live in 2020, must've you not realize we have better and faster machines?
thEsp is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 05-20-2020 , 12:45   Re: Help Me With Hud For Spectator
Reply With Quote #7

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
Thank you! works correctly;
I had corrected it before, I had a small typing error, but you corrected the code so I don't have to upload mine, thanks again!
Arje is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-20-2020 , 14:34   Re: Help Me With Hud For Spectator
Reply With Quote #8

Quote:
Originally Posted by thEsp View Post
That native does exactly what Gabe's code does, loop until the maximum number of players is reached and check if players are connected, plus some other checks. Natives are faster but not superior, we're dealing with small chunks of data and the performance is absolutely unnoticeable. Also, if you realize we live in 2020, must've you not realize we have better and faster machines?
Better and faster machines doesn't mean we should use bad scripting practices. I don't see the point of this argument.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
thEsp
BANNED
Join Date: Aug 2017
Old 05-20-2020 , 15:00   Re: Help Me With Hud For Spectator
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
Better and faster machines doesn't mean we should use bad scripting practices. I don't see the point of this argument.
You are in both cases wrong. Your last response was that natives are faster, and now you're saying it is a bad scripting practice. Natives aren't fast enough to make any difference that is noticeable, especially nowadays, and it is not a so-called bad scripting practice because as I already told you, core module does the same. Either way works totally fine, I don't blame you, but saying "... is much better" without proving why is not a good idea.
thEsp is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-20-2020 , 16:15   Re: Help Me With Hud For Spectator
Reply With Quote #10

Quote:
Originally Posted by thEsp View Post
You are in both cases wrong. Your last response was that natives are faster, and now you're saying it is a bad scripting practice. Natives aren't fast enough to make any difference that is noticeable, especially nowadays, and it is not a so-called bad scripting practice because as I already told you, core module does the same. Either way works totally fine, I don't blame you, but saying "... is much better" without proving why is not a good idea.
I mentioned both things in my first comment and I stand by them, so please don't manipulate my words. Like I said - this has been discussed many times, feel free to search why it is better.

Let's also not forget that you used the exact same words a while ago:

Quote:
Originally Posted by thEsp View Post
Use get_players native, it's better if you loop throughout a certain team.
https://forums.alliedmods.net/showthread.php?t=129484
__________________

Last edited by OciXCrom; 05-20-2020 at 16:45.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 20:31.


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