AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Four variables into one and back (https://forums.alliedmods.net/showthread.php?t=85521)

Emp` 02-12-2009 01:28

Four variables into one and back
 
I have four variables (ranging from 0 to 15 or 0000 to 1111 depending on how you want to look at it) and I need them stored into a single variable (and also be able to retrieve the four numbers back). I realize that it can easily be done, but I don't have time to figure it out exactly.

ConnorMcLeod 02-12-2009 01:48

Re: Four variables into one and back
 
You could use a system like this (see the Alloc_Color stock) :

http://forums.alliedmods.net/showthr...060#post754060

Emp` 02-12-2009 01:49

Re: Four variables into one and back
 
I really just wanted someone to do it for me :wink:

ConnorMcLeod 02-12-2009 01:51

Re: Four variables into one and back
 
Something like :

Code:

4Vars1One(a,b,c,d)
{
    return (d + (c<<4) + (b<<8) + (a<<12))
}

??

jim_yang 02-12-2009 07:16

Re: Four variables into one and back
 
Code:

#include <amxmodx>
 
#define PLUGIN    "Test"
#define AUTHOR    "Jim"
#define VERSION    "1.0"
 
#define MAKEWORD(%1,%2,%3,%4) ((((%1)&0xF)<<12)|(((%2)&0xF)<<8)|(((%3)&0xF)<<4)|((%4)&0xF))
#define GET_1(%1) ( (%1)>>12 & 0xF )
#define GET_2(%1) ( (%1)>>8  & 0xF )
#define GET_3(%1) ( (%1)>>4  & 0xF )
#define GET_4(%1) ( (%1)    & 0xF )
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_clcmd("test", "test")
}
 
public test(id)
{
    new a = 1
    new b = 5
    new c = 7
    new d = 13
    new e = MAKEWORD(a,b,c,d)
    console_print(id, "%d %d %d %d", a, b, c, d)
    console_print(id, "%d %d %d %d", GET_1(e), GET_2(e), GET_3(e), GET_4(e))
    return 1
}



All times are GMT -4. The time now is 16:55.

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