Raised This Month: $ Target: $400
 0% 

random hud text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sky_pg
Member
Join Date: Apr 2012
Old 06-12-2014 , 06:15   random hud text
Reply With Quote #1

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])

sky_pg is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-12-2014 , 06:35   Re: random hud text
Reply With Quote #2

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);
__________________
In Flames we trust!
Nextra is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 06-12-2014 , 06:39   Re: random hud text
Reply With Quote #3

hahah

sending hud info to players every 20 frames is basically DOSing them
aron9forever is offline
sky_pg
Member
Join Date: Apr 2012
Old 06-12-2014 , 07:17   Re: random hud text
Reply With Quote #4

Quote:
Originally Posted by aron9forever View Post
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...
sky_pg is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-12-2014 , 07:24   Re: random hud text
Reply With Quote #5

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 View Post
hahah

sending hud info to players every 20 frames is basically DOSing them
This pointlessly confrontational attitude is not helpful.
__________________
In Flames we trust!
Nextra is offline
sky_pg
Member
Join Date: Apr 2012
Old 06-12-2014 , 07:46   Re: random hud text
Reply With Quote #6

Quote:
Originally Posted by Nextra View Post
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?
sky_pg is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-12-2014 , 08:15   Re: random hud text
Reply With Quote #7

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.
__________________
In Flames we trust!
Nextra is offline
sky_pg
Member
Join Date: Apr 2012
Old 06-12-2014 , 08:27   Re: random hud text
Reply With Quote #8

Quote:
Originally Posted by Nextra View Post
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()
sky_pg is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-12-2014 , 08:35   Re: random hud text
Reply With Quote #9

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 
__________________
In Flames we trust!
Nextra is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-12-2014 , 10:29   Re: random hud text
Reply With Quote #10

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).
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
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 09:37.


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