AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random hud text (https://forums.alliedmods.net/showthread.php?t=241988)

sky_pg 06-12-2014 06:15

random hud text
 
im trying to get this to work but it gives me errors in game someone to help me?

PHP Code:

#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "test"

#define MAX 3
new stat_hud
new randoms

new const messages[MAX][] = 
{
    
"test",
    
"test 1",
    
"test 2"
}
public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
testmessage()
    
stat_hud CreateHudSyncObj(1)
}

public 
testmessage()
{
    
randoms random_num(0MAX)
    
set_task(10.0"testmessage")
}
public 
client_PostThink(id)
{
    if(!
is_user_connected(id))
        return
    
show_stat(id)    
}

public 
show_stat(id)
{    
    
set_hudmessage(016000.020.1402.02.0)
    
ShowSyncHudMsg(idstat_hud"%s"messages[randoms])



Nextra 06-12-2014 06:35

Re: random hud text
 
What errors do you receive?

If I remember correctly random_num(a, b) returns a random number from a to b, including b in the range. So you will sometimes set randoms = MAX which will result in an index out of bounds error. Try using random_num(0, MAX - 1);

aron9forever 06-12-2014 06:39

Re: random hud text
 
hahah

sending hud info to players every 20 frames is basically DOSing them

sky_pg 06-12-2014 07:17

Re: random hud text
 
Quote:

Originally Posted by aron9forever (Post 2150382)
hahah

sending hud info to players every 20 frames is basically DOSing them

"Test" saying u nothing? i wont change it every 10sec... "ha ha ha" :/

smart kids...

Nextra 06-12-2014 07:24

Re: random hud text
 
What he's trying to say is that it is a bad idea to send hudmessages on Client_PostThink. You can (and probably should) specify them to stay up for 1 second or more and utilize set_task to send them at more reasonable intervals.

Quote:

Originally Posted by aron9forever (Post 2150382)
hahah

sending hud info to players every 20 frames is basically DOSing them

This pointlessly confrontational attitude is not helpful.

sky_pg 06-12-2014 07:46

Re: random hud text
 
Quote:

Originally Posted by Nextra (Post 2150404)
What he's trying to say is that it is a bad idea to send hudmessages on Client_PostThink. You can (and probably should) specify them to stay up for 1 second or more and utilize set_task to send them at more reasonable intervals.

Could you suggest me a alternative/beter way?

Nextra 06-12-2014 08:15

Re: random hud text
 
That is my suggestion. The "holdtime" parameter of set_hudmessage allows you to keep the hudmessage on screen for 1 second (or longer). You then use set_task to run a task every second and send the hudmessage to all connected players.

sky_pg 06-12-2014 08:27

Re: random hud text
 
Quote:

Originally Posted by Nextra (Post 2150436)
That is my suggestion. The "holdtime" parameter of set_hudmessage allows you to keep the hudmessage on screen for 1 second (or longer). You then use set_task to run a task every second and send the hudmessage to all connected players.

or

if(get_gametime() - 1.0 > delay_hud[id])

delay_hud[id] = get_gametime()

Nextra 06-12-2014 08:35

Re: random hud text
 
That would work too, if you absolutely positively want to use Client_PreThink for this. I wouldn't consider this the right tool for the job though. Unless you have a very good reason to do it this way I would still recommend using a task and letting AMXX do the job for you.


If you are still certain you want to use PreThink, do it like this:
PHP Code:

if(get_gametime() > delay_hud[id])

delay_hud[id] = get_gametime() + 1.0 


Flick3rR 06-12-2014 10:29

Re: random hud text
 
If we are talking about permanent HUD message, my best suggestions are with self repeating task, or with thinking entity (like it's better I think).


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

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