Guest User

shwoop

a guest
Dec 13th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local TEAM_RESISTANCE = {
  2.     [TEAM_THIEF] = {
  3.         DMG_POISON,
  4.     },
  5. }
  6.  
  7. hook.Add("EntityTakeDamage", "resistance stuff", function(pPlayer, CDmgInfo)
  8.     local tResistance = TEAM_RESISTANCE[pPlayer:Team()] -- Get their resistance stuffs
  9.     if not tResistance then return end -- The index doesn't exist
  10.    
  11.     local iDmgType = CDmgInfo:GetDamageType() -- Returns a bitflag, explained below
  12.     for k,v in ipairs(tResistance) do -- lets iterate cause cool
  13.         if (bit.band(iDmgType, v) == 0) then -- iirc this is how you do it in glua, not certain though
  14.             return false
  15.         end
  16.     end
  17. end)
  18.  
  19.  
  20. --[[ BIT FLAGS
  21.  
  22. A bit flag is a 1 or a 0 in a binary number, for example
  23. In this example we'll use recipes ig
  24.  
  25. 0001
  26. The first bit here may represent whether or not the food needs to be put in the oven
  27.  
  28. 0010
  29. This may represent whether or not it needs to be mixed
  30.  
  31. 0100
  32. This may represent whether or not it is dairy
  33.  
  34. 1000
  35. This may represent whether or not it is halal
  36.  
  37.  
  38. Just like above, if I wanted to check if my recipe was halal, I would check if the last bit (1000) is set to 1, if it is, then it is halal.
  39.  
  40. If I wanted to check if it was halal AND dairy, then I would check if the two bits (1000) and (1100) are set to 1.
  41.  
  42. That's pretty much it ig
  43. ]]--
Advertisement
Add Comment
Please, Sign In to add comment