Advertisement
VADemon

Tasermod for CS2D. Alpha (Review) Version

Jun 4th, 2015
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.84 KB | None | 0 0
  1. -- Tasermod for darijs1 :: http://unrealsoftware.de/profile.php?userid=92580
  2. -- Requested in thread http://unrealsoftware.de/forum_posts.php?post=385648
  3.  
  4. -- STUN SCRIPT
  5. if tasermod then
  6.     print("WARNING: taserMod is already running!")
  7. end
  8.  
  9. tasermod = {}
  10. tasermod.player = {}
  11. tasermod.timeMultiplier = {}
  12. tasermod.damageMultiplier = {}
  13.  
  14. -- CONFIG
  15. tasermod.taserWeapon = 34
  16. tasermod.maxDistance = 96   -- NOT IMPLEMENTED in pixels, the effective distance of taser; doesn't work beyond this point
  17. tasermod.stunDuration = 2000    -- duration of the stun in ms
  18. tasermod.slownessDuration = 8500    -- total duration of slowness effect AFTER the stun
  19.  
  20. tasermod.minDamage = 1
  21. tasermod.maxDamage = 25
  22.  
  23. tasermod.victimCanDie = true
  24. tasermod.customkillMessage = "Taser" -- possible to add an image, check out http://www.cs2d.com/help.php?cat=server&cmd=customkill#cmd
  25.  
  26. tasermod.timeMultiplier[0] = 1.25   -- No Armor and Zombie Armor
  27. tasermod.timeMultiplier[100] = 1    -- Kevlar
  28. tasermod.timeMultiplier[201] = 0.95 -- LightArmor
  29. tasermod.timeMultiplier[202] = 0.9  -- Armor
  30. tasermod.timeMultiplier[203] = 0.80 -- HeavyArmor
  31. tasermod.timeMultiplier[204] = 0.50 -- MedicArmor
  32. tasermod.timeMultiplier[205] = 0.75 -- SuperArmor
  33. tasermod.timeMultiplier[206] = 1    -- StealthSuit
  34.  
  35. tasermod.damageMultiplier[0] = 1    -- No Armor and Zombie Armor
  36. tasermod.damageMultiplier[100] = 1  -- Kevlar
  37. tasermod.damageMultiplier[201] = 1  -- LightArmor
  38. tasermod.damageMultiplier[202] = 0.9    -- Armor
  39. tasermod.damageMultiplier[203] = 0.85   -- HeavyArmor
  40. tasermod.damageMultiplier[204] = 0.30   -- MedicArmor
  41. tasermod.damageMultiplier[205] = 0.8    -- SuperArmor
  42. tasermod.damageMultiplier[206] = 1.3    -- StealthSuit
  43.  
  44. -- END OF CONFIG
  45. tasermod.stunSpeedmod = -30
  46. tasermod.stepDuration = 60 --ms, duration between speedmod calculations. 3 Frames is a decent number, because CS2D doesn't support decimal places: eg 12.75 is 12
  47.  
  48. addhook("hit", "tasermod.hitPlayer")
  49.  
  50. function tasermod.hitPlayer(victimID, attackerID, weapon, hpdmg, armordmg, rawdmg)
  51.     if weapon == tasermod.taserWeapon then
  52.         if player(victimID, "team") == 1 and player(attackerID, "team") == 2 then   -- 1=T, 2=CT
  53.            
  54.             if tasermod.processDamage(victimID, attackerID) then
  55.                 msg("©040150210" .. player(attackerID, "name") .. " used his taser on ".. player(victimID, "name"))
  56.                 tasermod.setStun(victimID)
  57.                
  58.             end
  59.            
  60.             return 1    -- don't deal cs2d damage
  61.         end
  62.     end
  63. end
  64.  
  65. function tasermod.getArmorTimeMultiplier(id)
  66.     local armor = player(id, "armor")
  67.    
  68.     if tasermod.timeMultiplier[armor] then
  69.         return tasermod.timeMultiplier[armor]
  70.        
  71.     elseif armor > 0 and armor < 100 then   -- for damaged kevlar and kevlar&helm
  72.         return tasermod.timeMultiplier[100]
  73.        
  74.     else
  75.         print("[TASERMOD] ERROR: (.getArmorTimeMultiplier): Unknown armor value of ".. armor)
  76.     end
  77. end
  78.  
  79. function tasermod.getArmorDamageMultiplier(id)
  80.     local armor = player(id, "armor")
  81.    
  82.     if tasermod.damageMultiplier[armor] then
  83.         return tasermod.damageMultiplier[armor]
  84.        
  85.     elseif armor > 0 and armor < 100 then   -- for damaged kevlar and kevlar&helm
  86.         return tasermod.damageMultiplier[100]
  87.        
  88.     else
  89.         print("[TASERMOD] ERROR: (.getArmorDamageMultiplier): Unknown armor value of ".. armor)
  90.     end
  91. end
  92.  
  93. function tasermod.processDamage(id, attackerID)
  94.     local randomDamage = math.random(tasermod.minDamage, tasermod.maxDamage)
  95.     local damage = tasermod.math_round(randomDamage * tasermod.getArmorDamageMultiplier(id))
  96.     local victimHealth = player(id, "health")
  97.    
  98.     if victimHealth <= damage then  -- is the damage unacceptably high?
  99.    
  100.         if tasermod.victimCanDie then
  101.             parse("customkill ".. attackerID .." ".. tasermod.customkillMessage .. " ".. id)
  102.            
  103.             return false
  104.            
  105.         else
  106.             parse("sethealth ".. id .." ".. 1)  -- leave 1 hp
  107.            
  108.             return true
  109.         end
  110.        
  111.     else
  112.         parse("sethealth ".. id .." ".. victimHealth - damage)
  113.         return true
  114.     end
  115. end
  116.  
  117. function tasermod.math_round(a)
  118.      return math.floor(a+0.5)
  119. end
  120.  
  121. function tasermod.setStun(id)
  122.     if tasermod.player[id] == nil then
  123.    
  124.         tasermod.player[ id ] = {
  125.             isStunned = true,
  126.             originalSpeedmod = player(id, "speedmod"),
  127.             currentSpeedmod = tasermod.stunSpeedmod,
  128.             slownessTimeLeft = tasermod.slownessDuration,
  129.             stepSize = math.abs((player(id, "speedmod") - tasermod.stunSpeedmod) / (tasermod.slownessDuration / tasermod.stepDuration))
  130.         }
  131.    
  132.     elseif tasermod.player[id] and tasermod.player[id].isStunned then   -- @> protection against multiple shots
  133.    
  134.         freetimer("tasermod.onStunEnd", tostring(id))   -- remove timer for the previous shot, we'll start at time point 0 below
  135.         freetimer("tasermod.slownessDecay", tostring(id))
  136.        
  137.         tasermod.player[ id ].  currentSpeedmod = tasermod.stunSpeedmod
  138.         tasermod.player[ id ].  slownessTimeLeft = tasermod.slownessDuration
  139.         tasermod.player[ id ].  stepSize = math.abs((tasermod.player[ id ].originalSpeedmod - tasermod.stunSpeedmod) / (tasermod.slownessDuration / tasermod.stepDuration))
  140.     end
  141.    
  142.     parse("speedmod ".. id .." ".. tasermod.stunSpeedmod)
  143.     timer(tasermod.stunDuration, "tasermod.onStunEnd", tostring(id))
  144. end
  145.  
  146. function tasermod.onStunEnd(id)
  147.     tasermod.slownessDecay(id)
  148. end
  149.  
  150. -- Removes the stun effect
  151. function tasermod.slownessDecay(id)
  152.     local id = tonumber(id)
  153.    
  154.     if not player(id, "exists") then return nil end -- player isn't on the server
  155.    
  156.     tasermod.player[id].currentSpeedmod = (tasermod.player[id].currentSpeedmod + tasermod.player[id].stepSize)
  157.    
  158.     if tasermod.player[id].currentSpeedmod >= tasermod.player[id].originalSpeedmod then -- is the slowness over?
  159.    
  160.         parse("speedmod ".. id .." ".. tasermod.player[id].originalSpeedmod)
  161.         msg2(id, "©040150210[TASERMOD] You have now fully recovered from the taser shot")
  162.        
  163.         tasermod.player[id] = nil
  164.        
  165.     else
  166.         parse("speedmod ".. id .." ".. tasermod.math_round(tasermod.player[id].currentSpeedmod))
  167.        
  168.         timer(tasermod.stepDuration, "tasermod.slownessDecay", tostring(id))
  169.     end
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement