AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Replacing Name Showing (https://forums.alliedmods.net/showthread.php?t=64923)

Exolent[jNr] 12-27-2007 14:57

Replacing Name Showing
 
What I'm trying to do is replace the default name-showing when you look at a player, to a custom one that show a hud message.

Code:

new gHudSyncObj;

public plugin_init()
{
    register_event("StatusValue", "eventStatusValue", "be", "1=2", "2!0");
    gHudSyncObj = CreateHudSyncObj();
}

public eventStatusValue(id)
{
    new pid = read_data(2), red, green, blue, team = get_user_team(pid);
   
    switch(team)
    {
        case 1:
        {
            red = 255;
            green = 50;
            blue = 50;
        }
        case 2:
        {
            red = 50;
            green = 100;
            blue = 255;
        }
        default:
        {
            red = 100;
            green = 100;
            blue = 100;
        }
    }
   
    new szName[32];
    get_user_name(pid, szName, 31);
   
    ClearSyncHud(id, gHudSyncObj);
    set_hudmessage(red, green, blue, -1.0, -1.0, 0, 0.0, 0.25, 0.0, 0.0, 4);
    ShowSyncHudMsg(id, gHudSyncObj, szName);
    return PLUGIN_HANDLED;
}

It shows the message, but it only lasts for the hud time, and I expected it to last until I looked away from the player.

Also, it doesn't block the message in the bottom-left corner of the screen.

Does anyone have a different/better way to do this?

hlstriker 12-27-2007 23:08

Re: Replacing Name Showing
 
With the "StatusValue" message I think there is an argument that is set to 1 when you are looking at them, then it sends another message that sets the argument to 0 (I THINK!!! It's been awhile since I've used StatusValue).

If I am correct in the above then you can set a task to keep the hud message up until the argument is 0.

Also, the reason it's not blocking the message is because you can't block using register_event. You will need to use register_message.

Exolent[jNr] 12-28-2007 00:18

Re: Replacing Name Showing
 
heres a diff variation that i came up with after i read your post

Code:

#include <amxmodx>
#include <fakemeta>

new g_HudSyncObj;
new g_MaxPlayers;

public plugin_init()
{
    register_forward(FM_PlayerPreThink, "fwd_PlayerPreThink", 0);
    g_HudSyncObj = CreateHudSyncObj();
    g_MaxPlayers = get_maxplayers();
    set_msg_block(get_user_msgid("StatusValue"), BLOCK_SET);
}

public fwd_PlayerPreThink(id)
{
    static pid, body;
    get_user_aiming(id, pid, body, 9999);
    if(pev_valid(pid) && (0 < pid <= g_MaxPlayers) && is_user_connected(pid))
    {
        static red, green, blue, team, szName[42];
       
        team = get_user_team(pid, "", 0);
        get_user_name(pid, szName, 31);
        format(szName, 41, "%s^n(%s)", szName, (team == get_user_team(id, "", 0)) ? "Friend" : "Enemy");
       
        switch(team)
        {
            case 1:
            {
                red = 255;
                green = 50;
                blue = 50;
            }
            case 2:
            {
                red = 50;
                green = 150;
                blue = 255;
            }
            default:
            {
                red = 100;
                green = 100;
                blue = 100;
            }
        }
       
        ClearSyncHud(id, g_HudSyncObj);
        set_hudmessage(red, green, blue, -1.0, -1.0, 0, 0.0, 0.25, 0.0, 0.5, 4);
        ShowSyncHudMsg(id, szName);
    }
    return FMRES_IGNORED;
}

i dont have time to test, but how does that look?

hlstriker 12-28-2007 02:01

Re: Replacing Name Showing
 
This will display the players name and health you are looking at. Just add your team checks and whatever else to it that you had.

PHP Code:

new g_lookingHud;
new 
g_lookingAt[33];
new 
Float:g_nextHudMsg[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_forward(FM_PlayerPreThink"fwd_PlayerPreThink");
    
register_message(get_user_msgid("StatusValue"), "msg_StatusValue");
    
g_lookingHud CreateHudSyncObj();
}

public 
msg_StatusValue(msgIddestid)
{
    new 
flag get_msg_arg_int(1);
    new 
value get_msg_arg_int(2);
    
    if(
flag == 2)
    {
        if(
value 0)
            
g_lookingAt[id] = value;
        else
            
g_lookingAt[id] = 0;
    }
    
    return 
PLUGIN_HANDLED;
}

public 
fwd_PlayerPreThink(id)
{
    new 
Float:gametime get_gametime();
    
    if(
g_lookingAt[id] != && g_nextHudMsg[id] < gametime)
    {
        static 
szName[33], health;
        
health pev(g_lookingAt[id], pev_health);
        
get_user_name(g_lookingAt[id], szName32);
        
        
set_hudmessage(25500, -1.0, -1.000.00.250.00.54);
        
ShowSyncHudMsg(idg_lookingHud"%s (%i)"szNamehealth);
        
        
g_nextHudMsg[id] = gametime 0.7;
    }



ConnorMcLeod 12-28-2007 11:28

Re: Replacing Name Showing
 
Shouldn't you block StatusText message instead ?

hlstriker 12-28-2007 17:04

Re: Replacing Name Showing
 
I think that's the command I was thinking of at first when I saw this thread. I didn't even try StatusText because I saw StatusValue in X-olents code and just used that. The code I posted still works though :P

Edit:
Since StatusValue is the one that get's all of the information needed it is best to use it like we did. By blocking the StatusValue and it working there would be no need to block StatusText since it doesn't show up anyhow.

Exolent[jNr] 12-29-2007 01:40

Re: Replacing Name Showing
 
thanks hlstriker :up:


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

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