This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |