Player Immunity

Started by BigcaT_, Apr 11, 2015, 01:05 PM

Previous topic - Next topic

BigcaT_

yesterday i looked through vcmp wiki, i saw function: player.Immunity accidentally.
can someone tell me how to use it? can it make player invincible?

EK.IceFlake

Yep
player.Immunity = 100;
I used this so player cannot killed when typing.

BigcaT_

Quote from: NE.CrystalBlue on Apr 11, 2015, 01:45 PMYep
player.Immunity = 100;
I used this so player cannot killed when typing.
Thanks , and what is the number 100 means?
what will happen when PlayerEndTyping in your server?
player.Immunity = 0 ?

DizzasTeR

Quote from: BigcaT_ on Apr 11, 2015, 01:51 PM
Quote from: NE.CrystalBlue on Apr 11, 2015, 01:45 PMYep
player.Immunity = 100;
I used this so player cannot killed when typing.
Thanks , and what is the number 100 means?
what will happen when PlayerEndTyping in your server?
player.Immunity = 0 ?

Yes

BigcaT_

i put this code on my script. :
function onPlayerBeginTyping( player )
{
player.Immunity = 100;
}
function onPlayerEndTyping( player )
{
player.Immunity = 0;
}

but when i type , nothing happens...

KingOfVC

try  player.Immunity = 33

DizzasTeR

Quote from: BigcaT_ on Apr 11, 2015, 02:42 PMi put this code on my script. :
function onPlayerBeginTyping( player )
{
player.Immunity = 100;
}
function onPlayerEndTyping( player )
{
player.Immunity = 0;
}

but when i type , nothing happens...

It happens, to give you a better understanding on the immunity function, use the event OnPlayerEnterVehicle and on that event put:

player.Vehicle.Immunity = 1000;
Try ramming the vehicle as much as possible And you will notice what immunity function did.

To remove it just set the immunity back to 0.

.

Quote from: StormeusBinary  | Hex  | Dec | Field
---------------------------------------
0b00001 | 0x1  |  1  | bulletproof
0b00010 | 0x2  |  2  | fireproof
0b00100 | 0x4  |  4  | explosion-proof
0b01000 | 0x8  |  8  | collision-proof
0b10000 | 0x10 |  16 | melee-proof


0 means no immunity to any damage, 31 means immunity to all damage. You can add all the numbers together or use bitwise OR/AND to toggle flags.

Because you can use bitwise operations in Squirrel then you are free to do as following:
const IMM_BULLET_PROOF = 0x1;
const IMM_FIRE_PROOF = 0x2;
const IMM_EXPLOSION_PROOF = 0x4;
const IMM_COLLISION_PROOF = 0x8;
const IMM_MELEE_PROOF = 0x10;

And then use them in your code:
// Create the flags
local flags = IMM_BULLET_PROOF | IMM_EXPLOSION_PROOF | IMM_MELEE_PROOF;

// Test if the flags are there
if (flags & IMM_BULLET_PROOF) print("++player has bullet proof immunity");
if (flags & IMM_EXPLOSION_PROOF) print("++player has explosion proof immunity");
if (flags & IMM_FIRE_PROOF) print("++player has fire proof immunity");
if (flags & IMM_MELEE_PROOF) print("++player has melee proof immunity");
if (flags & IMM_COLLISION_PROOF) print("++player has collision proof immunity");

// Test if the flags aren't there
if (!(IMM_BULLET_PROOF & flags)) print("--player doesn't have bullet proof immunity");
if (!(IMM_EXPLOSION_PROOF & flags)) print("--player doesn't have explosion proof immunity");
if (!(IMM_FIRE_PROOF & flags)) print("--player doesn't have fire proof immunity");
if (!(IMM_MELEE_PROOF & flags)) print("--player doesn't have melee proof immunity");
if (!(IMM_COLLISION_PROOF & flags)) print("--player doesn't have collision proof immunity");

// Add another flag
flags = flags | IMM_FIRE_PROOF;

// Now test the previous flag
if (flags & IMM_FIRE_PROOF) print("++player has fire proof immunity");

// Now inverse the flags
flags = ~flags

// Now the enabled flags are disabled and disabled flags are enabled
// Meaning that we have only IMM_COLLISION_PROOF flag enabled now
if (!(IMM_COLLISION_PROOF & flags)) print("--player doesn't have collision proof immunity");
if (flags & IMM_COLLISION_PROOF) print("++player has collision proof immunity");
if (!(IMM_BULLET_PROOF & flags)) print("--player doesn't have bullet proof immunity");

Anyway, in my brief usage I noticed that the results aren't exactly as expected or how you're used to in C/C++ or whatever else you might use. I got some weird results in some cases. So, be careful :D
.

BigcaT_

Thanks to all who replied. Problem SolvedĀ¬! :-*
Topic Locked.