ReSpeedometer

ReSpeedometer 1.1b

Нет прав для скачивания
Сообщения
2,491
Реакции
2,791
Помог
61 раз(а)
Small improvements
Код:
g_speed[id] = g_speed[id] ? false : true;
->
Код:
g_speed[id] = !g_speed[id];
 
Сообщения
2,720
Реакции
2,997
Помог
60 раз(а)
Maybe better to use RG_CBasePlayer_PostThink (or something else) + skipframes variable for each player instead @ent_think entity with 0.1sec timer?
 
Сообщения
278
Реакции
137
Could you please update that topic? Thank you.

Maybe better to use RG_CBasePlayer_PostThink (or something else) + skipframes variable for each player instead @ent_think entity with 0.1sec timer?
Yeap, It is the best way.

Код:
#pragma semicolon 1

#include <amxmodx>
#include <reapi>

#define PLUGIN_NAME        "ReSpeedometer"
#define PLUGIN_VERS        "1.0"
#define PLUGIN_AUTH        "PurposeLess"

new g_speed[MAX_CLIENTS + 1], hudsync;

public plugin_init() {
    register_plugin(PLUGIN_NAME, PLUGIN_VERS, PLUGIN_AUTH);

    register_clcmd("say /speed", "@clcmd_speed");

    RegisterHookChain(RG_CBasePlayer_PostThink, "@CBasePlayer_PostThink", .post=true);

    hudsync = CreateHudSyncObj();
}

public client_putinserver(id)
{
    g_speed[id] = true;
}

public client_disconnected(id)
{
    ClearSyncHud(id, hudsync);
}

@clcmd_speed(const id)
{
    g_speed[id] = !g_speed[id];

    if(!g_speed[id])
    {
        ClearSyncHud(id, hudsync);
    }
}

@CBasePlayer_PostThink(const id)
{
    if(!g_speed[id])
    {
        return;
    }

    static Float:velocity[3], Float:speed, Float:speedh;
    get_entvar(id, var_velocity, velocity);

    speed = vector_length(velocity);
    speedh = floatsqroot(floatpower(velocity[0], 2.0) + floatpower(velocity[1], 2.0));

    set_hudmessage(255, 0, 0, -1.0, 0.75, 0, 0.0, 0.1, 0.01, 0.0);
    ShowSyncHudMsg(id, hudsync, "%3.2f units/second^n%3.2f velocity", speed, speedh);
}
 
Сообщения
2,720
Реакции
2,997
Помог
60 раз(а)
PostThink call too often, need to add variable
skipframes variable for each player
ShowSyncHudMsg - this is user "net message" and you shouldn't flood to "net channel" (now ~100 messages per second)
This may cause "SZ_GetSpace: overflow on clientName".

I suggest you add something like this
C:
g_SkipFrames[MAX_PLAYERS + 1];

@PostThink(id) {
    if(++g_SkipFrames[id] < 25)
        return;
       
    // Show Speedometer
   
    g_SkipFrames[id] = 0;
}
 
Последнее редактирование:
Сообщения
278
Реакции
137
PostThink call too often, need to add variable
That's been better way. I think it is working perfect right now.

Код:
#pragma semicolon 1

#include <amxmodx>
#include <reapi>

#define PLUGIN_NAME        "ReSpeedometer"
#define PLUGIN_VERS        "1.0"
#define PLUGIN_AUTH        "PurposeLess"

new g_speed[MAX_CLIENTS + 1], g_skipframes[MAX_CLIENTS + 1], hudsync;

public plugin_init() {
    register_plugin(PLUGIN_NAME, PLUGIN_VERS, PLUGIN_AUTH);

    register_clcmd("say /speed", "@clcmd_speed");

    RegisterHookChain(RG_CBasePlayer_PostThink, "@CBasePlayer_PostThink", .post=true);

    hudsync = CreateHudSyncObj();
}

public client_putinserver(id)
{
    g_speed[id] = true;
}

public client_disconnected(id)
{
    ClearSyncHud(id, hudsync);
}

@clcmd_speed(const id)
{
    g_speed[id] = !g_speed[id];

    if(!g_speed[id])
    {
        ClearSyncHud(id, hudsync);
    }
}

@CBasePlayer_PostThink(const id)
{
    if(!g_speed[id] || ++g_skipframes[id] < 25)
    {
        return;
    }

    static Float:velocity[3], Float:speed, Float:speedh;
    get_entvar(id, var_velocity, velocity);

    speed = vector_length(velocity);
    speedh = floatsqroot(floatpower(velocity[0], 2.0) + floatpower(velocity[1], 2.0));

    set_hudmessage(255, 0, 0, -1.0, 0.75, 0, 0.0, 0.1, 0.01, 0.0);
    ShowSyncHudMsg(id, hudsync, "%3.2f units/second^n%3.2f velocity", speed, speedh);

    g_skipframes[id] = 0;
}
 
Сообщения
2,720
Реакции
2,997
Помог
60 раз(а)
1) where is player alive status checks?;
2) ++g_skipframes[id] < 25) -> 25 need replace by CVar (update per sec);
3) now you hud message will show on 0.1sec (will blink);
4) As additional functionality, u may add different colors for different speed (red for low velocity, yellow for mid, green for high);
5) Need to add info for clients about /speed cmd. (Now they don't know about this command);
6) The user doesn't know the difference between unit\seconds & velocity. I suggest you leave the only velocity and name this as "123.1 u/s";
7) You shouldn't show speed message when client speed == 0;
8) HLTV? Bots?;
9) How can see speed observers?;
 
Последнее редактирование:
Сообщения
278
Реакции
137
wopox1337,
1) When you die, you see the speed of person you watch. So, I did not check if player alive or not. It is always okay to show speed, i guess.
2) Good one.
3) I did 0.2, but sometimes it blinks. What i should do? 1.0 etc?
4) Very good.
5) Will do it.
6) "123.3 u/s" is great, i did.
7) I didn't want it but it is better than old one.
8) Did it.
9) No idead what you talking about but i answered number 1 i guess.


For now;

Код:
#pragma semicolon 1

#include <amxmodx>
#include <reapi>

#define PLUGIN_NAME        "ReSpeedometer"
#define PLUGIN_VERS        "1.0"
#define PLUGIN_AUTH        "PurposeLess"

new    bool:g_speed[MAX_CLIENTS + 1],
    g_skipframes[MAX_CLIENTS + 1],
    hudsync;

new    cvar_updatepersec;

public plugin_init() {
    register_plugin(PLUGIN_NAME, PLUGIN_VERS, PLUGIN_AUTH);

    register_clcmd("say /speed", "@clcmd_speed");

    RegisterHookChain(RG_CBasePlayer_PostThink, "@CBasePlayer_PostThink", .post=true);

    bind_pcvar_num(create_cvar("cvar_updatepersec", "25"), cvar_updatepersec);

    hudsync = CreateHudSyncObj();
}

public client_putinserver(id)
{
    g_speed[id] = bool:(!is_user_bot(id) && !is_user_hltv(id));
}

public client_disconnected(id)
{
    ClearSyncHud(id, hudsync);
}

@clcmd_speed(const id)
{
    g_speed[id] = !g_speed[id];

    if(!g_speed[id])
    {
        ClearSyncHud(id, hudsync);
    }
}

@CBasePlayer_PostThink(const id)
{
    if(!g_speed[id] || ++g_skipframes[id] < cvar_updatepersec)
    {
        return;
    }

    static Float:velocity[3], Float:speed, color[2];
    get_entvar(id, var_velocity, velocity);

    speed = vector_length(velocity);

    switch(floatround(speed))
    {
        case 0: {
            return;
        }
        case 1..400: {
            color[0] = 255;
            color[1] = 0;
        }
        case 401..700: {
            color[0] = 255;
            color[1] = 255;
        }
        default: {
            color[0] = 0;
            color[1] = 255;
        }
    }

    set_hudmessage(color[0], color[1], 0, -1.0, 0.75, 0, 0.0, 0.2, 0.01, 0.0);
    ShowSyncHudMsg(id, hudsync, "%3.2f u/s", speed);

    g_skipframes[id] = 0;
}

I think it is good now. Do I need update anymore?

speedometer.png
 
Последнее редактирование:
Сообщения
2,720
Реакции
2,997
Помог
60 раз(а)
Use if/else statement instead switch/case. But better will be calculate color by speed dynamically (by math) and add CVar for setup maximum player speed for 'Good' color. Because in different servers maximum speed will be differ.

When you die, you see the speed of person you watch.
Need to add some check like 'is player observer'. Because player may just play for camera like ghost and will see speed but it speed is not important for gameplay and will flood to net channel.

If u want optimisation - u should think about net channel too. It is very important, this is very important, especially for servers with poor internet.

Usage of ReAPI in plugins not optimize many logic mistakes in many plugins. This is necessary to know and remember.
 
Сообщения
2,720
Реакции
2,997
Помог
60 раз(а)
I have a few ideas for the speedometer.
1) Color configuration (need CVar for set color, disable colors, set by speed.). rsm_color < 0, RRRGGGBBB>
2) add CVar to choose HUD type (hud, dhud, center print, etc)
 
Последнее редактирование:
Сообщения
78
Реакции
65
I think its good idea to let admins or even each user to change format of the displayed string.
Maybe something in server config like that speedometer "Your speed is %s."
Or user command in chat like /speed I fly with speed of sound plus %s
 
Сообщения
2,720
Реакции
2,997
Помог
60 раз(а)
Сообщения
78
Реакции
65
wopox1337, Reasonably. I thought its good idea because i just played on bhop server where speed displayed as [xxx] and its quite good looking. Now i guess both variants are good enough.
 
Сообщения
103
Реакции
179
I did 0.2, but sometimes it blinks. What i should do? 1.0 etc?
This is problem which I faced too. Guess it happens because HUD text lifetime not reset after receiving new message, and when lifetime tooks then fade-out starts and it look like blink. I set text lifetime to around 99999 and blink stopped happens. In this case, if you want to hide text, just show empty text to client.
 

IXY

Сообщения
103
Реакции
9
Сразу извиняюсь за очень глупый вопрос, что-то просмотрел код и не смог найти...

Как отключить включение худа при заходе на сервер? (Хочу, чтобы новые игроки не видели худ, только при команде /speed включали при необходимости.)
 
Сообщения
1,419
Реакции
2,509
Помог
59 раз(а)
Сразу извиняюсь за очень глупый вопрос, что-то просмотрел код и не смог найти...

Как отключить включение худа при заходе на сервер? (Хочу, чтобы новые игроки не видели худ, только при команде /speed включали при необходимости.)
Здесь ставится при заходе на сервер.

Код:
public client_putinserver(id) {
    g_speed[id] = bool:(!is_user_bot(id) && !is_user_hltv(id));
}
Если игрок не бот и не HLTV, то ставится true. Можно для всех сразу поставить false.
 

IXY

Сообщения
103
Реакции
9
twisterniq, получилось, спасибо.
Код:
public client_putinserver(id) {
    g_speed[id] = bool:(!is_user_bot(id) && !is_user_hltv(id) && !is_user_connected(id));
}
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу