Im still working on my Addon that reacts different to each type of damage. For that i used networking where the server sends the damagetype to the player by sending the Number that the damagetype is, according to this list DMG Enumerations
Which WOULD work fine, if the damage types are actually what the list says...the addon reacted to falldamage and bulletdamage just fine, but to stuff like toxic acid it just reacts like it would be generic damage. For example i let the addon print the number to see what lua would see. Falldamage and bullet damage is the number that the list says.
Stuff like posion, toxic waste (like that weird water type stuff that burns you) it all returns 4 or 0. Generic Damage or Slash(sharp or so)
4, which is sharp attacks or other npc attacks always comes when like a zhombie attacks you. and 0 when im in toxic wast etc.
Is this somehow fixable? Why does the list has specific damage types for toxic acid, radation etc when in the end it just returns as 0 generic damage? If this is not fixable i can pretty much throw the addon out the window. Since it can only react to like 2 or 3 damage types...
Little list to show you what different damages/attacks return
Being Shot by a NPC or Player: (2) Bullet Damage
Falldamage: (32) Fall Damage
Toxic Acid Water: (0) Genric Damage (even tho theres a specific dmg type for that which is 1048576)
Poison Headcrap: (4) Slash damage sharp objects or other npc attacks (even tho theres 32768 and 131072 for that)
Antilon Worker Spit: (0) Generic Damage (again, there are other dmg types for that in the list that it should return)
Rollermine (256) Shock Damage (this one is ok)
Fire (8) Fire damage (this one is ok too)
I also have laserdamage in the detection but i have no idea how i could make a laser in gmod to test it out...anyone know a map with lasers that do damage?
But in the end as you can see it often returns 0 or 4 which is generic damage or other kind of attacks. But never the ACTUAL number. Like poison, acid etc. There are specific damagtypes for that so why does it return 4 or 0? I cant make my addon like that. I bet lot of other kind of damages get a wrong kind of number as well instead of their own real number...
the damage from "radioactive" water or toxic waste is actually done by a trigger_hurt
to make toxic water you need to make water and put a trigger_hurt in there
assign a damage type nilly willy so if the trigger_hurt was set to deal generic damage, the toxic water would do generic damage
This sounds more so like an issue in your code and not with Gmod.
dmgtype is what i called the parameter in the hook, and with dmgtype:GetDamageType() you get the number from that list. I simply did Net.WriteInt with it. But for some reasons in some cases in gmod it comes as 4 or 0
Use net.WriteUInt, also what bit count did you use?
16
Also whats the difference between WriteInt and WriteUInt?
I figured i let the server do the check for what dmgtype it is instead of the client. less performance needed from the client, and im sure a whole gmod server is able to do that little check
WriteUInt has double the positive number space as WriteInt since it's unsigned (no negatives), thus an extra bit is available for representing the number. DMG enumerations do use ints though so you should stick with WriteInt.
The highest DMG enumeration is 1 << 30 for DMG_BUCKSHOT, thus you need at least 30 bits to network the enumeration correctly. You should network a 32-bit int to be safe.
oh so the reason it didnt worked always was because i only had 16 bit?
The difference between net.WriteInt and net.WriteUInt is that net.WriteUInt uses unsigned numbers and net.WriteInt uses signed numbers. Unsigned numbers aren't allowed to be negative while signed numbers are.
The range of numbers that both cover are the same given the same bit count, however it's where the they start is different.
Unsigned range : 0 <= x <= 2 ^ x - 1
Signed range: -2 ^ (x - 1) <= x <= 2 ^ (x - 1) - 1
You should use 32 here. DMG enums are a bit field that need at least 30 bits, though I'd suggest 32 just to round here.
This doesn't really matter in terms of performance from either the client or the server. I'd suggest you take a look at what your code intents to do.
If the client receiver takes a look at the bit field and does a lot of different checks on it for different damage types then I'd network the integer. This makes your networking code a lot simpler. If you're simply looking for a single damage type then doing the check server side probably makes more sense.
Well first i had the dmgtype Int being networked to the client, and from there the client takes the number and lets it run through a big if elseif statement which executes the falldmg() function for example if dmgtype is 32. which is falldamage. Now i changed it to the server making the if statement, and then sending a network message. Each network message for the different damages. means i now have several util.AddNetWorkStrings, one for flaldamge, on for posion and so on..which one is better?
I'd network the integer.
so one network that sends the damagetype number and then the clienr is doing the if checks
You can do the checks on the server and client. Doing it on the server can avoid sending the net message all together, and doing it in the client can be for net verification.
Well, if i do it on the server i would need a bunch of network strings to run from, one for falldamage, one for burndamage etc. and the client runs the specific functions for the specific netmessage. So im guessing only sending the number and nothing else is better networking wise..and then the client runs the number through the if statement, that makes the right function execute.
I mean, in the end its the same amount of networking, everytime you take damage. So..not sure
Oh, I misunderstood. Just network straight to the client then and let them handle the case code.
so network the number with 32 bit and the client can have fun with the number
Sorry, you need to Log In to post a reply to this thread.