Advertisement
Guest User

TAMods v0.4 basic damage numbers

a guest
Jul 7th, 2015
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. -- This function is called everytime a damage number should be created, instead of the original function
  2. function onDamageNumberCreate(dam_nums, number, loc, is_shield)
  3.    -- Create a new instance of DamageNumber. The default time that it takes before a damage number fades out is 1.70
  4.    local num = DamageNumber(number, 1.70, loc, is_shield)
  5.    -- Set the original color
  6.    num.color = rgb(255, 255, 255)
  7.    -- Add the new damage number to the original array
  8.    dam_nums:add(num)
  9. end
  10.  
  11. -- This function is called once per frame to update the attributes of the damage numbers and draw them
  12. function onDamageNumberUpdate(dam_nums, hud, delta)
  13.    local i = 0
  14.    -- Loop over every damage numbers
  15.    while i < dam_nums:size() do
  16.       -- Get the current damage number we're working on
  17.       local curr = dam_nums:get(i)
  18.       -- Make time pass for the damage number
  19.       curr.time = curr.time - delta
  20.       -- If the damage number's timer is finished
  21.       if curr.time <= 0 then
  22.        -- Remove the damage number from the array and update the index
  23.          dam_nums:remove(i)
  24.        -- This has to be done because the element at i+1 before the removal will move to index i
  25.        -- So without this line there's a damage number that would not be treated when a damage number is removed
  26.          i = i - 1
  27.       else
  28.        -- If the damage number is still alive, we have to draw it, so we create a vector for its location
  29.          local loc = Vector(curr.location.x, curr.location.y, curr.location.z)
  30.        -- Check that the location is not located behind the player, it would be useless to draw it there
  31.          if isOnScreen(hud, loc) then
  32.           -- Project the world location to get the on-screen x and y coordinates of the damage number
  33.             loc = project(hud, loc)
  34.           -- Set the depth of the number to the depth of the real location
  35.             loc.z = curr.location.w
  36.           -- And finally draw the damage number to the screen using its color, location and a scale of 1
  37.             drawDamageNumber(hud, tostring(curr.number), curr.color, loc, 1, 1)
  38.          end
  39.       end
  40.       i = i + 1
  41.    end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement