Skip to content

Instantly share code, notes, and snippets.

@Saren-Arterius
Created April 13, 2014 13:20
Show Gist options
  • Save Saren-Arterius/10583912 to your computer and use it in GitHub Desktop.
Save Saren-Arterius/10583912 to your computer and use it in GitHub Desktop.
TFM items shooting
function eventKeyboard(playerName, keyCode, down, xPlayerPosition, yPlayerPosition)
if keyCode == 32 then
playerShoot(playerName, false, xPlayerPosition, yPlayerPosition, tfm.get.room.playerList[playerName]["isFacingRight"])
elseif keyCode == 17 then
playerShoot(playerName, true, xPlayerPosition, yPlayerPosition, tfm.get.room.playerList[playerName]["isFacingRight"])
end
end
function playerShoot(playerName, fast, xPlayerPosition, yPlayerPosition, isFacingRight)
if fast then
if isFacingRight then
tfm.exec.addShamanObject(settings[playerName]["it"][math.random(#settings[playerName]["it"])], xPlayerPosition + settings[playerName]["xp"], yPlayerPosition + settings[playerName]["yp"], settings[playerName]["an"], settings[playerName]["xv"]*settings[playerName]["hs"], settings[playerName]["yv"]*settings[playerName]["hs"], false)
else
tfm.exec.addShamanObject(settings[playerName]["it"][math.random(#settings[playerName]["it"])], xPlayerPosition - settings[playerName]["xp"], yPlayerPosition + settings[playerName]["yp"], settings[playerName]["an"], -settings[playerName]["xv"]*settings[playerName]["hs"], settings[playerName]["yv"]*settings[playerName]["hs"], false)
end
else
if isFacingRight then
tfm.exec.addShamanObject(settings[playerName]["it"][math.random(#settings[playerName]["it"])], xPlayerPosition + settings[playerName]["xp"], yPlayerPosition + settings[playerName]["yp"], settings[playerName]["an"], settings[playerName]["xv"], settings[playerName]["yv"], false)
else
tfm.exec.addShamanObject(settings[playerName]["it"][math.random(#settings[playerName]["it"])], xPlayerPosition - settings[playerName]["xp"], yPlayerPosition + settings[playerName]["yp"], settings[playerName]["an"], -settings[playerName]["xv"], settings[playerName]["yv"], false)
end
end
end
function eventChatCommand(playerName, message)
commands = {}
for word in string.gmatch(message, "%S+") do
commands[#commands + 1] = word
end
if (settings[playerName][string.lower(commands[1])] ~= nil) and (tonumber(commands[2]) ~= nil) and string.lower(commands[1]) ~= "it" then
print(playerName.." - Value "..string.lower(commands[1]).." has been changed from "..settings[playerName][string.lower(commands[1])].." to "..tonumber(commands[2]))
settings[playerName][string.lower(commands[1])] = tonumber(commands[2])
elseif string.lower(commands[1]) == "it" then
if commands[2] == nil then
items = ""
for key, val in pairs(settings[playerName]["it"]) do
items = items..val..", "
end
print(playerName.." - Items selection: "..items)
elseif string.lower(commands[2]) == "r" then
settings[playerName]["it"] = {"23", "7", "28", "2", "32", "34", "4", "1", "19", "6", "10", "54", "3​", "35", "39", "40", "45", "46", "57", "59", "60", "61", "62"}
print(playerName.." - Items selection has been reset to default.")
else
settings[playerName]["it"] = {}
items = ""
for key, word in pairs(commands) do
if tonumber(word) ~= nil then
items = items..word..", "
settings[playerName]["it"][#settings[playerName]["it"] + 1] = tonumber(word)
end
end
print(playerName.." - New items selection: "..items)
end
elseif settings[playerName][string.lower(commands[1])] ~= nil then
print(playerName.." - Current "..string.lower(commands[1]).." value: "..settings[playerName][string.lower(commands[1])])
end
end
settings = {}
for playerName, obj in pairs(tfm.get.room.playerList) do
tfm.exec.bindKeyboard(playerName, 32, true, true)
tfm.exec.bindKeyboard(playerName, 32, false, true)
tfm.exec.bindKeyboard(playerName, 17, true, true)
tfm.exec.bindKeyboard(playerName, 17, false, true)
settings[playerName] = {}
settings[playerName]["an"] = 0
settings[playerName]["xv"] = 10
settings[playerName]["yv"] = -5
settings[playerName]["xp"] = 50
settings[playerName]["yp"] = 0
settings[playerName]["hs"] = 3
settings[playerName]["it"] = {"23", "7", "28", "2", "32", "34", "4", "1", "19", "6", "10", "54", "3​", "35", "39", "40", "45", "46", "57", "59", "60", "61", "62"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment