Raised This Month: $ Target: $400
 0% 

Four variables into one and back


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 02-12-2009 , 01:28   Four variables into one and back
Reply With Quote #1

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.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-12-2009 , 01:48   Re: Four variables into one and back
Reply With Quote #2

You could use a system like this (see the Alloc_Color stock) :

http://forums.alliedmods.net/showthr...060#post754060
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 02-12-2009 , 01:49   Re: Four variables into one and back
Reply With Quote #3

I really just wanted someone to do it for me
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-12-2009 , 01:51   Re: Four variables into one and back
Reply With Quote #4

Something like :

Code:
4Vars1One(a,b,c,d)
{
    return (d + (c<<4) + (b<<8) + (a<<12))
}
??
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 02-12-2009 , 07:16   Re: Four variables into one and back
Reply With Quote #5

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
}
__________________
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
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 16:55.


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