AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Trouble with cs_set_user_defuse (https://forums.alliedmods.net/showthread.php?t=101026)

Alucard^ 08-20-2009 02:21

Trouble with cs_set_user_defuse
 
Hi... i have a trouble with this function....

For example i set:

PHP Code:

cs_set_user_defuse(id125500

But when the round end and i respawn the color of defuse back to green =/

I tried with:

PHP Code:

RegisterHam(Ham_Spawn"player""PlayerSpawn")

...

public 
PlayerSpawn(id)
        
cs_set_user_defuse(id125500

But nothing.

Exolent[jNr] 08-20-2009 02:50

Re: Trouble with cs_set_user_defuse
 
Code:
#include < amxmodx > new const g_iDefuserColor[ 3 ] = { 255, 0, 255 }; public plugin_init( ) {     register_message( get_user_msgid( "StatusIcon" ), "MessageStatusIcon" ); } public MessageStatusIcon( iMsgId, iDest, iReceiver ) {     static szIcon[ 32 ];     get_msg_arg_string( 2, szIcon, 31 );         if( equal( szIcon, "defuser" ) )     {         for( new i = 0; i < 3; i++ )         {             if( get_msg_arg_int( i + 3 ) != g_iDefuserColor[ i ] )             {                 set_msg_arg_int( i + 3, ARG_BYTE, g_iDefuserColor[ i ] );             }         }     } }

xPaw 08-20-2009 11:42

Re: Trouble with cs_set_user_defuse
 
Or
PHP Code:

        for( new 36i++ )
        {
            if( 
get_msg_arg_int) != g_iDefuserColor] )
            {
                
set_msg_arg_intiARG_BYTEg_iDefuserColor] );
            }
        } 

xD

SnoW 08-20-2009 12:16

Re: Trouble with cs_set_user_defuse
 
Quote:

Originally Posted by xPaw (Post 906797)
Or
PHP Code:

        for( new 36i++ )
        {
            if( 
get_msg_arg_int) != g_iDefuserColor] )
            {
                
set_msg_arg_intiARG_BYTEg_iDefuserColor] );
            }
        } 

xD

No, then you would have to do:
PHP Code:

        for( new 36i++ )
        {
            if( 
get_msg_arg_int) != g_iDefuserColor] )
            {
                
set_msg_arg_intiARG_BYTEg_iDefuserColor] );
            }
        } 

Which would be just the same exolent did. The only cpu optimization you could do is this, somehow it takes more memory obviously:
PHP Code:

new const g_iDefuserColor] = { 0002550255 }; 

:wink:

ConnorMcLeod 08-20-2009 12:24

Re: Trouble with cs_set_user_defuse
 
Quote:

Originally Posted by Alucard^ (Post 906330)
Hi... i have a trouble with this function....

For example i set:

PHP Code:

cs_set_user_defuse(id125500

But when the round end and i respawn the color of defuse back to green =/

I tried with:

PHP Code:

RegisterHam(Ham_Spawn"player""PlayerSpawn")

...

public 
PlayerSpawn(id)
        
cs_set_user_defuse(id125500

But nothing.

The fact is cs updates players hud after they spawn so, default icon values are restored.
If it's made as in standart half life coding, it is proceeded in UpdateClientData when m_fInitHUD == 1, so the icon will be set back to green after you spawn, or when you execute fullupdate command, or when you make a demo.

Try this :
PHP Code:

#include <amxmodx>
#include <cstrike>

#define VERSION "0.0.1"

public plugin_init()
{
    
register_plugin("defuser icon color"VERSION"ConnorMcLeod")

    
register_event("StatusIcon""Event_StatusIcon_defuser""be""1=1""2=defuser")
}

public 
Event_StatusIcon_defuserid )
{
    
cs_set_user_defuse(id125000)



joaquimandrade 08-20-2009 13:24

Re: Trouble with cs_set_user_defuse
 
Quote:

Originally Posted by ConnorMcLeod (Post 906846)
The fact is cs updates players hud after they spawn so, default icon values are restored.
If it's made as in standart half life coding, it is proceeded in UpdateClientData when m_fInitHUD == 1, so the icon will be set back to green after you spawn, or when you execute fullupdate command, or when you make a demo.

Try this :
PHP Code:

#include <amxmodx>
#include <cstrike>

#define VERSION "0.0.1"

public plugin_init()
{
    
register_plugin("defuser icon color"VERSION"ConnorMcLeod")

    
register_event("StatusIcon""Event_StatusIcon_defuser""be""1=1""2=defuser")
}

public 
Event_StatusIcon_defuserid )
{
    
cs_set_user_defuse(id125000)




Isn't that way an "infinite loop"?

ConnorMcLeod 08-20-2009 14:58

Re: Trouble with cs_set_user_defuse
 
I think the message sent by cs_set_user_defuse is not hookable.
I used this method because i prefer to not use register_message when it's possible, + this way you need less natives calls.

Exolent[jNr] 08-20-2009 15:00

Re: Trouble with cs_set_user_defuse
 
Code:

static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) // cs_set_user_defusekit(index, defusekit = 1, r = 0, g = 160, b = 0, icon[] = "defuser", flash = 0); = 7 params
{
        // Give/take defusekit.
        // params[1] = user index
        // params[2] = 1 = give
        // params[3] = r
        // params[4] = g
        // params[5] = b
        // params[6] = icon[]
        // params[7] = flash = 0

        // Valid entity should be within range
        CHECK_PLAYER(params[1]);

        // Make into edict pointer
        edict_t *pPlayer = MF_GetPlayerEdict(params[1]);
       
        int* defusekit = ((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT);

        if (params[2])
        {
                int colour[3] = {DEFUSER_COLOUR_R, DEFUSER_COLOUR_G, DEFUSER_COLOUR_B};
                for (int i = 0; i < 3; i++)
                {
                        if (params[i + 3] != -1)
                        {
                                colour[i] = params[i + 3];
                        }
                }

                pPlayer->v.body = 1;

                char* icon;
                if (params[6] != -1)
                {
                        int len;
                        icon = MF_GetAmxString(amx, params[6], 1, &len);
                } else {
                        icon = "defuser";
                }

                *defusekit |= HAS_DEFUSE_KIT;
                MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer);
                WRITE_BYTE(params[7] == 1 ? 2 : 1); // show (if params[7] == 1, then this should flash, so we should set two here, else just 1 to show normally)
                WRITE_STRING(icon);
                WRITE_BYTE(colour[0]);
                WRITE_BYTE(colour[1]);
                WRITE_BYTE(colour[2]);
                MESSAGE_END();
        }
        else {
                *defusekit &= ~HAS_DEFUSE_KIT;
                MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer);
                WRITE_BYTE(0); // hide
                WRITE_STRING("defuser");
                MESSAGE_END();
                pPlayer->v.body = 0;
        }

        /*
        to show:
        L 02/20/2004 - 16:10:26: [JGHG Trace] {MessageBegin type=StatusIcon(107), dest=MSG_ONE(1), classname=player netname=JGHG
        L 02/20/2004 - 16:10:26: [JGHG Trace] WriteByte byte=1
        L 02/20/2004 - 16:10:26: [JGHG Trace] WriteString string=defuser
        L 02/20/2004 - 16:10:26: [JGHG Trace] WriteByte byte=0
        L 02/20/2004 - 16:10:26: [JGHG Trace] WriteByte byte=160
        L 02/20/2004 - 16:10:26: [JGHG Trace] WriteByte byte=0
        L 02/20/2004 - 16:10:26: [JGHG Trace] MessageEnd}

        to hide:
        L 02/20/2004 - 16:10:31: [JGHG Trace] {MessageBegin type=StatusIcon(107), dest=MSG_ONE(1), classname=player netname=JGHG
        L 02/20/2004 - 16:10:31: [JGHG Trace] WriteByte byte=0
        L 02/20/2004 - 16:10:31: [JGHG Trace] WriteString string=defuser
        L 02/20/2004 - 16:10:31: [JGHG Trace] MessageEnd}       
        */
        return 1;
}

Correct. The StatusIcon message from cs_set_user_defuse( ) is sent straight to the engine.

Alucard^ 08-20-2009 17:23

Re: Trouble with cs_set_user_defuse
 
So the connor way is better?

Thx to much.


All times are GMT -4. The time now is 15:12.

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