Skip to content

Instantly share code, notes, and snippets.

View EncodeTheCode's full-sized avatar
💭
Coding useful tools for workflow.

EncodeTheCode

💭
Coding useful tools for workflow.
View GitHub Profile
-- Initialize the table to store key states for each player
local playerKeys = {}
-- Add a helper function to check if multiple keys are pressed
local function isKeysPressed(playerId, keys)
for _, key in ipairs(keys) do
if not playerKeys[playerId][key] then
return false
end
end
function onPlayerKeyPress(id,key,state)
if(state==1)then
if(key=="A" and key=="W")then
msg("W and A has been pressed.")
c_msg(id,102,255,102,'W and A has been pressed!','@C')
elseif(key=="D"and key=="W")then
msg("W and D has been pressed.")
c_msg(id,102,255,102,'W and D has been pressed!','@C')
elseif(key=="D"and key=="S")then
msg("S and D has been pressed.")
function c_msg(p,r,g,b,m,c)
r,g,b,c=r or '0',g or '0',b or '0',c or ''
local k = string.format("%s%s%s%s", string.char(169), r, g, b)
-- k=string.sub(k,1,-1)
-- k=string.gsub(k,"%s+","")
msg2(p, k .. m .. c);
end
-- Initialize the table to store key states for each player
local playerKeys = {}
function c_msg(p,r,g,b,m,c)
r,g,b,c=r or '0',g or '0',b or '0',c or ''
local k = string.format("%s%s%s%s", string.char(169), r, g, b)
-- k=string.sub(k,1,-1)
-- k=string.gsub(k,"%s+","")
msg2(p, k .. m .. c);
end
-- Initialize the table to store key states for each player
local playerKeys = {}
function c_msg(p,r,g,b,m,c)
r,g,b,c=r or '0',g or '0',b or '0',c or ''
local k = string.format("%s%s%s%s", string.char(169), r, g, b)
-- k=string.sub(k,1,-1)
-- k=string.gsub(k,"%s+","")
msg2(p, k .. m .. c);
end
-- Initialize the table to store key states for each player
local playerKeys = {}
-- initialize empty table to store key presses for each player
local playerKeys = {}
function onPlayerKeyPress(id, key, state)
-- initialize table entry for this player if it doesn't exist yet
if not playerKeys[id] then
playerKeys[id] = {}
end
-- update key state in table for this player
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
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
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
-- Update the key state for the player
playerKeys[playerName][key] = (state == 1)
-- Check if both W and A are pressed
-- Check if both W and D are pressed
-- Check if both S and D are pressed
-- Check if both S and A are pressed
local function clear_keys(playerName)
playerKeys[playerName][key] = nil