new var1[MAX_PLAYERS],
var2[MAX_PLAYERS],
var3[MAX_PLAYERS],
var4[MAX_PLAYERS],
var5[MAX_PLAYERS],
var6[MAX_PLAYERS],
var7[MAX_PLAYERS],
var8[MAX_PLAYERS],
var9[MAX_PLAYERS],
var10[MAX_PLAYERS];
// ...
var1[playerid] = 2;
var2[playerid] = 0;
var3[playerid] = 9;
var4[playerid] = 4;
var5[playerid] = 6;
var6[playerid] = 3;
var7[playerid] = 5;
var8[playerid] = 4;
var9[playerid] = 1;
var10[playerid] = 1;
// ...
printf("var 1: %i", var1[playerid]); // output "var 1: 2"
printf("var 2: %i", var2[playerid]); // output "var 2: 0"
printf("var 3: %i", var3[playerid]); // output "var 3: 9"
printf("var 4: %i", var4[playerid]); // output "var 4: 4"
printf("var 5: %i", var4[playerid]); // output "var 5: 6"
printf("var 6: %i", var4[playerid]); // output "var 6: 3"
printf("var 7: %i", var4[playerid]); // output "var 7: 5"
printf("var 8: %i", var4[playerid]); // output "var 8: 3"
printf("var 9: %i", var4[playerid]); // output "var 9: 1"
printf("var 10: %i", var4[playerid]); // output "var 10: 1"
#include <combinations>
// Use defines or something for avoid confusions
#define COMBINATION_VAR_1 (0)
#define COMBINATION_VAR_2 (1)
#define COMBINATION_VAR_3 (2)
#define COMBINATION_VAR_4 (3)
#define COMBINATION_VAR_5 (4)
#define COMBINATION_VAR_6 (5)
#define COMBINATION_VAR_7 (6)
#define COMBINATION_VAR_8 (7)
#define COMBINATION_VAR_9 (8)
#define COMBINATION_VAR_10 (9)
new pCombs[MAX_PLAYERS];
// ...
SetCombination(pCombs[playerid], COMBINATION_VAR_1, 2);
SetCombination(pCombs[playerid], COMBINATION_VAR_2, 0);
SetCombination(pCombs[playerid], COMBINATION_VAR_3, 9);
SetCombination(pCombs[playerid], COMBINATION_VAR_4, 4);
SetCombination(pCombs[playerid], COMBINATION_VAR_5, 6);
SetCombination(pCombs[playerid], COMBINATION_VAR_6, 3);
SetCombination(pCombs[playerid], COMBINATION_VAR_7, 5);
SetCombination(pCombs[playerid], COMBINATION_VAR_8, 4);
SetCombination(pCombs[playerid], COMBINATION_VAR_9, 1);
SetCombination(pCombs[playerid], COMBINATION_VAR_10, 1);
// ...
printf("comb 1: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_1)); // output "comb 1: 2"
printf("comb 2: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_2)); // output "comb 2: 0"
printf("comb 3: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_3)); // output "comb 3: 9"
printf("comb 4: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_4)); // output "comb 4: 4"
printf("comb 5: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_5)); // output "comb 5: 6"
printf("comb 6: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_6)); // output "comb 6: 3"
printf("comb 7: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_7)); // output "comb 7: 5"
printf("comb 8: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_8)); // output "comb 8: 4"
printf("comb 9: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_9)); // output "comb 9: 1"
printf("comb 10: %i", GetCombination(pCombs[playerid], COMBINATION_VAR_10)); // output "comb 10: 1"
new val = GetCombination(my_var, my_slot) + 1; // Increae
SetCombination(my_var, my_slot, val);
new val = GetCombination(my_var, my_slot) - 1; // Decrease
SetCombination(my_var, my_slot, val);
//
new val = GetCombination(my_var, my_slot);
SetCombination(my_var, my_slot, ++val); // Increase
new val = GetCombination(my_var, my_slot);
SetCombination(my_var, my_slot, --val); // Decrease
// 10,000 iterations [Set] Tick: 33ms (0.0033 ms) [Get] Tick: 24ms (0.0024 ms) [Set] Tick: 35ms (0.0035 ms) [Get] Tick: 18ms (0.0018 ms) [Set] Tick: 31ms (0.0031 ms) [Get] Tick: 18ms (0.0018 ms)
Wow, that's cool, it's kinda like rBits but it's kinda better IMHO. Good job.
I don't understand the concept of how it's working, but however it's working |
// SetCombination:
comb[9 - slot] = (1 <= value <= 9) ? 48 + value : 48;
// GetCombination:
if (48 <= (slot = comb[9 - slot]) <= 57) return slot - 48;
The idea is good. I'd probably use something like this:
pawn Код:
|
stock SetCombination(&var, slot, value)
{
new comb[11];
format(comb, 11, "%010i", var);
comb[9 - slot] = (1 <= value <= 9) ? 48 + value : 48;
return -1;
}
stock GetCombination(var, slot)
{
new comb[11];
format(comb, 11, "%010i", var);
if(48 <= (slot = comb[9 - slot]) <= 57) return slot - 48;
return 0;
}
stock SetCombination(&var, slot, value)
{
new comb[11];
format(comb, 11, "%010i", var);
comb[9 - slot] = (1 <= value <= 9) ? 48 + value : 48;
var = strval(comb);
return 1;
}
stock GetCombination(var, slot)
{
new comb[11];
format(comb, 11, "%010i", var);
if(48 <= (slot = comb[9 - slot]) <= 57) return slot - 48;
return 0;
}
[Set] Konstantinos - 318 ms [Get] Konstantinos - 193 ms [Set] Swedky - 291 ms [Get] Swedky - 174 ms
var = comb[9 - slot] = ...;