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

Director HUD Message


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Garufa
Junior Member
Join Date: Sep 2011
Location: home/Garufa/
Old 09-08-2011 , 18:43   Director HUD Message
Reply With Quote #1

Hi, I'm trying to show these messages through modules, but I can't. Can anyone help me?

Here is the code:

PHP Code:
void Show_dHudMessageedict_t *pEdict )
{
    const 
char message128 ] = "Hello world!";

    
// Green color
    
unsigned long color 160 << 8;

    
MESSAGE_BEGINMSG_ONESVC_DIRECTORNULLpEdict );

        
WRITE_BYTEstrlenmessage ) + 31 );
        
WRITE_BYTEDRC_CMD_MESSAGE );
        
WRITE_BYTE);    // effect
        
        
WRITE_LONGcolor );    // color
        
        
WRITE_LONGFixedSigned16( -1.0<< 13 ) );    // x
        
WRITE_LONGFixedSigned160.25<< 13 ) );    // y

        
WRITE_LONGFixedUnsigned160.1<< ) );    // fadeintime
        
WRITE_LONGFixedUnsigned161.5<< ) );    // fadeouttime
        
WRITE_LONGFixedUnsigned163.0<< ) );    // holdtime
        
WRITE_LONGFixedUnsigned166.0<< ) );    // fxtime

        
WRITE_STRINGmessage );

    
MESSAGE_END(  );
}

short FixedSigned16float valuefloat scale )
{
    
int output;

    
output = (int) (value scale);

    if ( 
output 32767 )
        
output 32767;

    if ( 
output < -32768 )
        
output = -32768;

    return (
short)output;
}

unsigned short FixedUnsigned16float valuefloat scale )
{
    
int output;

    
output = (int) (value scale);
    if ( 
output )
        
output 0;
    if ( 
output 0xFFFF )
        
output 0xFFFF;

    return (
unsigned short)output;

Thanks!

Last edited by Garufa; 09-08-2011 at 18:47.
Garufa is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-09-2011 , 17:41   Re: Director HUD Message
Reply With Quote #2

What is the problem exactly ?
__________________
Arkshine is offline
Garufa
Junior Member
Join Date: Sep 2011
Location: home/Garufa/
Old 09-09-2011 , 19:11   Re: Director HUD Message
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
What is the problem exactly ?
It just does not show the message. I suspect the data types I'm using.

Also, I don't understand several things:

PHP Code:
WRITE_BYTEstrlenmessage ) + 31 ); 
This should be the size of the message, but because it adds 31?

PHP Code:
WRITE_LONGFixedSigned16( -1.0<< 13 ) ); 
The scale is correct?. Why do not use either WRITE_ANGLE or WRITE_COORD?. Both write float values​​.

I look at the hud_spectator.cpp, specifically the parse of DRC_CMD_MESSAGE:

PHP Code:
msg->READ_FLOAT();    // x pos
msg->READ_FLOAT();    // y pos
                                                
msg->fadein READ_FLOAT();    // fadein
msg->fadeout READ_FLOAT();    // fadeout
msg->holdtime READ_FLOAT();    // holdtime
msg->fxtime READ_FLOAT();    // fxtime; 
As you see, it uses READ_FLOAT() to parse the values, but what should be used to write?

I'm confused.

PHP Code:
// From parsemsg.cpp

float READ_FLOATvoid )
{
    
union
    
{
        
byte    b[4];
        
float   f;
        
int     l;
    } 
dat;
    
    
dat.b[0] = gpBuf[giRead];
    
dat.b[1] = gpBuf[giRead+1];
    
dat.b[2] = gpBuf[giRead+2];
    
dat.b[3] = gpBuf[giRead+3];
    
giRead += 4;
    
//    dat.l = LittleLong (dat.l);

    
return dat.f;   

Thanks in advanced.

PD: Sorry for my english.
Garufa is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-09-2011 , 19:33   Re: Director HUD Message
Reply With Quote #4

The first arg is the length of the message all the WRITE_*.

WRITE_FLOAT doesn't exist. WRITE_LONG works with float without problem.

I don't see what's wrong. Will try myself later.
__________________
Arkshine is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-18-2011 , 01:01   Re: Director HUD Message
Reply With Quote #5

pawn use cell present 4 bytes value in 32bit system, and add tag to parse it. so the mem form is just 32bit, depend on how you read it.
Float:a = 1.0;
binary is 0011 1111 1000 0000 0000 0000 0000 0000
if you untag the a (use _: ), then it will read the bits above as an int/long (32bits) form. then you will get 1065353216.
you can see that message use write_long to send this value, and parse it use read_float, so you should pass the value using its int form of that float value.

here is the transform function
Code:
long ftol(float x)
{
    __asm mov eax, x;
}
or the c format
Code:
long ftol(float x)
{
    return *(long *)(&x);
}
then you can correctly send this message, here is an example
Code:
	float x = -1.0;
	float y = 0.25;
	float fadein = 1.0;
	float fadeout = 1.0;
	float holdtime = 6.0;
	float fxtime = 1.0;

	char msg[] = "hello world!";
	MESSAGE_BEGIN(MSG_ALL, SVC_DIRECTOR);
	WRITE_BYTE(strlen(msg) + 31);
	WRITE_BYTE(6);
	WRITE_BYTE(1);
	WRITE_LONG(160<<8);
	WRITE_LONG(ftol(x));
	WRITE_LONG(ftol(y));
	WRITE_LONG(ftol(fadein));
	WRITE_LONG(ftol(fadeout));
	WRITE_LONG(ftol(holdtime));
	WRITE_LONG(ftol(fxtime));
	WRITE_STRING(msg);
	MESSAGE_END();
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Shadows In Rain
Senior Member
Join Date: Apr 2010
Location: Russia::Siberia
Old 09-18-2011 , 10:36   Re: Director HUD Message
Reply With Quote #6

Keep style :]
Code:
inline void WRITE_FLOAT(float val)
{
	WRITE_LONG(*reinterpret_cast<float*>(&val));
}
__________________
I'm using Google translator, yarrr. |.◕‿‿◕.|
Shadows In Rain is offline
Send a message via ICQ to Shadows In Rain
Garufa
Junior Member
Join Date: Sep 2011
Location: home/Garufa/
Old 09-18-2011 , 14:34   Re: Director HUD Message
Reply With Quote #7

Quote:
Originally Posted by jim_yang View Post
pawn use cell present 4 bytes value in 32bit system, and add tag to parse it. so the mem form is just 32bit, depend on how you read it.
Float:a = 1.0;
binary is 0011 1111 1000 0000 0000 0000 0000 0000
if you untag the a (use _: ), then it will read the bits above as an int/long (32bits) form. then you will get 1065353216.
you can see that message use write_long to send this value, and parse it use read_float, so you should pass the value using its int form of that float value.

here is the transform function...
I knew the problem was in the format of the data. Thanks Jim, your explanation I unlock a great mystery, at least for me ;)
Garufa is offline
Old 10-07-2011, 02:00
johnymac001
This message has been deleted by Arkshine. Reason: spambot
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 16:44.


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