diff options
author | David Athay <ko2fan@gmail.com> | 2008-11-06 16:19:54 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-11-06 16:19:54 +0000 |
commit | 40897abf694eadda6d32929d7263114bf00acc11 (patch) | |
tree | 4fb088602f860a334749a7bff61927bb3cef4cb2 | |
parent | 37a627f2e9d0de8d198f23cb363aacb1acf1f281 (diff) | |
download | manaserv-40897abf694eadda6d32929d7263114bf00acc11.tar.gz manaserv-40897abf694eadda6d32929d7263114bf00acc11.tar.bz2 manaserv-40897abf694eadda6d32929d7263114bf00acc11.tar.xz manaserv-40897abf694eadda6d32929d7263114bf00acc11.zip |
Forgot the data files, sorry
-rw-r--r-- | data/scripts/libs/libtmw.lua | 16 | ||||
-rw-r--r-- | data/scripts/test.lua | 7 |
2 files changed, 21 insertions, 2 deletions
diff --git a/data/scripts/libs/libtmw.lua b/data/scripts/libs/libtmw.lua index 4002a5af..4505d153 100644 --- a/data/scripts/libs/libtmw.lua +++ b/data/scripts/libs/libtmw.lua @@ -71,6 +71,14 @@ function do_choice(npc, ch, ...) return coroutine.yield(2) end +-- Sends an NPC request to send letter to a player and waits for them to +-- send the letter. +function do_post(npc, ch) + coroutine.yield(0) + tmw.npc_post(npc, ch) + return coroutine.yield(1) +end + -- Gets the value of a quest variable. -- Calling this function while an acknowledment is pending is desirable, so -- that lag cannot be perceived by the player. @@ -182,6 +190,14 @@ function npc_choose(npc, ch, u) end end +-- Called by the game when a player sends a letter. +function npc_post(npc, ch, sender, letter) + local w = states[ch] + if not (w and w[1] == npc and w[3] == 1 and process_npc(w, sender, letter)) then + states[ch] = nil + end +end + -- Called by the game whenever the value of a quest variable is known. -- Checks that the NPC expects it, and processes the respective coroutine. -- Note: the check for NPC correctness is missing, but it should never matter. diff --git a/data/scripts/test.lua b/data/scripts/test.lua index 70d21d76..1f7e12a6 100644 --- a/data/scripts/test.lua +++ b/data/scripts/test.lua @@ -213,8 +213,8 @@ function post_talk(npc, ch) do_message(npc, ch, "Hello " .. tmw.being_get_name(ch)) local strength = tmw.being_get_attribute(ch, ATTR_STRENGTH) do_message(npc, ch, "You have " .. tostring(strength) .. " strength") - do_message(npc, ch, "Would you like to see your mail?") - local answer = do_choice(npc, ch, "Yes", "No") + do_message(npc, ch, "What would you like to do?") + local answer = do_choice(npc, ch, "View Mail", "Send Mail", "Nothing") if answer == 1 then local sender, post = getpost(ch) if sender == "" then @@ -223,6 +223,9 @@ function post_talk(npc, ch) do_message(npc, ch, tostring(sender) .. " sent you " .. tostring(post)) end end + if answer == 2 then + do_post(npc, ch) + end end function fireworker_talk(npc, ch) |