Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Last active May 5, 2023 09:59
Show Gist options
  • Save EncodeTheCode/037abf6645b8da3cf4d09ee43614d214 to your computer and use it in GitHub Desktop.
Save EncodeTheCode/037abf6645b8da3cf4d09ee43614d214 to your computer and use it in GitHub Desktop.
local clock=os.clock
function sleep(n)
local t=clock()
while clock()-t<=n do end
end
function sleep_for(t)
local t = t or 0
sleep(t) -- Sleep server connection for 1 entire second.
end
has_spawned=false
function gfx(i)
local g,d,e="gfx/sprites/","custom/",".png"
return tostring(g..d..i..e)
end
gfx={
gfx('circle'),
gfx('light_circle'),
gfx('yellow_circle'),
gfx('red_circle'),
gfx('blue_circle'),
gfx('blue2_circle'),
gfx('pinky_circle'),
gfx('pinky2_circle'),
gfx('light_pink_circle'),
gfx('dark_pink_circle'),
gfx('dark_pink2_circle'),
gfx('purple_circle'),
gfx('olive_circle'),
gfx('mixed_circle'),
gfx('sniped')
}
sprite_array={}
for i=1,32 do sprite_array[i]=0 end -- This indexes 0 value to every 32 entries in this array.
function create_sprite(id,x,y)
local sprite_id=image(gfx[3],x,y,3) -- Create yellow circle.
local id=sprite_array[sprite_id]
end
function create_sprite_t(id,x,y)
local sprite_id=image(gfx[4],x,y,3) -- Create red circle.
local id=sprite_array[sprite_id]
end
function create_sprite_ct(id,x,y)
local sprite_id=image(gfx[5],x,y,3) -- Create blue circle.
local id=sprite_array[sprite_id]
end
function change_alpha(p,a)
local a=a or 0.0
if player(p,"exists") then imagealpha(p,a) end
end -- lua o=change_alpha(1,0.5)
function change_color(p,r,g,b)
local r,g,b=r or 0,b or 0,g or 0
if player(p,"exists") then imagecolor(p,r,g,b) end
end
function change_blend(p,b)
local b=b or 1
if player(p,"exists") then imageblend(p,b) end
end
function change_scale(p,x,y)
local x,y=x or 3,y or 3
if player(p,"exists") then imagescale(p,x,y) end
end
function change_pos(p,x,y,z)
local x,y,z=x or 3,y or 3,z or 3
if player(p,"exists") then imagepos(p,x,y,z) end
end
function change_image_property(a,b,c,d,p)
local a,b,c,d,p=a or "",b or 0,c or 0,d or 0,p or 0
if a=="alpha" then
p=c
change_alpha(p,b)
elseif a=="color" then
change_color(p,b,c,d)
elseif a=="blend" then
change_blend(p,b)
elseif a=="scale" then
change_scale(p,b,c)
elseif a=="pos" then
change_pos(p,b,c,d)
end
end
function animate_image_color(r,g,b,t,p)
local t,r,g,b=t or 3000,r or 0,b or 0,g or 0
tween_color(p,t,r,g,b)
end
-- Animate a image to fade to a specific color for a specific player
-- lua o=animate_image_color(102,255,102,3000,1)
-- Change alpha of image of specific player
-- lua o=change_image_property("alpha",1.0,1)
-- lua o=change_image_property("alpha",0.0,1)
-- Change color of image of specific player
-- lua o=change_image_property("color",0,0,0,1)
-- lua o=change_image_property("color",102,255,102,1)
-- lua o=change_image_property("color",255,255,255,1)
function add_bots()
parse("bot_add_t")
parse("bot_add_t")
parse("bot_add_ct")
parse("bot_add_ct")
end
function bot_unfreeze()
parse("bot_freeze 0")
end
function sv_commands()
parse("mp_autoteambalance 0") -- Disable team balance
parse("sv_maxplayers 32") -- Set max players to 32
add_bots()
end
function log_player_data()
local a1 = "Knight丶å°å± is using IP 113.101.228.7:38111, no U.S.G.N. ID and Steam ID #76561198359241322 (Knight丶小展)"
local a2 = "len4ikastafeva1989 is using IP 95.189.77.124:6150, no U.S.G.N. ID and Steam ID #76561199499679914 (len4ikastafeva1989)"
local a3 = "Hope dream is using IP 112.9.18.131:6383, U.S.G.N. ID #199114 and no Steam" -- China Russki? in school
local a4 = "Patron_m16 is using IP 94.245.132.67:5228, no U.S.G.N. ID and Steam ID #76561198808509696 (Patron_m16)"
end
function c_msg(p,r,g,b,m,c)
r=r or '000'
g=g or '000'
b=b or '000'
c=c or '' -- @C (Centered Message)
msg2(p,tostring(string.char(0169)..r..g..b)..m..c)
-- msg2(p,tostring('©'..r..g..b)..m..c)
end
function kill_player(p)
set_player_health(2,0)
end
function show_all_objects()
local o = object(0,"table")
print(o) -- a Lua table with all dynamic object IDs
for i in pairs(o) do
print(tostring(o[i]))
end
end -- lua o=show_all_objects()
function determine_steamid(p)
if player(p,"exists") then
if player(p,"steamid")==0 then
msg(player(p,"name").." has joined the game!")
else
msg(player(p,"name").." [Steam ID: #"..player(p,"steamid").."] has joined the game!")
end
end
end
function set_player_health(p,h)
if player(p,"exists") then
parse("sethealth "..p.." "..h) -- Sets player health to the h value.
parse('msg '..player(p,'name')..' ['..p..'#] received '..h..' health.')
c_msg(p,102,255,102,' '..player(p,'name')..' ['..p..'#] received '..h..' health!','@C')
else
print('Setting health of player failed.')
-- lua o={print('Hello')}
-- lua o={c_msg(1,102,255,102,'Hey you there!','@C'}
c_msg(1,102,255,102,'No player with that ID exists!','@C')
end
end
function onPlayerJoin(p)
determine_steamid(p)
end
function onPlayerSpawn(p)
if has_spawned==false then
has_spawned=true
sv_commands()
end
if player(p,"exists") then
msg("The player: '"..player(p, "name").."' has spawned!")
if player(p,"team")==1 then
create_sprite_t(p,player(p,"x"),player(p,"y"))
imagecolor(sprite_array[p],255,255,0)
imageblend(sprite_array[p],1)
imagealpha(sprite_array[p],0.5)
imagescale(sprite_array[p],2,3)
imagepos(sprite_array[p],30,30,45)
elseif player(p,"team")==2 then
create_sprite_ct(p,player(p,"x"),player(p,"y"))
imagecolor(sprite_array[p],255,255,0)
imageblend(sprite_array[p],1)
imagealpha(sprite_array[p],0.5)
imagescale(sprite_array[p],2,3)
imagepos(sprite_array[p],30,30,45)
else
create_sprite(p,player(p,"x"),player(p,"y"))
imagecolor(sprite_array[p],255,255,0)
imageblend(sprite_array[p],1)
imagealpha(sprite_array[p],0.5)
imagescale(sprite_array[p],2,3)
imagepos(sprite_array[p],30,30,45)
end
end
end
function onPlayerDie(p)
if player(p,"exists") then
freeimage(p)
return 0
end
-- lua o={freeimage(1)}
-- lua o={freeimage(id)}
end
function onPlayerHit(p)
if(player(p,"exists")==1)then
-- player(id,source,weapon,hpdmg,apdmg,rawdmg,object)
player(p,0,"hpdmg"-40)
player(p,0,"apdmg"-25)
player(p,0,"rawdmg"-5)
end
end
function onPlayerMove(id,x,y)
if not player(id, "exists") or player(id, "health") <= 0 then return end -- Check if the player exists and is alive
local players = player(0,"table")
for i = 1, #players do
if i ~= id and type(player(i,"team")) == "number" and type(player(i,"health")) == "number" and player(i,"team") ~= player(id,"team") and player(i,"health") > 0 then -- Check if the player is not the same as the one who triggered the hook
local dist = math.sqrt((player(id,"x") - player(i,"x"))^2 + (player(id,"y") - player(i,"y"))^2)
if dist < 96 then
parse("killplayer "..i)
end
end
end
end
addhook("spawn", "onPlayerSpawn")
addhook("move", "onPlayerMove")
addhook("die", "onPlayerDie")
addhook("hit", "onPlayerHit")
addhook("join","onPlayerJoin")
-- Modification idea
-- Main idea Star Wars 2D
-- Force Push ability that kills players nearby in a 96 pixel radius from the player. When the ability is used (keybind) or used as text.
-- Other cool usages of the radius kill function, needs more ideas.
function force_push(p,v)
local p -- Player
local v -- Victim
if player(p) then
end
if player(v) then
end
end
-- If force_push is given to a player, the player is able to perform the ability. But then it goes away until it recharges to 100%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment