diff options
-rw-r--r-- | example/scripts/crafting.lua | 18 | ||||
-rw-r--r-- | example/scripts/global_events.lua | 24 | ||||
-rw-r--r-- | example/scripts/items/candy.lua | 4 | ||||
-rw-r--r-- | example/scripts/maps/desert.lua | 80 | ||||
-rw-r--r-- | example/scripts/monster/testmonster.lua | 12 | ||||
-rw-r--r-- | example/scripts/npcs/banker.lua | 60 | ||||
-rw-r--r-- | example/scripts/npcs/barber.lua | 20 | ||||
-rw-r--r-- | example/scripts/npcs/debugger.lua | 68 | ||||
-rw-r--r-- | example/scripts/npcs/emotemaker.lua | 6 | ||||
-rw-r--r-- | example/scripts/npcs/healer.lua | 8 | ||||
-rw-r--r-- | example/scripts/npcs/merchant.lua | 20 | ||||
-rw-r--r-- | example/scripts/npcs/postman.lua | 18 | ||||
-rw-r--r-- | example/scripts/npcs/shaker.lua | 14 | ||||
-rw-r--r-- | example/scripts/special_actions.lua | 10 | ||||
-rw-r--r-- | example/scripts/status/jump.lua | 18 | ||||
-rw-r--r-- | example/scripts/status/plague.lua | 12 | ||||
-rw-r--r-- | scripts/lua/libmana.lua | 34 | ||||
-rw-r--r-- | scripts/lua/npclib.lua | 18 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 5 |
19 files changed, 225 insertions, 224 deletions
diff --git a/example/scripts/crafting.lua b/example/scripts/crafting.lua index db8c76dd..afe1e1b5 100644 --- a/example/scripts/crafting.lua +++ b/example/scripts/crafting.lua @@ -9,14 +9,14 @@ local function craft_strict(ch, recipe) if (recipe[1].id == 8 and recipe[1].amount == 2 and -- has two iron
recipe[2].id == 9 and recipe[2].amount == 1) -- and one wood
then
- mana.chr_inv_change(ch,
+ chr_inv_change(ch,
8, -2, --take away the iron
9, -1, --take away the wood
5, 1 ) -- give a sword
- mana.chat_message(ch, "You've crafted a sword")
+ chat_message(ch, "You've crafted a sword")
return
end
- mana.chat_message(ch, "This wouldn't create anything useful")
+ chat_message(ch, "This wouldn't create anything useful")
end
-- this turns multiple occurences of the same item into one by adding up
@@ -56,19 +56,19 @@ local function craft_lax(ch, recipe) if (recipe[1].id == 8 and recipe[1].amount >= 2 and -- has at least two iron
recipe[2].id == 9 and recipe[2].amount >= 1) -- and at least one wood
then
- mana.chr_inv_change(ch,
+ chr_inv_change(ch,
8, -2, -- take away the iron
9, -1, -- take away the wood
5, 1 ) -- give a sword
- mana.chat_message(ch, "You've crafted a sword")
+ chat_message(ch, "You've crafted a sword")
return
end
- mana.chat_message(ch, "This wouldn't create anything useful")
+ chat_message(ch, "This wouldn't create anything useful")
end
-- This function is registered with the game engine to use when a character
-- tries to craft something from items in its inventory.
-local function on_craft(ch, recipe)
+local function craft(ch, recipe)
-- ch is the crafting character
--
-- recipe is a table with the ingredients.
@@ -80,9 +80,9 @@ local function on_craft(ch, recipe) -- uncomment one (but not both!) of the following three lines to enable the
-- example crafting systems
- mana.chat_message(ch, "There is no crafting in this game world.")
+ chat_message(ch, "There is no crafting in this game world.")
--craft_strict(ch, recipe)
--craft_lax(ch, recipe)
end
-mana.on_craft(on_craft)
+on_craft(craft)
diff --git a/example/scripts/global_events.lua b/example/scripts/global_events.lua index 42a25f00..1268ef91 100644 --- a/example/scripts/global_events.lua +++ b/example/scripts/global_events.lua @@ -12,21 +12,21 @@ -- Register the callback that is called when the hit points of a character -- reach zero. -mana.on_character_death(function(ch) - mana.being_say(ch, "Noooooo!!!") +on_character_death(function(ch) + being_say(ch, "Noooooo!!!") end) -- This function is called when the player clicks on the OK button after the -- death message appeared. It should be used to implement the respawn -- mechanic (for example: warp the character to the respawn location and -- bring HP above zero in some way) -mana.on_character_death_accept(function(ch) +on_character_death_accept(function(ch) -- restores to full hp - mana.being_heal(ch) + being_heal(ch) -- restores 1 hp (in case you want to be less nice) - -- mana.being_heal(ch, 1) + -- being_heal(ch, 1) -- warp the character to the respawn location - mana.chr_warp(ch, 1, 815, 100) + chr_warp(ch, 1, 815, 100) end) @@ -51,14 +51,14 @@ end -- to the character and/or initialize a tutorial quest. local function on_chr_birth(ch) -- this message is shown on first login. - mana.chat_message(0, ch, "And so your adventure begins...") + chat_message(0, ch, "And so your adventure begins...") end -- This function is called when a character logs into the game. This can, -- for example, be utilized for a message-of-the-day or for various -- handlings of offline processing mechanics. local function on_chr_login(ch) - mana.chat_message(0, ch, "Welcome to Manasource") + chat_message(0, ch, "Welcome to Manasource") end @@ -66,11 +66,11 @@ end -- be useful for various handling of offline processing mechanics. local function on_chr_logout(ch) -- notifies nearby players of logout - local around = mana.get_beings_in_circle(posX(ch), posY(ch), 1000) - local msg = mana.being_get_name(ch).." left the game." + local around = get_beings_in_circle(posX(ch), posY(ch), 1000) + local msg = being_get_name(ch).." left the game." for b in pairs(around) do - if mana.being_type(b) == TYPE_CHARACTER then - mana.chat_message(0, b, msg) + if being_type(b) == TYPE_CHARACTER then + chat_message(0, b, msg) end end end diff --git a/example/scripts/items/candy.lua b/example/scripts/items/candy.lua index f60e687d..617e1d5f 100644 --- a/example/scripts/items/candy.lua +++ b/example/scripts/items/candy.lua @@ -8,8 +8,8 @@ --]] -local candy = mana.get_item_class("candy") +local candy = get_item_class("candy") candy:on("use", function(user) - mana.being_say(user, "*munch*munch*munch*") + being_say(user, "*munch*munch*munch*") end) diff --git a/example/scripts/maps/desert.lua b/example/scripts/maps/desert.lua index 5f61bd53..96518ac9 100644 --- a/example/scripts/maps/desert.lua +++ b/example/scripts/maps/desert.lua @@ -14,32 +14,32 @@ require "scripts/npcs/shaker" atinit(function() -- Barber examples - mana.npc_create("Barber Twin", 1, GENDER_MALE, 14 * TILESIZE + TILESIZE / 2, 9 * TILESIZE + TILESIZE / 2, Barber) - mana.npc_create("Barber Twin", 1, GENDER_MALE, 20 * TILESIZE + TILESIZE / 2, 11 * TILESIZE + TILESIZE / 2, npclib.talk(Barber, {14, 15, 16}, {})) + npc_create("Barber Twin", 1, GENDER_MALE, 14 * TILESIZE + TILESIZE / 2, 9 * TILESIZE + TILESIZE / 2, Barber) + npc_create("Barber Twin", 1, GENDER_MALE, 20 * TILESIZE + TILESIZE / 2, 11 * TILESIZE + TILESIZE / 2, npclib.talk(Barber, {14, 15, 16}, {})) -- A simple banker - mana.npc_create("Banker", 8, GENDER_MALE, 35 * TILESIZE + TILESIZE / 2, 24 * TILESIZE + TILESIZE / 2, Banker) + npc_create("Banker", 8, GENDER_MALE, 35 * TILESIZE + TILESIZE / 2, 24 * TILESIZE + TILESIZE / 2, Banker) -- A simple merchant. merchant_buy_table = { {"Candy", 10, 20}, {"Regenerative trinket", 10, 30}, {"Minor health potion", 10, 50}, {11, 10, 60}, {12, 10, 40} } merchant_sell_table = { {"Candy", 10, 19}, {"Sword", 10, 30}, {"Bow", 10, 200}, {"Leather shirt", 10, 300} } - mana.npc_create("Merchant", 3, GENDER_MALE, 4 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, merchant_buy_table, merchant_sell_table)) + npc_create("Merchant", 3, GENDER_MALE, 4 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, merchant_buy_table, merchant_sell_table)) -- Another Merchant, selling some equipment, and buying everything... smith_buy_table = { {"Sword", 10, 50}, {7, 10, 70}, {10, 10, 20} } - mana.npc_create("Smith", 5, GENDER_MALE, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Smith, smith_buy_table)) + npc_create("Smith", 5, GENDER_MALE, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Smith, smith_buy_table)) -- The most simple NPC - Welcoming new ones around. - mana.npc_create("Harmony", 11, GENDER_FEMALE, 4 * TILESIZE + TILESIZE / 2, 25 * TILESIZE + TILESIZE / 2, npclib.talk(Harmony, "Welcome in the template world!\nI hope you'll find here whatever you were searching for.", "Do look around to find some interesting things coming along!"), Harmony_update) + npc_create("Harmony", 11, GENDER_FEMALE, 4 * TILESIZE + TILESIZE / 2, 25 * TILESIZE + TILESIZE / 2, npclib.talk(Harmony, "Welcome in the template world!\nI hope you'll find here whatever you were searching for.", "Do look around to find some interesting things coming along!"), Harmony_update) -- Creates a Monster an let it talk for testing purpose. - mana.npc_create("Tamer", 9, GENDER_UNSPECIFIED, 28 * TILESIZE + TILESIZE / 2, 21 * TILESIZE + TILESIZE / 2, Tamer) + npc_create("Tamer", 9, GENDER_UNSPECIFIED, 28 * TILESIZE + TILESIZE / 2, 21 * TILESIZE + TILESIZE / 2, Tamer) end) function Smith(npc, ch, list) - local sword_count = mana.chr_inv_count(ch, true, true, "Sword") + local sword_count = chr_inv_count(ch, true, true, "Sword") if sword_count > 0 then - mana.npc_message(npc, ch, "Ah! I can see you already have a sword.") + npc_message(npc, ch, "Ah! I can see you already have a sword.") end Merchant(npc, ch, list) end @@ -48,23 +48,23 @@ function possessions_table(npc, ch) local item_message = "Inventory:".. "\nSlot id, item id, item name, amount:".. "\n----------------------" - local inventory_table = mana.chr_get_inventory(ch) + local inventory_table = chr_get_inventory(ch) for i = 1, #inventory_table do item_message = item_message.."\n"..inventory_table[i].slot..", " ..inventory_table[i].id..", "..inventory_table[i].name..", " ..inventory_table[i].amount end - mana.npc_message(npc, ch, item_message) + npc_message(npc, ch, item_message) item_message = "Equipment:".. "\nSlot id, item id, item name:".. "\n----------------------" - local equipment_table = mana.chr_get_equipment(ch) + local equipment_table = chr_get_equipment(ch) for i = 1, #equipment_table do item_message = item_message.."\n"..equipment_table[i].slot..", " ..equipment_table[i].id..", "..equipment_table[i].name end - mana.npc_message(npc, ch, item_message) + npc_message(npc, ch, item_message) end @@ -73,30 +73,30 @@ harmony_have_talked_to_someone = false function Harmony(npc, ch, list) -- Say all the messages in the messages list. for i = 1, #list do - mana.npc_message(npc, ch, list[i]) + npc_message(npc, ch, list[i]) end --- Give the player 100 units of money the first time. if harmony_have_talked_to_someone == false then - mana.npc_message(npc, ch, "Here is some money for you to find some toys to play with.\nEh Eh!") - mana.chr_money_change(ch, 100) - mana.npc_message(npc, ch, string.format("You now have %d shiny coins!", mana.chr_money(ch))) + npc_message(npc, ch, "Here is some money for you to find some toys to play with.\nEh Eh!") + chr_money_change(ch, 100) + npc_message(npc, ch, string.format("You now have %d shiny coins!", chr_money(ch))) harmony_have_talked_to_someone = true - mana.npc_message(npc, ch, string.format("Try to come back with a better level than %i.", mana.chr_get_level(ch))) + npc_message(npc, ch, string.format("Try to come back with a better level than %i.", chr_get_level(ch))) else - mana.npc_message(npc, ch, "Let me see what you've got so far... Don't be afraid!") - mana.effect_create(EMOTE_WINK, npc) + npc_message(npc, ch, "Let me see what you've got so far... Don't be afraid!") + effect_create(EMOTE_WINK, npc) possessions_table(npc, ch) end - mana.npc_message(npc, ch, "Have fun!") - mana.effect_create(EMOTE_HAPPY, npc) + npc_message(npc, ch, "Have fun!") + effect_create(EMOTE_HAPPY, npc) -- Make Harmony disappear for a while... with a small earthquake effect! - local shakeX = mana.posX(npc) - local shakeY = mana.posY(npc) - mana.npc_disable(npc) + local shakeX = posX(npc) + local shakeY = posY(npc) + npc_disable(npc) tremor(shakeX, shakeY, 300) -- 20 seconds later, Harmony comes back - schedule_in(20, function() mana.npc_enable(npc) end) + schedule_in(20, function() npc_enable(npc) end) schedule_in(20, function() tremor(shakeX, shakeY, 300) end) end @@ -108,35 +108,35 @@ function Harmony_update(npc) harmony_tick_count = harmony_tick_count + 1 if harmony_tick_count > 100 then harmony_tick_count = 0 - mana.being_say(npc, "Hey! You're new! Come here...") + being_say(npc, "Hey! You're new! Come here...") end end end function Tamer(npc, ch, list) - mana.being_say(npc, string.format("You have %s Sword(s).", - mana.chr_inv_count(ch, true, true, "Sword"))) - mana.being_say(npc, string.format("You are %s pixel away.", - mana.get_distance(npc, ch))) - mana.being_say(npc, "I will now spawn a monster for your training session.") + being_say(npc, string.format("You have %s Sword(s).", + chr_inv_count(ch, true, true, "Sword"))) + being_say(npc, string.format("You are %s pixel away.", + get_distance(npc, ch))) + being_say(npc, "I will now spawn a monster for your training session.") -- Remove monsters in the area - for i, b in ipairs(mana.get_beings_in_rectangle(mana.posX(npc) - 3 * TILESIZE, - mana.posY(npc) - 3 * TILESIZE, + for i, b in ipairs(get_beings_in_rectangle(posX(npc) - 3 * TILESIZE, + posY(npc) - 3 * TILESIZE, 6 * TILESIZE, 6 * TILESIZE)) do - if mana.being_type(b) == TYPE_MONSTER then - mana.monster_remove(b) + if being_type(b) == TYPE_MONSTER then + monster_remove(b) end end - local m1 = mana.monster_create("Maggot", mana.posX(ch), mana.posY(ch)) - mana.monster_change_anger(m1, ch, 100) + local m1 = monster_create("Maggot", posX(ch), posY(ch)) + monster_change_anger(m1, ch, 100) -- (The following is not safe, since the being might have been removed by -- the time this function gets executed (especially with the above code)) -- --schedule_in(0.5, function() - -- mana.being_say(m1, "Roaaarrrr!!!") - -- mana.monster_change_anger(m1, ch, 100) + -- being_say(m1, "Roaaarrrr!!!") + -- monster_change_anger(m1, ch, 100) -- end) end diff --git a/example/scripts/monster/testmonster.lua b/example/scripts/monster/testmonster.lua index 63b29179..6ef11faa 100644 --- a/example/scripts/monster/testmonster.lua +++ b/example/scripts/monster/testmonster.lua @@ -10,20 +10,20 @@ local function update(mob) local r = math.random(0, 200); if r == 0 then - mana.being_say(mob, "Roar! I am a boss") + being_say(mob, "Roar! I am a boss") end end local function strike(mob, victim, hit) if hit > 0 then - mana.being_say(mob, "Take this! "..hit.." damage!") - mana.being_say(victim, "Oh Noez!") + being_say(mob, "Take this! "..hit.." damage!") + being_say(victim, "Oh Noez!") else - mana.being_say(mob, "Oh no, my attack missed!") - mana.being_say(victim, "Whew...") + being_say(mob, "Oh no, my attack missed!") + being_say(victim, "Whew...") end end -local maggot = mana.get_monster_class("maggot") +local maggot = get_monster_class("maggot") maggot:on_update(update) maggot:on("strike", strike) diff --git a/example/scripts/npcs/banker.lua b/example/scripts/npcs/banker.lua index 762e0bbe..e6e1e284 100644 --- a/example/scripts/npcs/banker.lua +++ b/example/scripts/npcs/banker.lua @@ -11,22 +11,22 @@ ---------------------------------------------------------------------------------- function Banker(npc, ch) - if mana.being_get_gender(ch) == GENDER_MALE then - mana.npc_message(npc, ch, "Welcome to the bank, sir!") - elseif mana.being_get_gender(ch) == GENDER_FEMALE then - mana.npc_message(npc, ch, "Welcome to the bank, madam!") + if being_get_gender(ch) == GENDER_MALE then + npc_message(npc, ch, "Welcome to the bank, sir!") + elseif being_get_gender(ch) == GENDER_FEMALE then + npc_message(npc, ch, "Welcome to the bank, madam!") else - mana.npc_message(npc, ch, "Welcome to the bank... uhm... person of unspecified gender!") + npc_message(npc, ch, "Welcome to the bank... uhm... person of unspecified gender!") end - local account = tonumber(mana.chr_get_quest(ch, "BankAccount")) + local account = tonumber(chr_get_quest(ch, "BankAccount")) local result = -1 if (account == nil) then --Initial account creation, if needed - mana.npc_message(npc, ch, "Hello! Would you like to setup a bank account? There is a sign-on bonus right now!") - result = mana.npc_choice(npc, ch, "Yes", "No") + npc_message(npc, ch, "Hello! Would you like to setup a bank account? There is a sign-on bonus right now!") + result = npc_choice(npc, ch, "Yes", "No") if (result == 1) then - mana.chr_set_quest(ch, "BankAccount", 5) - mana.npc_message(npc, ch, "Your account has been made. Your sign-on bonus is 5GP.") + chr_set_quest(ch, "BankAccount", 5) + npc_message(npc, ch, "Your account has been made. Your sign-on bonus is 5GP.") account = 5 end end @@ -36,42 +36,42 @@ function Banker(npc, ch) local input = 0 result = 1 while (result < 3) do --While they've choosen a valid option that isn't "Never mind" - account = tonumber(mana.chr_get_quest(ch, "BankAccount")) --Why do I need to convert this? - mana.npc_message(npc, ch, "Your balance: " .. account .. ".\nYour money: " .. mana.chr_money(ch) .. ".") - result = mana.npc_choice(npc, ch, "Deposit", "Withdraw", "Never mind") + account = tonumber(chr_get_quest(ch, "BankAccount")) --Why do I need to convert this? + npc_message(npc, ch, "Your balance: " .. account .. ".\nYour money: " .. chr_money(ch) .. ".") + result = npc_choice(npc, ch, "Deposit", "Withdraw", "Never mind") if (result == 1) then --Deposit - money = mana.chr_money(ch); + money = chr_money(ch); if (money > 0) then --Make sure they have money to deposit - mana.npc_message(npc, ch, "How much would you like to deposit? (0 will cancel)") - input = mana.npc_ask_integer(npc, ch, 0, money, 1) - money = mana.chr_money(ch) + npc_message(npc, ch, "How much would you like to deposit? (0 will cancel)") + input = npc_ask_integer(npc, ch, 0, money, 1) + money = chr_money(ch) if (input > 0 and input <= money) then --Make sure something weird doesn't happen and they try to deposit more than they have - mana.chr_money_change(ch, -input) - mana.chr_set_quest(ch, "BankAccount", account + input) - mana.npc_message(npc, ch, input .. " GP deposited.") + chr_money_change(ch, -input) + chr_set_quest(ch, "BankAccount", account + input) + npc_message(npc, ch, input .. " GP deposited.") elseif (input > money) then --Chosen more than they have - mana.npc_message(npc, ch, "You don't have that much money. But you just did....") + npc_message(npc, ch, "You don't have that much money. But you just did....") end else - mana.npc_message(npc, ch, "You don't have any money to deposit!") + npc_message(npc, ch, "You don't have any money to deposit!") end elseif (result == 2) then --Withdraw if (account > 0) then --Make sure they have money to withdraw - mana.npc_message(npc, ch, "How much would you like to withdraw? (0 will cancel)") - input = mana.npc_ask_integer(npc, ch, 0, account, 1) + npc_message(npc, ch, "How much would you like to withdraw? (0 will cancel)") + input = npc_ask_integer(npc, ch, 0, account, 1) if (input > 0 and input <= account) then --Make sure something weird doesn't happen and they try to withdraw more than they have - mana.chr_money_change(ch, input) - mana.chr_set_quest(ch, "BankAccount", account - input) - mana.npc_message(npc, ch, input .. " GP withdrawn.") + chr_money_change(ch, input) + chr_set_quest(ch, "BankAccount", account - input) + npc_message(npc, ch, input .. " GP withdrawn.") elseif (input > account) then --Chosen more than they have - mana.npc_message(npc, ch, "You don't have that much in your account. But you just did....") + npc_message(npc, ch, "You don't have that much in your account. But you just did....") end else - mana.npc_message(npc, ch, "Your account is empty!") + npc_message(npc, ch, "Your account is empty!") end end end --This ends the while loop end - mana.npc_message(npc, ch, "Thank you. Come again!") + npc_message(npc, ch, "Thank you. Come again!") end diff --git a/example/scripts/npcs/barber.lua b/example/scripts/npcs/barber.lua index 79f92526..70efb435 100644 --- a/example/scripts/npcs/barber.lua +++ b/example/scripts/npcs/barber.lua @@ -79,11 +79,11 @@ function Barber(npc, ch, data) -- Choose an appropriate message if result == 1 then - mana.npc_message(npc, ch, "Hello! What style would you like today?") + npc_message(npc, ch, "Hello! What style would you like today?") elseif result == 2 then - mana.npc_message(npc, ch, "Hello! What color would you like today?") + npc_message(npc, ch, "Hello! What color would you like today?") else - mana.npc_message(npc, ch, "Hello! What can I do for you today?") + npc_message(npc, ch, "Hello! What can I do for you today?") end print("#styles ==", #styles) @@ -91,7 +91,7 @@ function Barber(npc, ch, data) -- Repeat until the user selects nothing repeat if (result == 1) then -- Do styles - result = mana.npc_choice(npc, ch, "Bald", styles, "Surprise me", "Never mind") + result = npc_choice(npc, ch, "Bald", styles, "Surprise me", "Never mind") result = result -1 @@ -104,16 +104,16 @@ function Barber(npc, ch, data) print("Style ==", result) if (result == 0) then - mana.chr_set_hair_style(ch, 0) + chr_set_hair_style(ch, 0) result = 1 elseif (result <= #styles) then - mana.chr_set_hair_style(ch, style_ids[result]) + chr_set_hair_style(ch, style_ids[result]) result = 1 else --"Never mind" result = 3 end elseif (result == 2) then -- Do colors - result = mana.npc_choice(npc, ch, colors, "Surprise me", "Never mind") + result = npc_choice(npc, ch, colors, "Surprise me", "Never mind") --Random if (result == #colors + 1) then @@ -121,7 +121,7 @@ function Barber(npc, ch, data) end if (result <= #colors) then - mana.chr_set_hair_color(ch, color_ids[result - 1]) + chr_set_hair_color(ch, color_ids[result - 1]) result = 2 else --"Never mind" result = 3 @@ -130,10 +130,10 @@ function Barber(npc, ch, data) -- If we have both styles and colors, show the main menu if #styles > 0 and #colors > 0 then - result = mana.npc_choice(npc, ch, "Change my style", "Change my color", "Never mind") + result = npc_choice(npc, ch, "Change my style", "Change my color", "Never mind") end until result >= 3 --While they've choosen a valid option that isn't "Never mind" -- Let's close up - mana.npc_message(npc, ch, "Thank you. Come again!") + npc_message(npc, ch, "Thank you. Come again!") end diff --git a/example/scripts/npcs/debugger.lua b/example/scripts/npcs/debugger.lua index 80f765c9..621ba0f6 100644 --- a/example/scripts/npcs/debugger.lua +++ b/example/scripts/npcs/debugger.lua @@ -12,67 +12,67 @@ function npc1_talk(npc, ch) on_remove(ch, function() print "Player has left the map." end); - mana.npc_message(npc, ch, "Hello! I am the testing NPC.") - local rights = mana.chr_get_rights(ch); + npc_message(npc, ch, "Hello! I am the testing NPC.") + local rights = chr_get_rights(ch); if (rights >= 128) then - mana.npc_message(npc, ch, "Oh mighty server administrator, how can I avoid your wrath?") + npc_message(npc, ch, "Oh mighty server administrator, how can I avoid your wrath?") elseif (rights >= 8) then - mana.npc_message(npc, ch, "How can I be of assistance, sir gamemaster?") + npc_message(npc, ch, "How can I be of assistance, sir gamemaster?") elseif (rights >= 4) then - mana.npc_message(npc, ch, "What feature would you like to debug, developer?") + npc_message(npc, ch, "What feature would you like to debug, developer?") elseif (rights >= 2) then - mana.npc_message(npc, ch, "How can I assist you in your testing duties?") + npc_message(npc, ch, "How can I assist you in your testing duties?") elseif (rights >= 1) then - mana.npc_message(npc, ch, "What do you want, lowly player?") + npc_message(npc, ch, "What do you want, lowly player?") else - mana.npc_message(npc, ch, "...aren't you supposed to be banned??") + npc_message(npc, ch, "...aren't you supposed to be banned??") end - local v = mana.npc_choice(npc, ch, "Guns! Lots of guns!", + local v = npc_choice(npc, ch, "Guns! Lots of guns!", "A Christmas party!", "To make a donation.", "Slowly count from one to ten.", "Tablepush Test") if v == 1 then - mana.npc_message(npc, ch, "Sorry, this is a heroic-fantasy game, I do not have any gun.") + npc_message(npc, ch, "Sorry, this is a heroic-fantasy game, I do not have any gun.") elseif v == 2 then - local n1, n2 = mana.chr_inv_count(ch, 524, 511) + local n1, n2 = chr_inv_count(ch, 524, 511) if n1 == 0 or n2 ~= 0 then - mana.npc_message(npc, ch, "Yeah right...") + npc_message(npc, ch, "Yeah right...") else - mana.npc_message(npc, ch, "I can't help you with the party. But I see you have a fancy hat. I could change it into Santa's hat. Not much of a party, but it would get you going.") - v = mana.npc_choice(npc, ch, "Please do.", "No way! Fancy hats are classier.") + npc_message(npc, ch, "I can't help you with the party. But I see you have a fancy hat. I could change it into Santa's hat. Not much of a party, but it would get you going.") + v = npc_choice(npc, ch, "Please do.", "No way! Fancy hats are classier.") if v == 1 then - mana.chr_inv_change(ch, 524, -1, 511, 1) + chr_inv_change(ch, 524, -1, 511, 1) end end elseif v == 3 then - if mana.chr_money_change(ch, -100) then - mana.npc_message(npc, ch, string.format("Thank you for you patronage! You are left with %d GP.", mana.chr_money(ch))) - local g = tonumber(mana.chr_get_quest(ch, "001_donation")) + if chr_money_change(ch, -100) then + npc_message(npc, ch, string.format("Thank you for you patronage! You are left with %d GP.", chr_money(ch))) + local g = tonumber(chr_get_quest(ch, "001_donation")) if not g then g = 0 end g = g + 100 - mana.chr_set_quest(ch, "001_donation", g) - mana.npc_message(npc, ch, string.format("As of today, you have donated %d GP.", g)) + chr_set_quest(ch, "001_donation", g) + npc_message(npc, ch, string.format("As of today, you have donated %d GP.", g)) else - mana.npc_message(npc, ch, "I would feel bad taking money from someone that poor.") + npc_message(npc, ch, "I would feel bad taking money from someone that poor.") end elseif v == 4 then - mana.being_say(npc, "As you wish...") - schedule_in(2, function() mana.being_say(npc, "One") end) - schedule_in(4, function() mana.being_say(npc, "Two") end) - schedule_in(6, function() mana.being_say(npc, "Three") end) - schedule_in(8, function() mana.being_say(npc, "Four") end) - schedule_in(10, function() mana.being_say(npc, "Five") end) - schedule_in(12, function() mana.being_say(npc, "Six") end) - schedule_in(14, function() mana.being_say(npc, "Seven") end) - schedule_in(16, function() mana.being_say(npc, "Eight") end) - schedule_in(18, function() mana.being_say(npc, "Nine") end) - schedule_in(20, function() mana.being_say(npc, "Ten") end) + being_say(npc, "As you wish...") + schedule_in(2, function() being_say(npc, "One") end) + schedule_in(4, function() being_say(npc, "Two") end) + schedule_in(6, function() being_say(npc, "Three") end) + schedule_in(8, function() being_say(npc, "Four") end) + schedule_in(10, function() being_say(npc, "Five") end) + schedule_in(12, function() being_say(npc, "Six") end) + schedule_in(14, function() being_say(npc, "Seven") end) + schedule_in(16, function() being_say(npc, "Eight") end) + schedule_in(18, function() being_say(npc, "Nine") end) + schedule_in(20, function() being_say(npc, "Ten") end) elseif v == 5 then function printTable (t) @@ -80,7 +80,7 @@ function npc1_talk(npc, ch) print (k, ":", v) end end - local t1, t2, t3, t4, t5 = mana.test_tableget(); + local t1, t2, t3, t4, t5 = test_tableget(); print("---------------"); print ("Table 1:"); printTable (t1) @@ -95,6 +95,6 @@ function npc1_talk(npc, ch) print("---------------"); end - mana.npc_message(npc, ch, "See you later!") + npc_message(npc, ch, "See you later!") end diff --git a/example/scripts/npcs/emotemaker.lua b/example/scripts/npcs/emotemaker.lua index 4aa39e80..0f546634 100644 --- a/example/scripts/npcs/emotemaker.lua +++ b/example/scripts/npcs/emotemaker.lua @@ -21,8 +21,8 @@ function emote_talk(npc, ch) elseif emo_state == EMOTE_HAPPY then state = "happy" end - mana.npc_message(npc, ch, string.format("The emotional palm seems %s.", state)) - v = mana.npc_choice(npc, ch, + npc_message(npc, ch, string.format("The emotional palm seems %s.", state)) + v = npc_choice(npc, ch, "Stupid palm, you are ugly and everyone hates you!", "You are such a nice palm, let me give you a hug.", "Are you a cocos nucifera or a syagrus romanzoffiana?") @@ -40,6 +40,6 @@ function emote_update(npc) emo_count = emo_count + 1 if emo_count > 50 then emo_count = 0 - mana.effect_create(emo_state, npc) + effect_create(emo_state, npc) end end diff --git a/example/scripts/npcs/healer.lua b/example/scripts/npcs/healer.lua index 478047bf..35696736 100644 --- a/example/scripts/npcs/healer.lua +++ b/example/scripts/npcs/healer.lua @@ -5,11 +5,11 @@ --]] function Healer(npc, ch) - mana.npc_message(npc, ch, "Do you need healing?") - local c = mana.npc_choice(npc, ch, "Heal me fully", "Heal 100 HP", "Don't heal me") + npc_message(npc, ch, "Do you need healing?") + local c = npc_choice(npc, ch, "Heal me fully", "Heal 100 HP", "Don't heal me") if c == 1 then - mana.being_heal(ch) + being_heal(ch) elseif c == 2 then - mana.being_heal(ch, 100) + being_heal(ch, 100) end end diff --git a/example/scripts/npcs/merchant.lua b/example/scripts/npcs/merchant.lua index 71d05441..2ef0a6b7 100644 --- a/example/scripts/npcs/merchant.lua +++ b/example/scripts/npcs/merchant.lua @@ -13,7 +13,7 @@ function Merchant(npc, ch, buy_sell_table) local function say(message) - mana.npc_message(npc, ch, message) + npc_message(npc, ch, message) end -- Important note: You can add two tables made of trinoms here when calling the @@ -22,11 +22,11 @@ function Merchant(npc, ch, buy_sell_table) -- buy_sell_table[1] will corresponds to the first table (used to list -- boughtable items, and buy_sell_table[2] listing sellable items. - local rights = mana.chr_get_rights(ch); + local rights = chr_get_rights(ch); if (rights >= 128) then - mana.announce(mana.being_get_name(ch) .. " the big administrator was at my shop!", - mana.being_get_name(npc)) + announce(being_get_name(ch) .. " the big administrator was at my shop!", + being_get_name(npc)) say "Oh mighty server administrator, how can I avoid your wrath?" elseif (rights >= 8) then say "How can I be of assistance, sir gamemaster?" @@ -35,7 +35,7 @@ function Merchant(npc, ch, buy_sell_table) elseif (rights >= 2) then say "How can I assist you in your testing duties?" elseif (rights >= 1) then - if mana.being_get_gender(ch) == GENDER_FEMALE then + if being_get_gender(ch) == GENDER_FEMALE then say "What do you want, Madam?" else say "What do you want, Sir?" @@ -56,7 +56,7 @@ function Merchant(npc, ch, buy_sell_table) table.insert (choice_table, "Tell me about the objects on this map") table.insert (choice_table, "Nevermind...") - local v = mana.npc_choice(npc, ch, choice_table) + local v = npc_choice(npc, ch, choice_table) --Debug and learning purpose --for i,k in ipairs(choice_table) do print(i,k) end @@ -67,7 +67,7 @@ function Merchant(npc, ch, buy_sell_table) if v == 1 then -- "To buy." - local buycase = mana.npc_trade(npc, ch, false, buy_sell_table[1]) + local buycase = npc_trade(npc, ch, false, buy_sell_table[1]) if buycase == 0 then say "What do you want to buy?" elseif buycase == 1 then @@ -80,7 +80,7 @@ function Merchant(npc, ch, buy_sell_table) if buy_sell_table[2] == nil then -- "To sell stuff..." - local sellcase = mana.npc_trade(npc, ch, true) + local sellcase = npc_trade(npc, ch, true) if sellcase == 0 then say "Ok, what do you want to sell?" elseif sellcase == 1 then @@ -90,7 +90,7 @@ function Merchant(npc, ch, buy_sell_table) end else -- "Can you make me a price for what I have?" - local sellcase = mana.npc_trade(npc, ch, true, buy_sell_table[2]) + local sellcase = npc_trade(npc, ch, true, buy_sell_table[2]) if sellcase == 0 then say "Here we go:" elseif sellcase == 1 then @@ -102,7 +102,7 @@ function Merchant(npc, ch, buy_sell_table) elseif v == 3 then - local objects = mana.map_get_objects() + local objects = map_get_objects() say("There are " .. #objects .. " objects on this map, their names are:") for i=1,#objects do say(tostring(i) .. ": " .. objects[i]:name()) diff --git a/example/scripts/npcs/postman.lua b/example/scripts/npcs/postman.lua index ef64b169..95e6844e 100644 --- a/example/scripts/npcs/postman.lua +++ b/example/scripts/npcs/postman.lua @@ -11,20 +11,20 @@ ---------------------------------------------------------------------------------- function post_talk(npc, ch) - mana.npc_message(npc, ch, "Hello " .. mana.being_get_name(ch)) - local strength = mana.being_get_attribute(ch, ATTR_STRENGTH) - mana.npc_message(npc, ch, "You have " .. tostring(strength) .. " strength") - mana.npc_message(npc, ch, "What would you like to do?") - local answer = mana.npc_choice(npc, ch, "View Mail", "Send Mail", "Nothing") + npc_message(npc, ch, "Hello " .. being_get_name(ch)) + local strength = being_get_attribute(ch, ATTR_STRENGTH) + npc_message(npc, ch, "You have " .. tostring(strength) .. " strength") + npc_message(npc, ch, "What would you like to do?") + local answer = npc_choice(npc, ch, "View Mail", "Send Mail", "Nothing") if answer == 1 then - local sender, post = mana.chr_get_post(ch) + local sender, post = chr_get_post(ch) if sender == "" then - mana.npc_message(npc, ch, "No Post right now, sorry") + npc_message(npc, ch, "No Post right now, sorry") else - mana.npc_message(npc, ch, tostring(sender) .. " sent you " .. tostring(post)) + npc_message(npc, ch, tostring(sender) .. " sent you " .. tostring(post)) end end if answer == 2 then - mana.npc_post(npc, ch) + npc_post(npc, ch) end end diff --git a/example/scripts/npcs/shaker.lua b/example/scripts/npcs/shaker.lua index ac6b152a..768fc126 100644 --- a/example/scripts/npcs/shaker.lua +++ b/example/scripts/npcs/shaker.lua @@ -15,8 +15,8 @@ function shaker_update(npc) if shake_count > 20 then
shake_count = 0
- center_x = mana.posX(npc)
- center_y = mana.posY(npc)
+ center_x = posX(npc)
+ center_y = posY(npc)
tremor(center_x, center_y, 300)
end
end
@@ -28,17 +28,17 @@ function square(x) end
function tremor (center_x, center_y, intensity)
- for dummy, object in ipairs(mana.get_beings_in_circle(center_x, center_y, intensity)) do
- if mana.being_type(object) == TYPE_CHARACTER then
- object_x = mana.posX(object)
- object_y = mana.posY(object)
+ for dummy, object in ipairs(get_beings_in_circle(center_x, center_y, intensity)) do
+ if being_type(object) == TYPE_CHARACTER then
+ object_x = posX(object)
+ object_y = posY(object)
dist_x = object_x - center_x
dist_y = object_y - center_y
dist = math.sqrt(square(dist_x) + square(dist_y))
intensity_local = intensity - dist
intensity_x = (intensity - dist) * (dist_x / dist) / 5
intensity_y = (intensity - dist) * (dist_y / dist) / 5
- mana.chr_shake_screen(object, intensity_x, intensity_y)
+ chr_shake_screen(object, intensity_x, intensity_y)
end
end
end
diff --git a/example/scripts/special_actions.lua b/example/scripts/special_actions.lua index 7e42ad43..25619f41 100644 --- a/example/scripts/special_actions.lua +++ b/example/scripts/special_actions.lua @@ -16,13 +16,13 @@ specialCost[3] = 1000 local function use_special(ch, id) -- perform whatever the special with the ID does if id == 1 then - mana.being_say(ch, "Kaaame...Haaame... HAAAAAA!") + being_say(ch, "Kaaame...Haaame... HAAAAAA!") end if id == 2 then - mana.being_say(ch, "HAA-DOKEN!") + being_say(ch, "HAA-DOKEN!") end if id == 3 then - mana.being_say(ch, "Sonic BOOM") + being_say(ch, "Sonic BOOM") end end @@ -31,5 +31,5 @@ local function get_special_recharge_cost(id) return specialCost[id] end -mana.on_use_special(use_special) -mana.on_get_special_recharge_cost(get_special_recharge_cost) +on_use_special(use_special) +on_get_special_recharge_cost(get_special_recharge_cost) diff --git a/example/scripts/status/jump.lua b/example/scripts/status/jump.lua index 166c90d1..9dc01951 100644 --- a/example/scripts/status/jump.lua +++ b/example/scripts/status/jump.lua @@ -14,16 +14,16 @@ local function tick(target, ticknumber) if (ticknumber % 10 == 0) then - mana.being_say(target, "I have the jumping bug!") + being_say(target, "I have the jumping bug!") end - if (mana.being_get_status_time(target, 2) < 2000) then - mana.being_set_status_time(target, 2, 6000) + if (being_get_status_time(target, 2) < 2000) then + being_set_status_time(target, 2, 6000) end if (ticknumber % 50 ~= 0) then return end - local victims = mana.get_beings_in_circle(mana.posX(target), mana.posY(target), 64) + local victims = get_beings_in_circle(posX(target), posY(target), 64) local count = #victims if i == 0 then return end @@ -40,16 +40,16 @@ local function tick(target, ticknumber) victim = nil i = -1 else - i = mana.being_type(victim) + i = being_type(victim) end until (i == TYPE_MONSTER or i == TYPE_CHARACTER or remaining == 0) if (victim == nil) then return end - mana.being_remove_status(target, 2) + being_remove_status(target, 2) - mana.being_apply_status(victim, 2, 6000) - mana.being_say(victim, "Now I have the jumping bug") + being_apply_status(victim, 2, 6000) + being_say(victim, "Now I have the jumping bug") end -mana.get_status_effect("jumping status"):on_tick(tick) +get_status_effect("jumping status"):on_tick(tick) diff --git a/example/scripts/status/plague.lua b/example/scripts/status/plague.lua index a43b9d40..2f6a5f6c 100644 --- a/example/scripts/status/plague.lua +++ b/example/scripts/status/plague.lua @@ -14,17 +14,17 @@ local function tick(target, ticknumber) if (ticknumber % 10 == 0) then - mana.being_say(target, "I have the plague! :( = " .. ticknumber) + being_say(target, "I have the plague! :( = " .. ticknumber) end - local victims = mana.get_beings_in_circle(mana.posX(target), mana.posY(target), 64) + local victims = get_beings_in_circle(posX(target), posY(target), 64) local i = 1 while (victims[i]) do - if (mana.being_has_status(victims[i], 1) == false) then - mana.being_apply_status(victims[i], 1, 6000) - mana.being_say(victims[i], "I don't feel so good") + if (being_has_status(victims[i], 1) == false) then + being_apply_status(victims[i], 1, 6000) + being_say(victims[i], "I don't feel so good") end i = i + 1 end end -mana.get_status_effect("plague"):on_tick(tick) +get_status_effect("plague"):on_tick(tick) diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index e76e9ec0..e9c89212 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -61,7 +61,7 @@ end local function create_npc_delayed(name, id, gender, x, y) -- Bind the name to a local variable first, as it will be reused. local h = npc_handler - atinit(function() mana.npc_create(name, id, gender, x, y, h) end) + atinit(function() npc_create(name, id, gender, x, y, h) end) npc_handler = nil end @@ -120,7 +120,7 @@ local onworldvar_functs = {} local function on_mapvar_callback(key, value) local functs = onmapvar_functs[key] - local mapid = mana.get_map_id() + local mapid = get_map_id() for func, map in pairs(functs) do if map == mapid then func(key, value) @@ -138,15 +138,15 @@ end function on_mapvar_changed(key, funct) if not onmapvar_functs[key] then onmapvar_functs[key] = {} - mana.on_mapvar_changed(key, on_mapvar_callback) + on_mapvar_changed(key, on_mapvar_callback) end - onmapvar_functs[key][funct] = mana.get_map_id() + onmapvar_functs[key][funct] = get_map_id() end function on_worldvar_changed(key, funct) if not onworldvar_functs[key] then onworldvar_functs[key] = {} - mana.on_worldvar_changed(key, on_worldvar_callback) + on_worldvar_changed(key, on_worldvar_callback) end onworldvar_functs[key][funct] = true end @@ -170,7 +170,7 @@ function on_death(being, funct) ondeath_functs[being] = {} end table.insert(ondeath_functs[being], funct) - mana.being_register(being) + being_register(being) end -- requests the gameserver to notify the script engine when the being @@ -180,7 +180,7 @@ function on_remove(being, funct) onremove_functs[being] = {} end table.insert(onremove_functs[being], funct) - mana.being_register(being) + being_register(being) end -- Registered as callback for when a registered being dies. @@ -206,22 +206,22 @@ end -- Below are some convenience methods added to the engine API -mana.chr_money_change = function(ch, amount) - mana.being_set_base_attribute( +chr_money_change = function(ch, amount) + being_set_base_attribute( ch, ATTR_GP, - mana.being_get_base_attribute(ch, ATTR_GP) + amount) + being_get_base_attribute(ch, ATTR_GP) + amount) end -mana.chr_money = function(ch) - return mana.being_get_base_attribute(ch, ATTR_GP) +chr_money = function(ch) + return being_get_base_attribute(ch, ATTR_GP) end -- Register callbacks -mana.on_update(update) +on_update(update) -mana.on_create_npc_delayed(create_npc_delayed) -mana.on_map_initialize(map_initialize) +on_create_npc_delayed(create_npc_delayed) +on_map_initialize(map_initialize) -mana.on_being_death(death_notification) -mana.on_being_remove(remove_notification) +on_being_death(death_notification) +on_being_remove(remove_notification) diff --git a/scripts/lua/npclib.lua b/scripts/lua/npclib.lua index 9edfcbd9..48e53769 100644 --- a/scripts/lua/npclib.lua +++ b/scripts/lua/npclib.lua @@ -31,8 +31,8 @@ local wasmall_starty = {} function walkaround_small(npc) if not wasmall_timer[npc] then wasmall_timer[npc] = 1 - wasmall_startx[npc] = mana.posX(npc) - wasmall_starty[npc] = mana.posY(npc) + wasmall_startx[npc] = posX(npc) + wasmall_starty[npc] = posY(npc) end wasmall_timer[npc] = wasmall_timer[npc] + 1 @@ -41,7 +41,7 @@ function walkaround_small(npc) wasmall_timer[npc] = math.random(1, 10) local x = math.random(-32, 32) + wasmall_startx[npc] local y = math.random(-32, 32) + wasmall_starty[npc] - mana.being_walk(npc, x, y, 2) + being_walk(npc, x, y, 2) end end @@ -58,8 +58,8 @@ local wawide_starty = {} function walkaround_wide(npc) if not wawide_timer[npc] then wawide_timer[npc] = 1 - wawide_startx[npc] = mana.posX(npc) - wawide_starty[npc] = mana.posY(npc) + wawide_startx[npc] = posX(npc) + wawide_starty[npc] = posY(npc) end wawide_timer[npc] = wawide_timer[npc] + 1 @@ -68,7 +68,7 @@ function walkaround_wide(npc) wawide_timer[npc] = math.random(1, 10) local x = math.random(-128, 128) + wawide_startx[npc] local y = math.random(-128, 128) + wawide_starty[npc] - mana.being_walk(npc, x, y, 2) + being_walk(npc, x, y, 2) end end @@ -88,9 +88,9 @@ function walkaround_map(npc) if wam_timer[npc] == 50 then wam_timer[npc] = math.random(1, 10) - local x = math.random(-128, 128) + mana.posX(npc) - local y = math.random(-128, 128) + mana.posY(npc) - mana.being_walk(npc, x, y, 2) + local x = math.random(-128, 128) + posX(npc) + local y = math.random(-128, 128) + posY(npc) + being_walk(npc, x, y, 2) end end diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 273bdf42..9eca2df6 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -2239,8 +2239,9 @@ LuaScript::LuaScript(): { "announce", &announce }, { NULL, NULL } }; - luaL_register(mRootState, "mana", callbacks); - lua_pop(mRootState, 1); // pop the 'mana' table + lua_pushvalue(mRootState, LUA_GLOBALSINDEX); + luaL_register(mRootState, NULL, callbacks); + lua_pop(mRootState, 1); // pop the globals table static luaL_Reg const members_ItemClass[] = { { "on", &item_class_on }, |