Raised This Month: $51 Target: $400
 12% 

Double Damage


Post New Thread Reply   
 
Thread Tools Display Modes
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-12-2020 , 08:34   Re: Double Damage
Reply With Quote #11

Quote:
Originally Posted by OciXCrom View Post
Bugsy gave you everything you need, so you don't need the iWeapons array. It's better to check the weapon using a bitstum rather than looping an entire array.
I'm using the array in multiple parts of my code which is why i really need it. I also have no idea how bitsums work
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-12-2020 , 08:40   Re: Double Damage
Reply With Quote #12

I don't know how exactly you're using it in other places, but if it's with "get_user_weapon" or some other function that can be used with the bitsum, you should stick to Bugsy's method:

Code:
new g_WeaponList = ( 1 << CSW_AK47 ) | ( 1 << CSW_M4A1 ) | ( 1 << CSW_AWP )

Then you would use this check to see if the weapon is in the list:

Code:
g_WeaponList & (1 << get_user_weapon(id))

These 2 lines are the same as doing this, but (probably) more efficient:

Code:
new const iWeapons[] = {     CSW_AK47,     CSW_M4A1,     CSW_AWP }; new iWeapon = get_user_weapon(iAttacker)     for(new i; i < sizeof(iWeapons); i++) {     if(iWeapon == iWeapons[i])     {         SetHamParamFloat(4, iDamage * 2);         break     } }
__________________

Last edited by OciXCrom; 01-12-2020 at 08:41.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-12-2020 , 12:19   Re: Double Damage
Reply With Quote #13

It's a good time to learn bitsums then. Once you understand how they work you can find new ways to handle things, many times with much less code. I wrote a tutorial in the code snippets section, or feel free to ask questions.
__________________

Last edited by Bugsy; 01-12-2020 at 12:19.
Bugsy is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-12-2020 , 12:28   Re: Double Damage
Reply With Quote #14

Thanks bugsy, will certainly do.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-12-2020 , 13:38   Re: Double Damage
Reply With Quote #15

Quote:
Originally Posted by OciXCrom View Post
I don't know how exactly you're using it in other places, but if it's with "get_user_weapon" or some other function that can be used with the bitsum, you should stick to Bugsy's method:

Code:
new g_WeaponList = ( 1 << CSW_AK47 ) | ( 1 << CSW_M4A1 ) | ( 1 << CSW_AWP )

Then you would use this check to see if the weapon is in the list:

Code:
g_WeaponList & (1 << get_user_weapon(id))

These 2 lines are the same as doing this, but (probably) more efficient:

Code:
new const iWeapons[] = {     CSW_AK47,     CSW_M4A1,     CSW_AWP }; new iWeapon = get_user_weapon(iAttacker)     for(new i; i < sizeof(iWeapons); i++) {     if(iWeapon == iWeapons[i])     {         SetHamParamFloat(4, iDamage * 2);         break     } }
It is more efficient. Bitsums method is O(1)(always executes in constant time) and array is O(sizeof array)(grows linearly with the array dimension).
__________________

Last edited by HamletEagle; 01-12-2020 at 13:39.
HamletEagle is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-13-2020 , 09:03   Re: Double Damage
Reply With Quote #16

I'm not only using the array for get_user_weapon(), i also use it to set the bpammo using cs_set_user_bpammo, can this also be done with the bitsums then?

PHP Code:
cs_set_user_bpammo(idiWeapons[item], 255); 
I've read Bugsy's thread multiple times but i still can't seem to figure out the purpose of bitsums. I understand that 1 byte = 8 bits, but further as that it won't come through to be honest.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2020 , 09:21   Re: Double Damage
Reply With Quote #17

Quote:
Originally Posted by Napoleon_be View Post
I'm not only using the array for get_user_weapon(), i also use it to set the bpammo using cs_set_user_bpammo, can this also be done with the bitsums then?

PHP Code:
cs_set_user_bpammo(idiWeapons[item], 255); 
I've read Bugsy's thread multiple times but i still can't seem to figure out the purpose of bitsums. I understand that 1 byte = 8 bits, but further as that it won't come through to be honest.
Can you show the full code/function where you use set bp ammo?
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-13-2020 , 09:38   Re: Double Damage
Reply With Quote #18

Quote:
I've read Bugsy's thread multiple times but i still can't seem to figure out the purpose of bitsums.
I know this thread is not about bitsum help, so sorry if I'm going offtopic.

The idea behind bitsums is that since in a variable there are 32 bits(or 4 bytes) each individual bit can be used to store a piece of information.
Usually, people use arrays for this purpose, but in some cases(when you want to store at most 32 values) you can use a single variable instead of an array.

Assume you run some kind of car leasing company and you have 32 cars. At any point you need to know which cars are available and which were leased.
You can do this by:
PHP Code:
#define MAX_CARS 32

new leasedCars[MAX_CARS]

leasedCars[i] = if car is leased
leasedCars
[i] = 0 otherwise

if(leasedCars[3] == 1)  //3rd car is leased
if(leasedCars[8] == 0//8th car is available 
But this can in fact be done without an array, with one single variable.

PHP Code:
new leasedCars 
Since our cars are indexed from 0 to 31(max 32 cars) we can say that if bit i from leasedCars is 1 then i-th car is leased. Otherwise, it is available and can be given to a customer.

Code:
Assume: 
leasedCars = 00000000 00000000 00000000 00000000 (the binary represenation of the value stored in leasedCars)

Assume we want to see if 3rd car is available. We check the 3rd bit(start counting from right to left, first bit has index 0) - it is the bit in bold, red

00000000 00000000 00000000 00000000

As you can see the 3rd bit is 0 so the car is indeed available. We give it to the customer and mark it as leased. 

leasedCars becomes:

leasedCars = 00000000 00000000 00000000 00001000

Later we want to check again if car 3 is available or not, we check the 3rd bit and see it is 1, which means the car is leased.
Then we may check for another car, let's say 8th car. We see the 8th bit is 0, we give that car to the customer and mark it as leased.

leasedCars = 00000000 00000000 00000001 00001000

Now leasedCars tells us that car 3 and 8 are leased and all other cars are available.
I will not go into how you set each individual bit to 0/1 and how you check the value of a specific bit, you can read about that in Bugsy's tutorial.

But why would you do that?
It can save space(tho it is negligible and I would not advise you to use bitsums solely for saving space), it is faster(but still negligible) and the important thing it is convenient and sometimes simplies the logic of your code.

For example, space:
For bitsum method: 4 bytes(one variable)
For array method: 32(array size) x 4 bytes(each entry inside the array has 4 bytes) = 128 bytes.
__________________

Last edited by HamletEagle; 01-13-2020 at 09:47.
HamletEagle is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-13-2020 , 11:21   Re: Double Damage
Reply With Quote #19

@Bugsy,

PHP Code:
public VipMenuHandler(idmenuitem)
{
    if(!
is_user_alive(id))
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    
bUsedMenu[id] = true;
    
bHasWeapon[id] = true;
    
    
strip_user_weapons(id);
    
give_item(id"weapon_knife");
    
give_item(idszWeapons[item]);
    
give_item(id"weapon_deagle");
    
cs_set_user_bpammo(idiWeapons[item], 255);
    
cs_set_user_bpammo(idCSW_DEAGLE255);
    
    
set_pev(idpev_viewmodel2szWeaponModels[item]);
    
    
ColorChat(idGREEN"[Vip-Menu]:^3 You took: %s"szMenuItems[item]);
    
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;

@HamletEagle, Thanks for the explenation, i get what you're telling me and i'll get deeper into bugsy's thread on how to set those bits to 0 or 1. Also i didn't know u started counting from right to left. Also one last question, is the first bit always 0 or can it also be set to 1?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2020 , 12:32   Re: Double Damage
Reply With Quote #20

Depends on the value stored. There are 8 bits in a byte, if the value of the byte is 0 the bits will be 0000 0000. If the byte holds 1, the bits will be 0000 0001.

0 = 0000 0000
1 = 0000 0001
2 = 0000 0010
3 = 0000 0011
4 = 0000 0100
5 = 0000 0101
6 = 0000 0110
__________________
Bugsy 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 04:45.


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