AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Floatround? (https://forums.alliedmods.net/showthread.php?t=134987)

nikhilgupta345 08-11-2010 00:18

Floatround?
 
So I saw another thread in scripting help about showing a hud to dead people saying how much time is left in the map. I tried doing that, but with floatround, I keep getting a tag mismatch error. Fysiks said there is something else wrong with the code? What's wrong with it?
Thanks
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Hud"
#define VERSION "1.0"
#define AUTHOR "Omgitsme"

new timeleft
new float:timeleft2
public plugin_init()
{
    register_plugin("Hud", "1.0", "Omgitsme")
    set_task(0.9, "gettingtime", 2, _, _, "b")
    set_task(0.9, "timeleftmessage", 1, _, _, "b")
}

public gettingtime()
{
timeleft=get_timeleft()
timeleft2=timeleft/60
floatround(timeleft2, floatround_floor)
timeleft=(timeleft %60)
}

public timeleftmessage()
{   
new players[32], num, player
get_players(players, num)
for(new i;i<num;i++)
{    player=players[i]
    if(!is_user_alive(player))
    {
        set_hudmessage(255, 255, 255, 0.70, 0.0, 0, 6.0, 0.9)
        show_hudmessage(player, "Time left on this map is %i:%i", timeleft2, timeleft)
    }
}

}

fysiks 08-11-2010 02:07

Re: Floatround?
 
PHP Code:

#include <amxmodx>

public plugin_init()
{
    
set_task(0.9"timeleftmessage"1__"b")
}

public 
timeleftmessage()
{    
    static 
timeleft
    timeleft 
get_timeleft()
    
set_hudmessage(2552552550.700.006.00.9)
    
show_hudmessage(0"Time left on this map is %d:%02d"timeleft 60timeleft 60)



nikhilgupta345 08-11-2010 19:05

Re: Floatround?
 
First, what does %02d do?


Also, if I do timeleft /60 as the first %d, won't that show a decimal?

fysiks 08-11-2010 19:33

Re: Floatround?
 
Quote:

Originally Posted by nikhilgupta345 (Post 1268439)
First, what does %02d do?


Also, if I do timeleft /60 as the first %d, won't that show a decimal?

0 means pad front with zeros. 2 means always show two characters. Find out more here.

%d and %i both show only integers and not floating point numbers (which you are refering to as "decimal")

nikhilgupta345 08-11-2010 20:12

Re: Floatround?
 
K, is there anything I can optimize?

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Hud"
#define VERSION "1.0"
#define AUTHOR "nikhilgupta345"


public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    set_task(0.9, "gettingtime", 2, _, _, "b")
}

public gettingtime()
{
static timeleft
timeleft=get_timeleft()
new players[32], num, player
get_players(players, num)
for(new i;i<num;i++)
{    player=players[i]
    if(!is_user_alive(player))
    {
        set_hudmessage(255, 255, 255, 0.5, 0.2, 0, 6.0, 0.9)
        show_hudmessage(player, "Time left on this map is %d:%02d", timeleft / 60, timeleft % 60)
    }
}
}

And thanks btw.

naven 08-12-2010 03:10

Re: Floatround?
 
There would be less code if you just show that to everyone (index = 0)

Hunter-Digital 08-12-2010 05:13

Re: Floatround?
 
Quote:

Originally Posted by nikhilgupta345 (Post 1268486)
K, is there anything I can optimize?

Yes, you're using too much unrequired code, fysiks already wrote a code for you:

Quote:

Originally Posted by fysiks (Post 1267890)
PHP Code:

#include <amxmodx>

public plugin_init()
{
    
set_task(0.9"timeleftmessage"1__"b")
}

public 
timeleftmessage()
{    
    static 
timeleft
    timeleft 
get_timeleft()
    
set_hudmessage(2552552550.700.001.00.50.51)
    
show_hudmessage(0"Time left on this map is %d:%02d"timeleft /  60timeleft 60)



I modified the set_hudmessage() params so that you don't spam with 4 messages in the same possition each having 6 seconds...


All times are GMT -4. The time now is 22:03.

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