Skip to content

Instantly share code, notes, and snippets.

@tmartty
Created December 20, 2017 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmartty/2d5c173cf390645135ecb2dfefa19d4a to your computer and use it in GitHub Desktop.
Save tmartty/2d5c173cf390645135ecb2dfefa19d4a to your computer and use it in GitHub Desktop.
CS2D Lua Scan Training Script
--------------------------------------------------
-- Based on Laserpointer Script by Plookerbooy --
-- & --
-- Hitzone Script by Unreal Software --
-- --
-- Modified by United --
--------------------------------------------------
function init(a,b)
local array = {}
for i = 1, a do
array[i] = b
end
return array
end
lpline=init(32, "")
lppostion=init(32, {})
lpstate=init(32, false)
addhook("die","_reset")
addhook("leave","_reset")
addhook("use","_attack")
addhook("always","_always")
addhook("clientdata","_clientdata")
-- addhook("flashlight","_reset")
if sample==nil then sample={} end
sample.hitzone={}
sample.hitzone.id=0
-----------------------
-- STARTROUND --
-----------------------
addhook("startround","sample.hitzone.startround")
function sample.hitzone.startround()
sample.hitzone.id=0
end
-----------------------
-- HITZONE --
-----------------------
addhook("hitzone","sample.hitzone.hit")
hits = 0
function sample.hitzone.hit(id)
-- Show Message
if hits == 0 then
msg("+++ Hit!")
hits = hits + 1
return
end
if hits == 1 then
msg("--- Hit!")
hits = hits -1
return
end
end
function _attack(id)
reqcld(id, 2)
end
function _clientdata(id, t, x, y, team)
-- get data and assign to variables
local xf, yf, teamf = x, y, team
if (player(id, "team") == 1) then
parse('effect "flare" '..xf..' '..yf..' 32 16 0 0 255')
end
if (player(id, "team") == 2) then
parse('effect "flare" '..xf..' '..yf..' 32 16 255 0 0')
end
lppostion[id] = {xf, yf}
lpstate[id]=id
-- remove previous dummy hitzone
freeimage(sample.hitzone.id)
-- create dummy hitzone
for _, id in pairs(player(0, "tableliving")) do
if lpstate[id] then
local x, y = lppostion[id][1], lppostion[id][2]
sample.hitzone.id=image("gfx/player/randomplayer.bmp",x,y,1)
imagehitzone(sample.hitzone.id,3,-28/2,-28/2,28,28)
if (player(id, "team") == 1) then
imagecolor(sample.hitzone.id,0,0,255)
end
if (player(id, "team") == 2) then
imagecolor(sample.hitzone.id,255,0,0)
end
rot = player(id, "rot") - 180
imagepos(sample.hitzone.id,x,y,rot)
end
end
end
function _reset(id)
if lpstate[id] then
lpstate[id]=false
freeimage(lpline[id])
freeimage(sample.hitzone.id)
end
end
function _always()
for _, id in pairs(player(0, "tableliving")) do
if lpstate[id] then
local x, y, ix, iy = player(id,"x"), player(id,"y"), lppostion[id][1], lppostion[id][2]
local lpdist = math.sqrt((x-ix)^2 + (y-iy)^2)
if lpline[id]~="" then
freeimage(lpline[id])
end
lpline[id] = image("gfx/line.bmp", x, y, 1)
local hp=100
local angle= -math.deg(math.atan2(ix-x,iy-y))
local linex,liney= x-math.sin(math.rad(angle))*lpdist/2, y+math.cos(math.rad(angle))*lpdist/2
imagepos(lpline[id], linex, liney, angle)
imagescale(lpline[id],1,lpdist)
if freeline(x, y, ix, iy) then
imagecolor(lpline[id], 0, 255, 0)
else
imagecolor(lpline[id], 255, 0, 0)
end
end
end
end
function freeline(x1, y1, x2, y2)
for i=1, math.floor(math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2))) do
if tile(math.floor((x1 + i * math.cos(math.atan2(y2 - y1, x2 - x1))) / 32),math.floor((y1 + i * math.sin(math.atan2(y2 - y1, x2 - x1))) / 32), "wall") == true then
return false
end
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment