diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-14 15:41:33 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-14 15:41:33 +0200 |
commit | 0f1449567d5a2ccab9ff6fdc9975150299482834 (patch) | |
tree | 9d03df41026928cc5cecd6801a0f214fabd1d77e | |
parent | 080ddbe822b03416934a875b2d949e3afc84fb96 (diff) | |
download | manaserv-0f1449567d5a2ccab9ff6fdc9975150299482834.tar.gz manaserv-0f1449567d5a2ccab9ff6fdc9975150299482834.tar.xz manaserv-0f1449567d5a2ccab9ff6fdc9975150299482834.zip |
Simplified some script function names
npc_message -> say
npc_choice -> ask
npc_ask_integer -> ask_number
npc_ask_string -> ask_string
npc_trade -> trade
-rw-r--r-- | example/scripts/maps/desert.lua | 18 | ||||
-rw-r--r-- | example/scripts/npcs/banker.lua | 38 | ||||
-rw-r--r-- | example/scripts/npcs/barber.lua | 14 | ||||
-rw-r--r-- | example/scripts/npcs/debugger.lua | 40 | ||||
-rw-r--r-- | example/scripts/npcs/emotemaker.lua | 8 | ||||
-rw-r--r-- | example/scripts/npcs/healer.lua | 4 | ||||
-rw-r--r-- | example/scripts/npcs/merchant.lua | 10 | ||||
-rw-r--r-- | example/scripts/npcs/postman.lua | 12 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 77 |
9 files changed, 109 insertions, 112 deletions
diff --git a/example/scripts/maps/desert.lua b/example/scripts/maps/desert.lua index 1fee2fc..86f5c81 100644 --- a/example/scripts/maps/desert.lua +++ b/example/scripts/maps/desert.lua @@ -39,7 +39,7 @@ end) function Smith(npc, ch, list) local sword_count = chr_inv_count(ch, true, true, "Sword") if sword_count > 0 then - npc_message("Ah! I can see you already have a sword.") + say("Ah! I can see you already have a sword.") end Merchant(npc, ch, list) end @@ -54,7 +54,7 @@ function possessions_table(npc, ch) ..inventory_table[i].id..", "..inventory_table[i].name..", " ..inventory_table[i].amount end - npc_message(item_message) + say(item_message) item_message = "Equipment:".. "\nSlot id, item id, item name:".. @@ -64,7 +64,7 @@ function possessions_table(npc, ch) item_message = item_message.."\n"..equipment_table[i].slot..", " ..equipment_table[i].id..", "..equipment_table[i].name end - npc_message(item_message) + say(item_message) end @@ -74,21 +74,21 @@ function Harmony(npc, ch, list) being_apply_status(ch, 1, 99999) -- Say all the messages in the messages list. for i = 1, #list do - npc_message(list[i]) + say(list[i]) end --- Give the player 100 units of money the first time. if harmony_have_talked_to_someone == false then - npc_message("Here is some money for you to find some toys to play with.\nEh Eh!") + say("Here is some money for you to find some toys to play with.\nEh Eh!") chr_money_change(ch, 100) - npc_message(string.format("You now have %d shiny coins!", chr_money(ch))) + say(string.format("You now have %d shiny coins!", chr_money(ch))) harmony_have_talked_to_someone = true - npc_message(string.format("Try to come back with a better level than %i.", chr_get_level(ch))) + say(string.format("Try to come back with a better level than %i.", chr_get_level(ch))) else - npc_message("Let me see what you've got so far... Don't be afraid!") + say("Let me see what you've got so far... Don't be afraid!") effect_create(EMOTE_WINK, npc) possessions_table(npc, ch) end - npc_message("Have fun!") + say("Have fun!") effect_create(EMOTE_HAPPY, npc) -- Make Harmony disappear for a while... with a small earthquake effect! local shakeX = posX(npc) diff --git a/example/scripts/npcs/banker.lua b/example/scripts/npcs/banker.lua index 88ba9ac..4d5dda1 100644 --- a/example/scripts/npcs/banker.lua +++ b/example/scripts/npcs/banker.lua @@ -12,21 +12,21 @@ function Banker(npc, ch) if being_get_gender(ch) == GENDER_MALE then - npc_message("Welcome to the bank, sir!") + say("Welcome to the bank, sir!") elseif being_get_gender(ch) == GENDER_FEMALE then - npc_message("Welcome to the bank, madam!") + say("Welcome to the bank, madam!") else - npc_message("Welcome to the bank... uhm... person of unspecified gender!") + say("Welcome to the bank... uhm... person of unspecified gender!") end local account = tonumber(chr_get_quest(ch, "BankAccount")) local result = -1 if (account == nil) then --Initial account creation, if needed - npc_message("Hello! Would you like to setup a bank account? There is a sign-on bonus right now!") - result = npc_choice("Yes", "No") + say("Hello! Would you like to setup a bank account? There is a sign-on bonus right now!") + result = ask("Yes", "No") if (result == 1) then chr_set_quest(ch, "BankAccount", 5) - npc_message("Your account has been made. Your sign-on bonus is 5GP.") + say("Your account has been made. Your sign-on bonus is 5GP.") account = 5 end end @@ -37,41 +37,41 @@ function Banker(npc, ch) result = 1 while (result < 3) do --While they've choosen a valid option that isn't "Never mind" account = tonumber(chr_get_quest(ch, "BankAccount")) --Why do I need to convert this? - npc_message("Your balance: " .. account .. ".\nYour money: " .. chr_money(ch) .. ".") - result = npc_choice("Deposit", "Withdraw", "Never mind") + say("Your balance: " .. account .. ".\nYour money: " .. chr_money(ch) .. ".") + result = ask("Deposit", "Withdraw", "Never mind") if (result == 1) then --Deposit money = chr_money(ch); if (money > 0) then --Make sure they have money to deposit - npc_message("How much would you like to deposit? (0 will cancel)") - input = npc_ask_integer(0, money, 1) + say("How much would you like to deposit? (0 will cancel)") + input = ask_integer(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 chr_money_change(ch, -input) chr_set_quest(ch, "BankAccount", account + input) - npc_message(input .. " GP deposited.") + say(input .. " GP deposited.") elseif (input > money) then --Chosen more than they have - npc_message("You don't have that much money. But you just did....") + say("You don't have that much money. But you just did....") end else - npc_message("You don't have any money to deposit!") + say("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 - npc_message("How much would you like to withdraw? (0 will cancel)") - input = npc_ask_integer(0, account, 1) + say("How much would you like to withdraw? (0 will cancel)") + input = ask_integer(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 chr_money_change(ch, input) chr_set_quest(ch, "BankAccount", account - input) - npc_message(input .. " GP withdrawn.") + say(input .. " GP withdrawn.") elseif (input > account) then --Chosen more than they have - npc_message("You don't have that much in your account. But you just did....") + say("You don't have that much in your account. But you just did....") end else - npc_message("Your account is empty!") + say("Your account is empty!") end end end --This ends the while loop end - npc_message("Thank you. Come again!") + say("Thank you. Come again!") end diff --git a/example/scripts/npcs/barber.lua b/example/scripts/npcs/barber.lua index 58aa1a9..a616cd2 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 - npc_message("Hello! What style would you like today?") + say("Hello! What style would you like today?") elseif result == 2 then - npc_message("Hello! What color would you like today?") + say("Hello! What color would you like today?") else - npc_message("Hello! What can I do for you today?") + say("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 = npc_choice("Bald", styles, "Surprise me", "Never mind") + result = ask("Bald", styles, "Surprise me", "Never mind") result = result -1 @@ -113,7 +113,7 @@ function Barber(npc, ch, data) result = 3 end elseif (result == 2) then -- Do colors - result = npc_choice(colors, "Surprise me", "Never mind") + result = ask(colors, "Surprise me", "Never mind") --Random if (result == #colors + 1) then @@ -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 = npc_choice("Change my style", "Change my color", "Never mind") + result = ask("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 - npc_message("Thank you. Come again!") + say("Thank you. Come again!") end diff --git a/example/scripts/npcs/debugger.lua b/example/scripts/npcs/debugger.lua index e21982a..669964e 100644 --- a/example/scripts/npcs/debugger.lua +++ b/example/scripts/npcs/debugger.lua @@ -12,38 +12,38 @@ function npc1_talk(npc, ch) on_remove(ch, function() print "Player has left the map." end); - npc_message("Hello! I am the testing NPC.") + say("Hello! I am the testing NPC.") local rights = chr_get_rights(ch); if (rights >= 128) then - npc_message("Oh mighty server administrator, how can I avoid your wrath?") + say("Oh mighty server administrator, how can I avoid your wrath?") elseif (rights >= 8) then - npc_message("How can I be of assistance, sir gamemaster?") + say("How can I be of assistance, sir gamemaster?") elseif (rights >= 4) then - npc_message("What feature would you like to debug, developer?") + say("What feature would you like to debug, developer?") elseif (rights >= 2) then - npc_message("How can I assist you in your testing duties?") + say("How can I assist you in your testing duties?") elseif (rights >= 1) then - npc_message("What do you want, lowly player?") + say("What do you want, lowly player?") else - npc_message("...aren't you supposed to be banned??") + say("...aren't you supposed to be banned??") end - local v = npc_choice("Guns! Lots of guns!", - "A Christmas party!", - "To make a donation.", - "Slowly count from one to ten.", - "Tablepush Test") + local v = ask("Guns! Lots of guns!", + "A Christmas party!", + "To make a donation.", + "Slowly count from one to ten.", + "Tablepush Test") if v == 1 then - npc_message("Sorry, this is a heroic-fantasy game, I do not have any gun.") + say("Sorry, this is a heroic-fantasy game, I do not have any gun.") elseif v == 2 then local n1, n2 = chr_inv_count(ch, 524, 511) if n1 == 0 or n2 ~= 0 then - npc_message("Yeah right...") + say("Yeah right...") else - npc_message("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("Please do.", "No way! Fancy hats are classier.") + say("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 = ask("Please do.", "No way! Fancy hats are classier.") if v == 1 then chr_inv_change(ch, 524, -1, 511, 1) end @@ -51,14 +51,14 @@ function npc1_talk(npc, ch) elseif v == 3 then if chr_money_change(ch, -100) then - npc_message(string.format("Thank you for you patronage! You are left with %d GP.", chr_money(ch))) + say(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 chr_set_quest(ch, "001_donation", g) - npc_message(string.format("As of today, you have donated %d GP.", g)) + say(string.format("As of today, you have donated %d GP.", g)) else - npc_message("I would feel bad taking money from someone that poor.") + say("I would feel bad taking money from someone that poor.") end elseif v == 4 then @@ -95,6 +95,6 @@ function npc1_talk(npc, ch) print("---------------"); end - npc_message("See you later!") + say("See you later!") end diff --git a/example/scripts/npcs/emotemaker.lua b/example/scripts/npcs/emotemaker.lua index ee8928b..27abd45 100644 --- a/example/scripts/npcs/emotemaker.lua +++ b/example/scripts/npcs/emotemaker.lua @@ -21,10 +21,10 @@ function emote_talk(npc, ch) elseif emo_state == EMOTE_HAPPY then state = "happy" end - npc_message(string.format("The emotional palm seems %s.", state)) - v = npc_choice("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?") + say(string.format("The emotional palm seems %s.", state)) + v = ask("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?") if (v == 1) then emo_state = EMOTE_SAD diff --git a/example/scripts/npcs/healer.lua b/example/scripts/npcs/healer.lua index 910e221..2ee348f 100644 --- a/example/scripts/npcs/healer.lua +++ b/example/scripts/npcs/healer.lua @@ -5,8 +5,8 @@ --]] function Healer(npc, ch) - npc_message("Do you need healing?") - local c = npc_choice("Heal me fully", "Heal 100 HP", "Don't heal me") + say("Do you need healing?") + local c = ask("Heal me fully", "Heal 100 HP", "Don't heal me") if c == 1 then being_heal(ch) elseif c == 2 then diff --git a/example/scripts/npcs/merchant.lua b/example/scripts/npcs/merchant.lua index bcec5fa..185ce34 100644 --- a/example/scripts/npcs/merchant.lua +++ b/example/scripts/npcs/merchant.lua @@ -12,8 +12,6 @@ function Merchant(npc, ch, buy_sell_table) - local say = npc_message - -- Important note: You can add two tables made of trinoms here when calling the -- merchant function. E.g.: Merchant(npc, ch, buy_table, sell_table) -- Even though, the function here will see only one table: @@ -54,7 +52,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 = npc_choice(choice_table) + local v = ask(choice_table) --Debug and learning purpose --for i,k in ipairs(choice_table) do print(i,k) end @@ -65,7 +63,7 @@ function Merchant(npc, ch, buy_sell_table) if v == 1 then -- "To buy." - local buycase = npc_trade(false, buy_sell_table[1]) + local buycase = trade(false, buy_sell_table[1]) if buycase == 0 then say "What do you want to buy?" elseif buycase == 1 then @@ -78,7 +76,7 @@ function Merchant(npc, ch, buy_sell_table) if buy_sell_table[2] == nil then -- "To sell stuff..." - local sellcase = npc_trade(true) + local sellcase = trade(true) if sellcase == 0 then say "Ok, what do you want to sell?" elseif sellcase == 1 then @@ -88,7 +86,7 @@ function Merchant(npc, ch, buy_sell_table) end else -- "Can you make me a price for what I have?" - local sellcase = npc_trade(true, buy_sell_table[2]) + local sellcase = trade(true, buy_sell_table[2]) if sellcase == 0 then say "Here we go:" elseif sellcase == 1 then diff --git a/example/scripts/npcs/postman.lua b/example/scripts/npcs/postman.lua index c0901f8..7cb1163 100644 --- a/example/scripts/npcs/postman.lua +++ b/example/scripts/npcs/postman.lua @@ -11,17 +11,17 @@ ---------------------------------------------------------------------------------- function post_talk(npc, ch) - npc_message("Hello " .. being_get_name(ch)) + say("Hello " .. being_get_name(ch)) local strength = being_get_attribute(ch, ATTR_STRENGTH) - npc_message("You have " .. tostring(strength) .. " strength") - npc_message("What would you like to do?") - local answer = npc_choice("View Mail", "Send Mail", "Nothing") + say("You have " .. tostring(strength) .. " strength") + say("What would you like to do?") + local answer = ask("View Mail", "Send Mail", "Nothing") if answer == 1 then local sender, post = chr_get_post(ch) if sender == "" then - npc_message("No Post right now, sorry") + say("No Post right now, sorry") else - npc_message(tostring(sender) .. " sent you " .. tostring(post)) + say(tostring(sender) .. " sent you " .. tostring(post)) end end if answer == 2 then diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 37d1832..9048f7b 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -492,15 +492,15 @@ static int item_drop(lua_State *s) /** LUA_CATEGORY Input and output (input) */ -/** LUA npc_message (input) - * npc_message(string message) +/** LUA say (input) + * say(string message) ** * **Warning:** May only be called from an NPC talk function. * - * Shows an NPC dialog box on the screen of displaying the string ''msg''. + * Shows an NPC dialog box on the screen of displaying the string ''message''. * Idles the current thread until the user click "OK". */ -static int npc_message(lua_State *s) +static int say(lua_State *s) { const char *m = luaL_checkstring(s, 1); @@ -519,8 +519,8 @@ static int npc_message(lua_State *s) return lua_yield(s, 0); } -/** LUA npc_choice (input) - * npc_choice(item1, item2, ... itemN) +/** LUA ask (input) + * ask(item1, item2, ... itemN) ** * **Return value:** Number of the option the player selected (starting with 1). * @@ -532,10 +532,10 @@ static int npc_message(lua_State *s) * * Items are either strings or tables of strings (indices are ignored, * but presumed to be taken in order). So, - * ''npc_choice("A", {"B", "C", "D"}, "E")'' is the same as - * ''npc_choice("A", "B", "C", "D", "E")''. + * ''ask("A", {"B", "C", "D"}, "E")'' is the same as + * ''ask("A", "B", "C", "D", "E")''. */ -static int npc_choice(lua_State *s) +static int ask(lua_State *s) { Script::Thread *thread = checkCurrentThread(s); Entity *npc = thread->getContext().npc; @@ -562,8 +562,7 @@ static int npc_choice(lua_State *s) } else { - luaL_error(s, "npc_choice called " - "with incorrect parameters."); + luaL_error(s, "ask called with incorrect parameters."); return 0; } lua_pop(s, 1); @@ -571,7 +570,7 @@ static int npc_choice(lua_State *s) } else { - luaL_error(s, "npc_choice called with incorrect parameters."); + luaL_error(s, "ask called with incorrect parameters."); return 0; } } @@ -581,8 +580,8 @@ static int npc_choice(lua_State *s) return lua_yield(s, 0); } -/** LUA npc_ask_integer (input) - * npc_ask_integer(min_num, max_num, [default_num]) +/** LUA ask_number (input) + * ask_number(min_num, max_num, [default_num]) ** * **Return value:** The number the player entered into the field. * @@ -592,7 +591,7 @@ static int npc_choice(lua_State *s) * ''min_num'' and ''max_num''. If ''default_num'' is set this number will be * uses as default. Otherwise ''min_num'' will be the default. */ -static int npc_ask_integer(lua_State *s) +static int ask_number(lua_State *s) { int min = luaL_checkint(s, 1); int max = luaL_checkint(s, 2); @@ -615,8 +614,8 @@ static int npc_ask_integer(lua_State *s) return lua_yield(s, 0); } -/** LUA npc_ask_string (input) - * npc_ask_string() +/** LUA ask_string (input) + * ask_string() ** * **Return value:** The string the player entered. * @@ -624,7 +623,7 @@ static int npc_ask_integer(lua_State *s) * * Shows a dialog box to a user which allows him to enter a text. */ -static int npc_ask_string(lua_State *s) +static int ask_string(lua_State *s) { Script::Thread *thread = checkCurrentThread(s); Entity *npc = thread->getContext().npc; @@ -710,13 +709,13 @@ static int announce(lua_State *s) /** LUA_CATEGORY Inventory interaction (inventory) */ -/** LUA npc_trade (inventory) - * npc_trade(bool mode, - * {int item1id, int item1amount, int item1cost}, ..., - * {int itemNid, int itemNamount, int itemNcost}) - * npc_trade(bool mode, - * {string item1name, int item1amount, int item1cost}, ..., - * {string itemNname, int itemNamount, int itemNcost}) +/** LUA trade (inventory) + * trade(bool mode, + * { int item1id, int item1amount, int item1cost }, ..., + * { int itemNid, int itemNamount, int itemNcost }) + * trade(bool mode, + * { string item1name, int item1amount, int item1cost }, ..., + * { string itemNname, int itemNamount, int itemNcost }) ** * FIXME: Move into a seperate file * Opens a trade window from an NPC conversation. ''mode'' @@ -736,9 +735,9 @@ static int announce(lua_State *s) * * **2** in case of errors. * * **Examples:** - * <code lua npc_trade.lua> + * <code lua trade.lua> * -- "A buy sample." - * local buycase = npc_trade(false, { + * local buycase = trade(false, { * {"Sword", 10, 20}, * {"Bow", 10, 30}, * {"Dagger", 10, 50} @@ -755,7 +754,7 @@ static int announce(lua_State *s) * -- ... * * -- "Example: Let the player sell only pre-determined items." - * local sellcase = npc_trade(true, { + * local sellcase = trade(true, { * {"Sword", 10, 20}, * {"Bow", 10, 30}, * {"Dagger", 10, 200}, @@ -776,7 +775,7 @@ static int announce(lua_State *s) * * -- "Example: Let the player sell every item with a 'value' parameter in * the server's items.xml file - * local sellcase = npc_trade(true) + * local sellcase = trade(true) * if sellcase == 0 then * npc_message("Ok, what do you want to sell:") * elseif sellcase == 1 then @@ -787,7 +786,7 @@ static int announce(lua_State *s) * end * </code> */ -static int npc_trade(lua_State *s) +static int trade(lua_State *s) { const Script::Context *context = getScript(s)->getContext(); Entity *npc = context->npc; @@ -823,7 +822,7 @@ static int npc_trade(lua_State *s) } else { - raiseWarning(s, "npc_trade[Buy] called with invalid " + raiseWarning(s, "trade[Buy] called with invalid " "or empty items table parameter."); t->cancel(); lua_pushinteger(s, 2); @@ -838,7 +837,7 @@ static int npc_trade(lua_State *s) { if (!lua_istable(s, -1)) { - raiseWarning(s, "npc_trade called with invalid " + raiseWarning(s, "trade called with invalid " "or empty items table parameter."); t->cancel(); lua_pushinteger(s, 2); @@ -855,7 +854,7 @@ static int npc_trade(lua_State *s) if (!it) { - raiseWarning(s, "npc_trade called with incorrect " + raiseWarning(s, "trade called with incorrect " "item id or name."); t->cancel(); lua_pushinteger(s, 2); @@ -865,7 +864,7 @@ static int npc_trade(lua_State *s) } else if (!lua_isnumber(s, -1)) { - raiseWarning(s, "npc_trade called with incorrect parameters " + raiseWarning(s, "trade called with incorrect parameters " "in item table."); t->cancel(); lua_pushinteger(s, 2); @@ -3548,9 +3547,11 @@ LuaScript::LuaScript(): { "get_monster_class", &get_monster_class }, { "get_status_effect", &get_status_effect }, { "npc_create", &npc_create }, - { "npc_message", &npc_message }, - { "npc_choice", &npc_choice }, - { "npc_trade", &npc_trade }, + { "say", &say }, + { "ask", &ask }, + { "ask_number", &ask_number }, + { "ask_string", &ask_string }, + { "trade", &trade }, { "npc_post", &npc_post }, { "npc_enable", &npc_enable }, { "npc_disable", &npc_disable }, @@ -3639,8 +3640,6 @@ LuaScript::LuaScript(): { "map_get_pvp", &map_get_pvp }, { "item_drop", &item_drop }, { "item_get_name", &item_get_name }, - { "npc_ask_integer", &npc_ask_integer }, - { "npc_ask_string", &npc_ask_string }, { "log", &log }, { "get_distance", &get_distance }, { "map_get_objects", &map_get_objects }, |