• Disabling fall damage with KeyDown/KeyPressed/KeyReleased in a SWEP
    18 replies, posted
Hello again, Facepunch. So I'm trying to set up a weapon that, whenever I hold down duck{or sprint or the jump button itself, just any button thats a valid ENUM), it negates all fall damage. I already know a basic understanding of KeyPressed/Released/Down, so thats not too bad. But, what I'm trying to do disable fall damage when i do some sort of superjump, i guess? So any advice or tips on how to make this happen would be appreciated.
GM/EntityTakeDamage CTakeDamageInfo/IsFallDamage
Alright, how would I implement that in my swep? Like, I got this, yeah? if ply:KeyDown( IN_DUCK ) then --insert fall damage remover here-- elseif not ply:KeyDown( IN_DUCK ) then --insert fall damage restorer here-- end
GM/GetFallDamage could always use this as well if you wish.
Only reason i didn't say that is because I'm not sure if returning 0 blocks the damage from applying at all (e.g. making noise) whereas with takedamage you can completely block it. In the SWEP store whether or not it should prevent damage as a variable, and in the hook check if its a player, if they have the swep, and if it should prevent damage.
Can you be more specific and try using a code example please? im not sure how to do that.
Check in GM/EntityTakeDamage using Player/GetActiveWeapon if the weapon the player is currently holding is the one you want to disable fall damage for and if the player is pressing his duck-key using Player/KeyDown(IN_DUCK), if so use CTakeDamageInfo/SetDamage (-CTakeDamageInfo/GetDamage). I recommend using math.Clamp to prevent players from "cheating" their health up into infinite.
Could i get that in a code box like This please
Why would we spoon feed you. At least try to do it yourself, I gave you everything you need. If you can't do that, post a job on gmodstore.
Because I have no idea how to properly implement that in. And that's kinda rude referring to it as "spoonfeeding." :/
Doing something like this REQUIRES at least a bit of Lua knowledge and as I said you can post a job on gmodstore or you learn how to do it yourself (Beginner Tutorial Intro).
If you want code i want coin
Welp, i managed to figure it out anyway. It's this. I just put this somewhere in my SWEP:Think category and it works! hook.Add("GetFallDamage", "NegateFallDamageSWEP", function(pPlayer) if (pPlayer:KeyDown(IN_DUCK)) then local pWeapon = pPlayer:GetActiveWeapon() if (pWeapon:IsValid() and pWeapon:GetClass() == "my_swep") then return 0 end end end)
while it may technically work, that is not a good way to do this because its going to keep adding that hook every tic on that swep. You only need to add it once for this to work.
He actually only overrides it but still, you are right, a very bad practice to do it like that.
And, how would I be a ble to do that then? How do you only add it "once?"
By not using it in a Think hook. Place it somewhere else, outside of any function.
Works.
update: sometimes it works as intended, sometimes it doesnt. It is only confirmed to work CONSISTENLY inside of the Think Category.
Sorry, you need to Log In to post a reply to this thread.