Skip to content

Instantly share code, notes, and snippets.

@VADemon
Created February 24, 2013 17:35
Show Gist options
  • Save VADemon/5024728 to your computer and use it in GitHub Desktop.
Save VADemon/5024728 to your computer and use it in GitHub Desktop.
AntiTeamFlash script for CS2D 0.1.2.2+
--Licensed under WTFPLv2; script made by VADemon v1.0
addhook("attack", "flash.attack")
flash = {}
function flash.attack(id) --on throwing
if player(id, "weapontype")==52 or player(id, "weapontype")==0 then
flash.check_for_flash(id)
end
end
function flash.team_flash(fuck_timer)
local projID, playerID = string.match(fuck_timer, "(%d+)\n(%d+)")
local projID, playerID = tonumber(projID), tonumber(playerID)
local playerTeam, enemyTeam = player(playerID, "team")
local playerX, playerY = player(playerID, "x"), player(playerID, "y")
local distance = flash.distance
local color
if playerTeam==1 then
enemyTeam = 2
color = "©255025000"
elseif playerTeam==2 then
enemyTeam = 1
color = "©050150255"
else
return nil --in rare cases if player disconnects/joins the spec
end
for k,v in pairs(player(0,"team"..enemyTeam.."living")) do
if distance(playerX, playerY, v)<=900 then --if withing 900px then leave the flashbang
--msg("1st")
--msg(distance(playerX, playerY, v))
return false
end
end
for k,v in pairs(player(0,"team"..playerTeam.."living")) do
if distance(playerX, playerY, v)>=740 then --if outside the range then let it blind that idiot
--msg("2nd")
--msg(distance(playerX, playerY, v))
return false
end
end
for k,v in pairs(player(0, "team"..playerTeam)) do
msg2(v, color .. player(playerID, "name") .. "©255220000 threw a flashbang nearby to teammates! What an idiot.")
end
parse("freeprojectile "..fuck_timer)
end
function flash.check_for_flash(PLAYERID)
local list = projectilelist(0,tonumber(PLAYERID)) --flying projectiles
for k,p in pairs(list) do
if projectile(p.id, PLAYERID, "type")==52 then
timer(1700, "flash.team_flash", p.id.."\n"..PLAYERID)
--msg("New flashbang detected")
end
end
end
function flash.distance(x1,y1,i)
return math.sqrt(math.pow(math.abs(player(i,"x")-x1),2)+math.pow(math.abs(player(i,"y")-y1),2)) -- %)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment