Raised This Month: $51 Target: $400
 12% 

showing speed player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 10-03-2008 , 10:26   showing speed player
Reply With Quote #1

hi guys, here i trying to add a hud msg speed player in a plugin that i modificated.. the speed is showing, yes.. but.. i think this is not the best way to show the speed.. oh, and.. i want to show the speed without decimals.. any can give me the best way to do this?

see the code:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>


#define PLUGIN_NAME    "HP Hud Display"
#define PLUGIN_VERSION    "1.0"
#define PLUGIN_AUTHOR    "Alucard"

//credits: Exolent, Emp`

new HUDSYNC;
new 
hp_color;
new 
hp_custom;
new 
hp_effects;


public 
plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR);
    
    
set_task(1.0,"timer_task",_,"",0,"b");
    
HUDSYNC CreateHudSyncObj();

    
hp_color register_cvar("hp_color""1"00.0);
    
hp_custom register_cvar("hp_custom""255 255 0"00.0);
    
hp_effects register_cvar("hp_effects""1"00.0);

    return 
PLUGIN_CONTINUE;
}

public 
timer_task() {

    new 
hud_redhud_greenhud_blue;
    switch( 
get_pcvar_num(hp_color) )
    {
        case 
0:
        {
            
hud_red 255;
            
hud_green 255;
            
hud_blue 255;
        }
        case 
1:
        {
            new 
color[16], red[4], green[4], blue[4];
            
get_pcvar_string(hp_customcolor15);
            
parse(colorred3green3blue3);
            
            
hud_red str_to_num(red);
            
hud_green str_to_num(green);
            
hud_blue str_to_num(blue);
        }
        case 
2:
        {
            
hud_red random(256);
            
hud_green random(256);
            
hud_blue random(256);
        }
    }

    static 
scoreboard[128];
    for(new 
i=1;i<=32;i++) {
              
        if(
is_user_connected(i) && is_user_alive(i) ) {
                new 
speedstr[32] = ""

                
new Float:speed[3]

                
pev(ipev_velocityspeed);
        
                
float_to_str 
                
floatsqroot(floatadd(floatpower(speed[0], 2.0), floatpower(speed[1], 2.0)))
                , 
speedstr5);

                
format(speedstr31speedstr);

                
formatex(scoreboard127"HP: %i | AP: %i | SPEED: %s"get_user_health(i), get_user_armor(i), speedstr );
                
set_hudmessage(hud_redhud_greenhud_blue0.030.94get_pcvar_num(hp_effects), 0.02.00.00.22);
                
ShowSyncHudMsgiHUDSYNCscoreboard );
                }
      }

thx, and sry for my english
Alucard^ is offline
Send a message via Skype™ to Alucard^
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 10-03-2008 , 13:08   Re: showing speed player
Reply With Quote #2

Use client prethink ?
Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-03-2008 , 13:12   Re: showing speed player
Reply With Quote #3

Set the task to 0.1

http://forums.alliedmods.net/showpos...9&postcount=28
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 10-04-2008 , 08:45   Re: showing speed player
Reply With Quote #4

@Sn!ff3r

thx but u can give me an example? cuz i am new in scripting.. or is there a tutorial or something about "prethink"?

@connorr

thx connor, i never think that i need a lot of code to do this o.o..

and mm, i am confused, how can i implement this in my plugin? i only need the current speed
Alucard^ is offline
Send a message via Skype™ to Alucard^
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 10-04-2008 , 12:13   Re: showing speed player
Reply With Quote #5

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "Your speed"
#define VERSION "1.0"
#define AUTHOR "Sn!ff3r"

new g_sync

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_forward(FM_PlayerPreThink,"prethink")
    
g_sync CreateHudSyncObj()
}

public 
prethink(id)
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED    
    
    
static Float:velocity[3], Float:speed
    
    pev
(idpev_velocityvelocity)
    
    
speed vector_length(velocity)
    
    
set_hudmessage(255255255, -1.00.906.0, -1.0)
    
ShowSyncHudMsg(id,g_sync,"Your current speed: %3.0f",speed)
    
    return 
FMRES_IGNORED

Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 10-04-2008 , 12:25   Re: showing speed player
Reply With Quote #6

thx sniffer

oh and why?:

Quote:
%3.0f

Last edited by Alucard^; 10-04-2008 at 12:28.
Alucard^ is offline
Send a message via Skype™ to Alucard^
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 10-04-2008 , 13:15   Re: showing speed player
Reply With Quote #7



http://forums.alliedmods.net/showpos...57&postcount=8
Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 10-04-2008 , 19:13   Re: showing speed player
Reply With Quote #8

I would personally suggest not to send it more often than needed.

PreThink could be called like 100 times a second for some players (maybe more), causing lag (choke) on a slow connection and/or the server to drop clients with the "reliable channel overflowed" error.
__________________
MeRcyLeZZ is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-05-2008 , 02:39   Re: showing speed player
Reply With Quote #9

Setting hudmessage during startframe was causing lot of choke, i don't know if it's the same with prethink.
MeRcyLeZZ is right, a 0.1 task should be enough (or filter by 0.1s in prethink)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
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:12.


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