AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Fix method random_num (https://forums.alliedmods.net/showthread.php?t=236833)

extream87 03-11-2014 20:39

[HELP] Fix method random_num
 
What is the best method to do this?
Sometimes the hudmessage not appear but the sound works.
Code:
public plugin_init() { register_event("HLTV","rnstart","a", "1=0", "2=0"); } public rnstart(id) {     if(get_pcvar_num(rnstartcvar) == 1)     {     firstblood = 1           new rand = random_num(1,3)     switch(rand)     {     case 1:     {         set_hudmessage(255, 0, 255, -1.0, 0.30, 0, 6.0, 6.0)         show_hudmessage(0, "P R E P A R E 1 !")         client_cmd(0,"spk sound/Prepare1.wav")     }     case 2:     {         set_hudmessage(255, 0, 255, -1.0, 0.30, 0, 6.0, 6.0)         show_hudmessage(0, "P R E P A R E 2 !")         client_cmd(0,"spk sound/Prepare2.wav")     }     case 3:     {         set_hudmessage(255, 0, 255, -1.0, 0.30, 0, 6.0, 6.0)         show_hudmessage(0, "P R E P A R E 3 !")         client_cmd(0,"spk sound/Prepare3.wav")     }     }       } }

^SmileY 03-11-2014 22:55

Re: [HELP] Fix method random_num
 
If you only use any variable one time, it is make no sense to create it!
Put it directly
new rand = random_num(1,3) switch(rand)

To

switch(random_num(1,3))

extream87 03-12-2014 03:16

Re: [HELP] Fix method random_num
 
Yes is only in player spawn.

Well i've putted "," and i think now is working.

Code:
public plugin_init() { register_event("HLTV","rnstart","a", "1=0", "2=0"); } public rnstart(id) {     if(get_pcvar_num(rnstartcvar) == 1)     {     firstblood = 1           switch(random_num(1,3))     {     case 1:     {         set_hudmessage(255, 0, 255, -1.0, 0.30, 0, 6.0, 6.0),         show_hudmessage(0, "P R E P A R E 1 !"),         client_cmd(0,"spk sound/Prepare1.wav")     }     case 2:     {         set_hudmessage(255, 0, 255, -1.0, 0.30, 0, 6.0, 6.0),         show_hudmessage(0, "P R E P A R E 2 !"),         client_cmd(0,"spk sound/Prepare2.wav")     }     case 3:     {         set_hudmessage(255, 0, 255, -1.0, 0.30, 0, 6.0, 6.0),         show_hudmessage(0, "P R E P A R E 3 !"),         client_cmd(0,"spk sound/Prepare3.wav")     }     }       } }

fysiks 03-12-2014 03:41

Re: [HELP] Fix method random_num
 
That is common with HUD messages because they can easily be removed by other plugins or even the game itself without ever showing your message.

extream87 03-12-2014 03:42

Re: [HELP] Fix method random_num
 
Ah ok fysiks, so it's normal?

Shooting King 03-12-2014 04:09

Re: [HELP] Fix method random_num
 
Set Channel to -1 and try again.

extream87 03-12-2014 09:57

Re: [HELP] Fix method random_num
 
Shooting_King: This?
Code:
switch(random_num(1,3-1))

Neeeeeeeeeel.- 03-12-2014 10:39

Re: [HELP] Fix method random_num
 
Quote:

Originally Posted by extream87 (Post 2110848)
Shooting_King: This?
Code:
switch(random_num(1,3-1))

No, he was talking about hud message channel.

You should know that you cannot display more than 4 hud's at the same time.

extream87 03-12-2014 10:44

Re: [HELP] Fix method random_num
 
Sure and when player spawn happen i dont have any hudmessage.
If you look to the code you see that are 3 hudmessages but only one is randomly chosen.

So what Shooting_King says is:
Code:
show_hudmessage(-1, "P R E P A R E 1 !"),
Im write now?
The -1 have the same value as 0?
Cause i need this message appear to all players.

Edit:
With -1 nothing appears.

Kiske 03-12-2014 13:14

Re: [HELP] Fix method random_num
 
Quote:

/**
* Sets format for hudmessage.
* Note - as of AMX Mod X 1.61, setting the channel to -1
* will automatically choose the next available HUD channel for a player.
*/
native set_hudmessage(red=200, green=100, blue=0, Float:x=-1.0, Float:y=0.35, effects=0, Float:fxtime=6.0, Float:holdtime=12.0, Float:fadeintime=0.1, Float:fadeouttime=0.2,channel=4);

/* Displays HUD message to given player. */
native show_hudmessage(index,const message[],any:...);
...


All times are GMT -4. The time now is 06:01.

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