Cvar: Add number together
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. |
Re: Cvar: Add number together
|
Re: Cvar: Add number together
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). |
Re: Cvar: Add number together
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. |
Re: Cvar: Add number together
I understand now, thank you very much for your help.
|
| All times are GMT -4. The time now is 07:49. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.