Raised This Month: $32 Target: $400
 8% 

UserMessages to New Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheXeon
Member
Join Date: May 2016
Old 02-07-2018 , 17:06   UserMessages to New Syntax
Reply With Quote #1

Hey all! I'm updating SMLIB to new syntax, and want to implement methodmaps properly for UserMessages. Is the following valid or even correct?

PHP Code:
stock bool Client_ScreenFade(int clientint durationint modeint holdtime=-1int r=0int g=0int b=0int a=255bool reliable=true)
{
    
Handle userMessage StartMessageOne("Fade"client, (reliable?USERMSG_RELIABLE:0)); // Can view_as be used here to convert to Protobuf/BfWrite?

    
if (userMessage == null) {
        return 
false;
    }

    if (
GetFeatureStatus(FeatureType_Native"GetUserMessageType") == FeatureStatus_Available &&
        
GetUserMessageType() == UM_Protobuf) {

        
Protobuf message UserMessageToProtobuf(userMessage); // Is this valid, and does this need to be deleted below?

        
int color[4];
        
color[0] = r;
        
color[1] = g;
        
color[2] = b;
        
color[3] = a;

        
message.SetInt("duration",   duration);
        
message.SetInt("hold_time",  holdtime);
        
message.SetInt("flags",      mode);
        
message.SetColor("clr",        color);
    }
    else {

        
BfWrite message UserMessageToBfWrite(userMessage); // Is this valid, and does this need to be deleted below?

        
message.WriteShort(duration);    // Fade duration
        
message.WriteShort(holdtime);    // Fade hold time
        
message.WriteShort(mode);        // What to do
        
message.WriteByte(r);            // Color R
        
message.WriteByte(g);            // Color G
        
message.WriteByte(b);            // Color B
        
message.WriteByte(a);            // Color Alpha
    
}
    
EndMessage();

    return 
true;

The wiki for UserMessages is still using old syntax/non-methodmapped functions, so this could also be used to update the wiki too :)

Last edited by TheXeon; 02-07-2018 at 17:06. Reason: Updated to PHP tags
TheXeon is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 02-08-2018 , 03:45   Re: UserMessages to New Syntax
Reply With Quote #2

Seems fine to me. All UserMessageToXXX does is return the same Handle but view_as-ed, so if you want to do view_as manually it'd still work but I wouldn't recommend it.
As for the wiki, a lot of stuff on there is outdated. Feel free to edit/fix it when you find something. You can log in using your AM account and make edits.
hmmmmm is offline
Reply


Thread Tools
Display Modes

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 11:57.


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