AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how to format bit values (https://forums.alliedmods.net/showthread.php?t=147459)

drekes 01-09-2011 13:49

how to format bit values
 
i'm trying to log all the parameters of Ham_TakeDamage but for damagebits i get 32 if i fell to my death.
But how do i format it to see which bits are used ?

PHP Code:

public FwdTakeDamagePlayerPre(victiminflictorattackerFloatDamagedamagebits)
{
    
    new 
Data[128];
    
formatex(Datacharsmax(Data), "^nvictim = %i^ninflictor = %i^nattacker = %i^n Damage = %.2f^n bits = %i",
    
victiminflictorattackerDamagedamagebits);
    
    
log_to_file("addons/amxmodx/takedamagelog.txt"Data);


i know this is a bad way to log it, but it's just to see the parameters.

This is the output when i fell to my death:
Code:

L 01/09/2011 - 19:44:10: Log file started (file "cstrike\addons\amxmodx\takedamagelog.txt") (game "cstrike") (amx "1.8.1.3746")
L 01/09/2011 - 19:44:10:
victim = 1
inflictor = 0
attacker = 0
 Damage = 312.50
 bits = 32


fysiks 01-09-2011 14:13

Re: how to format bit values
 
It's binary, there is only one answer. http://acc6.its.brooklyn.cuny.edu/~g.../nav2tool.html

Programmatically, you can loop and compare each bit to the damage bit variables (hlsdk_const.inc).

drekes 01-09-2011 14:17

Re: how to format bit values
 
I get the binary stuff, but i don't know how to convert it to (1<<0) for example.
I'll try to loop and compare them.

Thanks.

fysiks 01-09-2011 14:20

Re: how to format bit values
 
Quote:

Originally Posted by drekes (Post 1389958)
I get the binary stuff, but i don't know how to convert it to (1<<0) for example.
I'll try to loop and compare them.

Thanks.

1<<0 is just a scripting representation of a binary number. There are probably ways to find out the bit position without looping. I would suggest looking at the link Bugsy posted for "bit hacks".

drekes 01-09-2011 14:22

Re: how to format bit values
 
will do, thanks.

Bugsy 01-09-2011 15:21

Re: how to format bit values
 
If you don't find anything in the thread fysiks directed you to, try this.

PHP Code:

for ( new 32 p++ )
{
     if ( 
iDmgBits & ( << ) )
          
client_printprint_chat "( 1 << %d ) was found" );



drekes 01-09-2011 15:24

Re: how to format bit values
 
Thanks Bugsy, and thanks for your bit tutorial too, it's been very helpful.


All times are GMT -4. The time now is 02:01.

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