Last active
September 28, 2015 19:48
-
-
Save Ablu/1488173 to your computer and use it in GitHub Desktop.
Helpscript to debug manaserv map scripts without need of a server
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
-- Use: | |
-- lua debugger.lua <mapfile to debug> | |
-- e = exit | |
-- t = talk to npc | |
-- tr = trigger a trigger | |
-- cp = create player | |
-- in = info about npc | |
-- it = info about trigger | |
-- ip = info about player | |
error("This script is outdated") | |
require "scripts/lua/libmana-constants" | |
npcs = {} | |
trigger = {} | |
player = {} | |
mana = {} | |
function create_npc(name, spriteid, posx, posy, talk_func, update_func) | |
local i = #npcs + 1 | |
npcs[i] = {} | |
npcs[i].name = name | |
npcs[i].sprite = spriteid | |
npcs[i].x = posx | |
npcs[i].y = posy | |
npcs[i].talkf = talk_func | |
npcs[i].updatef = update_func | |
print("NPC created: " .. name .. " (" .. posx .. ":" .. posy .. ") " .. | |
"internal ID: " .. i) | |
return i | |
end | |
mana.trigger_create = function(x, y, w, h, f, arg, once) | |
local i = #trigger + 1 | |
trigger[i] = {} | |
trigger[i].x = x | |
trigger[i].y = y | |
trigger[i].w = w | |
trigger[i].h = h | |
trigger[i].arg = arg | |
trigger[i].f = function(b) loadstring(f) end | |
trigger[i].once = once | |
print("Trigger created: (" .. x .. "," .. y .. ":" .. w .. "," .. h .. ") " | |
.. "arg: " .. arg .. " func: " .. f .. " Internal ID: " .. i) | |
end | |
mana.item_drop = function(x, y, id, amount) | |
print("Dropped " .. amount .. " items of id " .. id .. | |
" at " .. x .. ":" .. y) | |
end | |
mana.posX = function(handle) | |
if npcs[handle] then | |
return npcs[handle].x | |
else | |
print("Requesting x position of handle " .. handle .. ":") | |
print("Value to return?") | |
return tonumber(io.read()) | |
end | |
end | |
mana.posY = function(handle) | |
if npcs[handle] then | |
return npcs[handle].y | |
else | |
print("Requesting y position of handle " .. handle .. ":") | |
print("Value to return?") | |
return tonumber(io.read()) | |
end | |
end | |
function do_message(npc, ch, text) | |
print("NPC " .. npc .. " said to " .. ch .. ": " .. text) | |
end | |
function do_npc_close(npc, ch) | |
print("Conversation between " .. npc .. " and " .. ch .. " closed") | |
end | |
function schedule_every(secs, f) | |
print("schedule_every registered: interval: " .. secs) | |
end | |
function atinit(f) | |
f() | |
end | |
print("Debugging map script \"" .. arg[1] .. "\".") | |
dofile(arg[1]) | |
function create_player() | |
local i = #player + 1 | |
print("Creating player with id " .. i + 1000) | |
print("Name of player:") | |
local name = io.read() | |
player[i] = {} | |
player[i].name = name | |
end | |
function talk() | |
print("NPC to talk with (internal ID):") | |
local id = io.read("*number") | |
if not npcs[id] then | |
print("NPC " .. id .. " does not exist.") | |
else | |
print("Talking to NPC " .. id .. " (" .. npcs[id].name .. "):") | |
npcs[id].talkf(id, 9999) | |
end | |
end | |
function trigger_trigger() | |
print("Trigger to trigger (internal ID):") | |
local id = io.read("*number") | |
if not trigger[id] then | |
print("Trigger with id " .. id .. " does not exist") | |
else | |
print("Being that triggered trigger (internal ID):") | |
local b_id = io.read("*number") | |
trigger[id].f(b_id) | |
end | |
end | |
function npc_info() | |
print("NPC id (internal ID):") | |
local id = io.read("*number") | |
if not npcs[id] then | |
print("NPC " .. id .. " does not exist!") | |
else | |
print("Info about NPC " .. id .. ":") | |
for i,v in pairs(npcs[id]) do | |
print(i .. ": " .. v or "") | |
end | |
end | |
end | |
function player_info() | |
print("Player id (internal ID):") | |
local id = io.read("*number") - 1000 | |
if not player[id] then | |
print("Player " .. id + 1000 .. " does not exist!") | |
else | |
print("Info about Player " .. id + 1000 .. ":") | |
for i,v in pairs(player[id]) do | |
print(i .. ": " .. v or "") | |
end | |
end | |
end | |
function trigger_info() | |
print("Trigger id (internal ID):") | |
local id = io.read("*number") | |
if not trigger[id] then | |
print("Trigger " .. id .. " does not exist!") | |
else | |
print("Info about Trigger " .. id .. ":") | |
for i,v in pairs(trigger[id]) do | |
print(i .. ": " .. v or "") | |
end | |
end | |
end | |
local a = io.read() | |
while a ~= "e" do | |
if a == "t" then | |
talk() | |
elseif a == "tr" then | |
trigger_trigger() | |
elseif a == "cp" then | |
create_player() | |
elseif a == "in" then | |
npc_info() | |
elseif a == "it" then | |
trigger_info() | |
elseif a == "ip" then | |
player_info() | |
end | |
a = io.read() | |
end | |
print("exit") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment