When my armor is 1337 and I try print(LocalPlayer():armor()) it just gives me 57? 100 gives 100, 150 gives 150, 250 gives 250, 500 gives 244, 1000 gives 232… Weird
Its something to do with the engine cant take more then a number. (I cant really explain it :3) But it’s not a bug.
How to get the real amount of armor then?
If memory serves, armor is networked as a byte/char. Which means it supports values between and including 0 to 255 and you are seeing the overflow behavior. You will need to network the armor yourself.
Good explaining there!
I was JUST gonns say that… they send it as one byte which turns it into 0-255 before it does that, you probbably need to redo the armor system with a usermessage that contains a short instead of a char
Thx! Got it work!
] lua_run_cl print(1337%256) 57
Thats why 1337 turns into 57,
] lua_run_cl print(2^16) 65536
with a short you can have 65535 as max, with a long…
] lua_run_cl print(2^32) 4294967296
4294967295 is max with long, use long/short depending on what you need it for
though its only half of the max due to negatives, i recommend if you want to use amounts thats really high you substract: 32768
on the server, then on the client who gets the message you add 32768 to get the value, this makes it possible to use really high amounts
This is technically incorrect.
Long ( int64 ): -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807
Integer ( int32 ): -2,147,483,647 to 2,147,483,647
Short ( int16 ): -32,767 to 32,767
So the Long value you are quoting is actually the max value of uint32.
a long in a usermessage is 4 bytes
Then it’s not actually a long .
Someone should do double, that would be cool. but i doubt someone will use values up to 18446744073709551616 (64 bits)
He could also keep the stock armor value and simply multiply it accordingly for display on client and for damage reduction on server no?
It’d be easier to simply use a DTInt.
local function Tick( ) local k, v for k, v in ipairs( player.GetAll( ) ) do if ValidEntity( v ) then v:SetDTInt( 3, v:Armor( ) ) end end end hook.Add( "Tick", "NWArmor Tick", Tick )
But then you have to draw the armor yourself clientside, which isn’t that much of a problem if you are running a custom gamemode.
He could also size up his armor system to fit in 255
but i’m just saying that because the builtin armor system is probably more efficient network wise than sending variables around.