Raised This Month: $ Target: $400
 0% 

Cvar: Add number together


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 04-26-2012 , 07:41   Cvar: Add number together
Reply With Quote #1

How can i make a cvar in the following way.

// 1 - Grenade bonus
// 2 - HP Bonus
// 4 - Money bonus
// 8 - Something else
// 16 - Something else
// 32 - Something else etc.

This should be added together in the same cvar for example if the client selects grenade, hp, and money bonus the cvar should be 7.

How can i read this in a plugin and how do i know what options are selected?

Thank you.

Last edited by DjOptimuS; 04-26-2012 at 07:41.
DjOptimuS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-26-2012 , 08:13   Re: Cvar: Add number together
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?go=func&id=178
__________________
Arkshine is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 04-26-2012 , 08:59   Re: Cvar: Add number together
Reply With Quote #3

i guess that i explained it wrong.

I want to make a plugin to give certain bonuses on different events and the server owner must set his cvar, the server cvar, to a certain number, in order to have the bonuses that he wants on his server.

The cvar it will be for example sv_bonuses

Example of bonuses

// 1 - Grenade bonus
// 2 - HP Bonus
// 4 - Money bonus
// 8 - Bomb plant bonus
// 16 - Bomb defuse bonus
// 32 - Bomb pickup bonus

If the server owner wants to have only hp bonus and bomb pickup bonus, he should set his server cvar to 2 + 32 which means that sv_bonuses will be set to 34 (serverside).
DjOptimuS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-26-2012 , 09:35   Re: Cvar: Add number together
Reply With Quote #4

You don't understand I guess.

Using letters are more easy, you don't need to calculate.

// a - Grenade bonus
// b - HP Bonus
// c - Money bonus
// d - Bomb plant bonus
// e - Bomb defuse bonus
// f - Bomb pickup bonus

For example : random_cvar "ac"

Register your cvar normally. Then to get a sum of flags, you use read_flags().

To know what bonuses, you can make an enum :

enum ( <= 1 )
{
BONUS_GRENADE = 1,
BONUS_HP,
BONUS_MONEY,
BONUS_BOMB_PLANTED,
BONUS_BOMB_DEFUSED,
BONUS_BOMB_PICKED_UP
};

Then, to check, retrieve the sum of bits with read_flags and get_pcvar_string :

new flags[ 12 ];
get_pcvar_string( pointer, flags, charsmax( flags ) );

new bitsum = read_flags( flags );

And all you need to do :

if( bitsum & BONUS_GRENADE )
{

}

if( bitsum & BONUS_HP )
{

}

etc.


You can also use numbers, and you would not need to use read_flags. You could cache directly the value with get_pcvar_num.

You get the ideas.
__________________
Arkshine is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 04-26-2012 , 09:39   Re: Cvar: Add number together
Reply With Quote #5

I understand now, thank you very much for your help.
DjOptimuS is offline
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 07:49.


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