AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help Me With Hud For Spectator (https://forums.alliedmods.net/showthread.php?t=324573)

Arje 05-19-2020 19:46

Help Me With Hud For Spectator
 
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
    
}



gabuch2 05-19-2020 20:21

Re: Help Me With Hud For Spectator
 
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

OciXCrom 05-19-2020 21:53

Re: Help Me With Hud For Spectator
 
It's much better to do the loop with "get_players".

thEsp 05-20-2020 06:08

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by OciXCrom (Post 2701152)
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.

OciXCrom 05-20-2020 10:19

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by thEsp (Post 2701191)
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.

thEsp 05-20-2020 10:51

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by OciXCrom (Post 2701228)
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?

Arje 05-20-2020 12:45

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by Gabe Iggy (Post 2701139)
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!

OciXCrom 05-20-2020 14:34

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by thEsp (Post 2701231)
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.

thEsp 05-20-2020 15:00

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by OciXCrom (Post 2701268)
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.

OciXCrom 05-20-2020 16:15

Re: Help Me With Hud For Spectator
 
Quote:

Originally Posted by thEsp (Post 2701271)
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 (Post 2659916)
Use get_players native, it's better if you loop throughout a certain team.
https://forums.alliedmods.net/showthread.php?t=129484



All times are GMT -4. The time now is 20:32.

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