Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  My first scripting attempt  (Read 10267 times)

0 Members and 0 Guests are viewing this topic.

Poidrac

« on: 03, March 2010, 10:23:57 »
Wonder if anyone wants to have a read through this and see how it is.

Since this is my first attempt, I'm pretty sure they'll be errors in there... but I'm looking forward to finding out how many :D

Code: [Select]
local npc = event.me
local player = event.activator


require("interface_builder")
local ib = InterfaceBuilder()

require("quest_builder")
local qb = QuestBuilder()

local function questGoal(questnr)

    if questnr == 1 then
        local target = qb:AddQuestTarget(1, 1, 1, "scythe_war",
                                         "Earthblight Scythe")
        target:AddQuestItem(1, "quest_object", "trash_wood2.101",
                        "premium wood")

    elseif questnr == 2 then
        local target = qb:AddQuestTarget (1, 1, 1 "wyvern",
                                         "Garuda")
        target:AddQuestItem(1, "quest_object", "ornament_d",
                        "Air Essence")
    end
end

local function questReward(questnr)

    if questnr == 1 then
        player:AddMoney(0, 0, 5, 0)
    elseif questnr == 2 then
        get key()
    end
end

local function give_key()
    local key

    for obj in obj_inventory(player) do
        if obj.type == game.TYPE_SPECIAL_KEY and
           obj.slaying == "AirEssence" then
            key = obj

            break
        end
    end

    if not key then
        key = player:CreateObjectInside("ornament_d", game.IDENTIFIED)

        assert(key, "Could not create key!")
        key.name = Essence
        key.title = "of Air"
        key.slaying = "AirEssence"
        player:Write(npc.name .. " chants a little and then hands the essence back to you.")
        player:Write("She says: You'll need this in the future, don't lose it.")
    end
end

qb:AddQuest("Dreambow's New Bow", game.QUEST_KILLITEM, nil, nil, nil, nil, 1,
            questGoal, questReward)
qb:AddQuest("The Garuda", game.QUEST_KILLITEM, nil, nil, nil, nil, 1,
            questGoal, questReward)

local questnr = qb:Build(player)

local function topic_default()
    ib:SetTitle("What?")
    ib:SetMsg("I'm sorry. I didn't understand.\n")
end

local function topic_greeting()
    ib:SetHeader("st_001", npc)
   
    if questnr == 1 and
       qb:GetStatus(1) == game.QSTAT_NO then
        ib:SetTitle("Morning")
        ib:SetMsg("Good morning to you, welcome to the Archery Hall.  I am " ..
                  npc:GetName() .. ".\n")
        ib:AddMsg("\nAh, so, you're the strange foreigner I've been hearing about.\n")
        ib:AddMsg("\nNo, don't worry, nothing goes on in this town that I " ..
                  "don't hear about, I'm sort of the unofficial leader of " ..
                  "this Domain\n")
        ib:AddMsg("\nI do actually have a favor to ask of you.")
        ib:SetLHSButton("Quest")
    elseif questnr == 2 and
        qb:GetStatus(1) == game.QSTAT_NO then
         ib:SetTitle("Morning")
         ib:SetMsg("Oh thank you for the wood.\n")
         ib:AddMsg("\nAs you can see, my new bow is coming along nicely, " ..
                   "this one might even end up being more powerful than " ..
                   "my origial.\n"
         ib:AddMsg("|** " .. npc.name .. " looks you up and down **|\n")
         ib:AddMsg("There is something else I'd like you to do, if you feel " ..
                   "up to the challenge.\n")
         ib:SetLHSButton("Quest")
    else
        ib:SetMsg("Welcome back, I trust you are well?")
            if questnr ~= 0 then
                if qb:GetStatus(questnr) == game.QSTAT_NO then
                    ib:AddMsg("\nJust let me know when you're ready for your " ..
                              "next ^quest^.")
                    ib:SetLHSButton("Quest")
                elseif qb:GetStatus(questnr) == game.QSTAT_ACTIVE or
                       qb:GetStatus(questnr) == game.QSTAT_SOLVED then
                    ib:AddMsg("\nHow's progress on that ^quest^?")
                    ib:AddLink("Easy, here you go.", "quest complete")
                    ib:AddLink("How the heck do I finish this quest!",
                           "quest incomplete")
                end
            else
                if player:GetQuest("Earthbound Fury") == nil then
                    ib:AddMsg("\nYou did well for me, up for your next challenge?\n")
                    ib:AddMsg("\nMy sister, Mari Mysticblade is to the north of town " ..
                              "she's already been told of your arrival, and she'll " ..
                              "have a job for you.\n")
                else
                    if player:GetQuest("Living Flame") == nil then
                        ib:AddMsg("\nNice work with the Earthbound Fury.\n")
                        ib:AddMsg("\nI'll let you in on a little secret, that was the " ..
                                  "easiest of the four demon servants when they first " ..
                                  "appeared some years ago.  I didn't want to lose my " ..
                                  "sister, so I sent her after it.\n")
                        ib:AddMsg("\nBut that's neither here nor there now.\n")
                        ib:AddMsg("\nSara Nobles, the local garrison commander is your " ..
                                  "next point of call.  She already knows you are coming.\n")
                    else
                        if player:GetQuest("Embodyment of Water") == nil then
                            ib:AddMsg("\nCongratulations on your victory\n"
                            ib:AddMsg("\nSara Nobles has been a long time companion to me " ..
                                      "and Aurora Okiri over the years.  We've held back the " ..
                                      "demon for so long now.\n")
                            ib:AddMsg("\nHow long, you ask? Well, if I said I was pushing " ..
                                      "almost 750 years of age, would you believe me?\n")
                            ib:AddMsg("\nAnyway, Aurora Okiri in the castle has your next " ..
                                      "assignment.\n"
                            ib:AddMsg("\nOh, and be VERY respectful, you don't want to get " ..
                                      "on the bad side of her or her husband.|n")
                        else
                            if player:GetQuest("Tamo") == nil then
                                ib:AddMsg("\nYou have all four essences? Excellent.\n")
                                ib:AddMsg("\nOur cursed leader, the Poison Dragon, at the back " ..
                                          "of the castle has your final quest.\n")
                                ib:AddMsg("\nDon't be alarmed by his appearance.\n")
                                ib:AddMsg("\nEver since he rendered the demon inert, he's been " ..
                                          "trapped in that form.\n")
                                ib:AddMsg("\nHe's much more gentle than his appearance projects.\n")
                            else
                                ib:AddMsg("\nThank you for all your work.  This town is doomed to " ..
                                          "remain cursed until the end of days.\n")
                                ib:AddMsg("\nBut I will stay by it's side until that time.\n"
                                ib:AddMsg("\nI just wish that one day, I could find my happiness.\n")
                            end
                            ib:AddMsg(\n"Have fun in all you do.")
                        end
                    end
                end
            end
    end
end

local function topic_quest()
    ib:SetHeader("st_003", npc)

    if questnr == 0 then
        ib:SetMsg("\nNice to see you again\n")
        ib:AddMsg("\nAs you can see, all is well in the Dragon Domain\n")

    else
        ib:SetTitle(qb:GetName(questnr))

        if questnr == 1 then
            ib:SetMsg("Yes.\n")
            ib:AddMsg("\nAs you have probably seen on the shrine outside, " ..
                      "My original bow cannot be used.\n")
            ib:AddMsg("\nIn addition, my last 10 bows have all been made " ..
                      "of less than desirable materials.\n"
            ib:AddMsg("\nWhat I would really need to craft a bow of similar " ..
                      "power to that of my original would be some Premium " ..
                      "Wood.\n")
            ib:AddMsg("\nHowever, the only other batch of this wood was " ..
                      "used to craft an Enchanted Scythe.\n")
            ib:AddMsg("\nUnfortunately, the magical properties of this " ..
                      "scythe were so powerful, it took on a life of it's " ..
                      "own and used it's power to animate the other weapons " ..
                      "in the storage chamber below.\n")
            ib:AddMsg("\nCan you please go and destroy this scythe and " ..
                      "return with it's shaft?\n")
            ib:AddMsg("\nThat will be enough to help me craft my bow.\n")
        elseif questnr == 2 then
            ib:SetMsg("This one will be a bit trickier.\n")
            ib:AddMsg("\nI'll start with a little history lesson.\n")
            ib:AddMsg("\nDon't groan like that.\n")
            ib:AddMsg("\nBack when I and my companions rendered the demon " ..
                      "inert, we had to claim the essence of 4 elementals " ..
                      "to perform the sealing.\n")
            ib:AddMsg("\nThe seal has worn away a lot over the past couple " ..
                      "of years for reasons unknown to us.\n")
            ib:AddMsg("\nI'd like you to claim victory over these elementals " ..
                      "and return with their essence so that we may fortify " ..
                      "the seal.\n")
            ib:AddMsg("\nAre you willing to help us?\n")
        end

        if qb:GetStatus(questnr) == game.QSTAT_NO then
            ib:SetAccept("Accept", "accept quest")
        end
    end
end

local function topic_questAccept()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_NO then
        ib:SetMsg("Don't go too fast.  Nothing good comes from rushing " ..
                  "ahead.")

    else
        ib:SetTitle(qb:GetName(questnr))

        if questnr == 1 then
            ib:SetMsg("Excellent.\n")
            ib:AddMsg("\nThe weapon storage is down the stairs next to me.\n")
            ib:AddMsg("\nYou will need a key however, I think I gave it to " ..
                      "the barkeep, DJ Bagnpux.\n")
            ib:AddMsg("\nSee him first about getting the key.\n")
        elseif questnr == 2 then
            ib:SetMsg("Thank you in Advance.\n")
            ib:AddMsg("\nThe Garuda makes its nest on the Sky Platform.\n")
            ib:AddMsg("\nThe rope leading up to it is just to the east of " ..
                      "town.\n")
            ib:AddMsg("\nBe careful up there.\n")
        end
    end
end

local function topic_questDecline()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_NO then
        ib:SetMsg("Don't go too fast.  Nothing good comes from rushing " ..
                  "ahead.")
    else
        ib:SetMsg("That's a shame. Oh well, your choice.\n")
        ib:AddMsg("\nIf you feel the want to give it a go though, look " ..
                  "me up\n")
    end
end

local function topic_questComplete()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_SOLVED then
        ib:SetMsg("|** " .. npc.name .. " looks you up and down **|\n")

        if qb:GetStatus(questnr) == game.QSTAT_NO then
            ib:AddMsg("\nThat's quite an achievement, as I have " ..
                      "yet to give you the ^quest^.")

        elseif qb:GetStatus(questnr) == game.QSTAT_ACTIVE then
            ib:AddMsg("\n")
            qb:AddItemList(questnr, ib)
            ib:AddMsg("\nDon't give me that... I know you haven't finished " ..
                      "yet.\n")
        end
    else
        if questnr == 1 then
            ib:SetMsg("Thank you, this enchanted wood is just what I need.\n")
            ib:AddMsg("You look like you want a reward for doing this...\n")
            ib:AddMsg("Just teasing, here you go.\n")
            ib:AddMsg("\n|** " .. npc.name .. " gives you 5 gold. **|\n")
            ib:SetCoins(0, 0, 5, 0)
            qb:Finish(1, "5 gold coins")

        elseif questnr ==2 then
            ib:SetMsg("Nice going.\n")
            ib:AddMsg("There's quite a bit of essence here.  Give me a moment.\n")
            ib:AddIcon("Essence of Air", "ornament_d", "")
            qb:Finish(2, "Essence of Air")
        end

        if questnr ~= 0 then
            if qb:GetQuestNr() > questnr and
               qb:GetStatus(questnr + 1) == game.QSTAT_NO then
                ib:SetLHSButton("Quest")
            elseif qb:GetQuestNr() == questnr then
                ib:SetLHSButton("What now?")
            end
        end
    end
end

local function topic_questIncomplete()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_ACTIVE then
        ib:SetMsg("|** " .. npc.name .. " looks at you intently **|\n")

        if qb:GetStatus(questnr) == game.QSTAT_NO then
            ib:AddMsg("\nThat's quite an achievement, as I have " ..
                      "yet to give you the ^quest^.")

        elseif qb:GetStatus(questnr) == game.QSTAT_SOLVED then
            ib:SetTitle(qb:GetName(questnr))
            ib:AddMsg("\n")
            qb:AddItemList(questnr, ib)
            ib:AddMsg("\nI already know you're lying... Do you want " ..
                      "to rethink your answer?\n")
        end
    else
        ib:SetTitle(qb:GetName(questnr))
        ib:SetMsg("Good job I'm a patient person.  Get out of here.")
    end
end

local function topic_rumours()
    ib:SetHeader("st_004", npc)
    ib:SetMsg("~TODO~")
end

local function topic_services()
    ib:SetHeader("st_005", npc)
    ib:SetMsg("~TODO~")
end

require("topic_list")

local tl = TopicList()

tl:SetDefault(topic_default)
tl:AddGreeting("what now%??", topic_greeting)
tl:AddBackground(nil, topic_background)
tl:AddQuest(nil, topic_quest)
tl:AddTopics("accept quest", topic_questAccept)
tl:AddTopics("decline quest", topic_questDecline)
tl:AddTopics("quest complete", topic_questComplete)
tl:AddTopics("quest incomplete", topic_questIncomplete)
tl:AddRumours(nil, topic_rumours)
tl:AddServices(nil, topic_services)
ib:ShowSENTInce(game.GUI_NPC_MODE_NPC, tl:CheckMessage(event, true))

another question, I have is this.  I want an NPC to not offer a quest until the ones before it are complete.  I placed it in a script like this:

Code: [Select]
local function topic_greeting()
    ib:SetHeader("st_001", npc)

    if qb:GetStatus("The Garuda") == game.QSTAT_NO or
       qb:GetStatus("The Garuda") == game.QSTAT_ACTIVE or
       qb:GetStatus("Earthbound Fury") == game.QSTAT_NO or
       qb:GetStatus("Earthbound Fury") == game.QSTAT_ACTIVE then
        ib:SetMsg("Who are you?.\n")
        ib:AddMsg("\nGreat, another traveller.  I suggest you go see " ..
                  "Mari Dreambow in the Archery Hall.\n")
    elseif questnr == 1 and
       qb:GetStatus("The Garuda") == game.QSTAT_SOLVED and
       qb:GetStatus("Earthbound Fury") == game.QSTAT_SOLVED then
        ib:SetMsg("So, you're this sudden star.\n")
        ib:AddMsg("\nI've already been told you were coming and why\n")
        ib:AddMsg("\nMy elemental is fire based.\n")
        ib:AddMsg("\nYou think you're ready to face my challenge?\n")
        ib:SetLHSButton("Quest")
    else
        ib:SetMsg("What is it this time?.\n")
    end
end

would this be the best way, or even the right way at all...

Finally... if I was wanting to add a special quest reward body armour, how would be the best way to go about that be? I've looked at Cashin's quest, but it doesn't quite say what I want, mainly what sort of keywords I'd need for it to be classed as body armour or how to add addition stats.

Help on these issues would be greatly appreciated.

Happy reading.  ^-^
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

smacky

« Reply #1 on: 03, March 2010, 14:41:18 »
Code: [Select]
local function questGoal(questnr)

    if questnr == 1 then
        local target = qb:AddQuestTarget(1, 1, 1, "scythe_war",
                                         "Earthblight Scythe")
        target:AddQuestItem(1, "quest_object", "trash_wood2.101",
                        "premium wood")

    elseif questnr == 2 then
        local target = qb:AddQuestTarget (1, 1, 1 "wyvern",
                                         "Garuda")
        target:AddQuestItem(1, "quest_object", "ornament_d",
                        "Air Essence")
    end
end

The first argument of qb:AddQuestTarget() and qb:AddQuestItem() is questnr.

Also, I'm not clear what you're doing for questnr = 1. ...Target is for mobs and ...Item for, well, items (this naming is just to stick with what was already there). Also note that the second argument of ...Item is a number (nrof).

Quote
Code: [Select]
local function questReward(questnr)

    if questnr == 1 then
        player:AddMoney(0, 0, 5, 0)
    elseif questnr == 2 then
        get key()
    end
end

get key() is not a valid identifier. I assume you mean give_key().

Quote
Code: [Select]
local function give_key()
    ...
    key.name = Essence

Need quotes (it's a string).

I've not looked at the ib and tl stuff as that is pretty basic and generic if you follow the logical layout in the Guildhall scripts (I will cover this in more detail when I do a Daipedia tutorial).

Quote
another question, I have is this.  I want an NPC to not offer a quest until the ones before it are complete.

This is in fact how qb has to work. So you need do nothing extra. :)

Quote
Finally... if I was wanting to add a special quest reward body armour, how would be the best way to go about that be? I've looked at Cashin's quest, but it doesn't quite say what I want, mainly what sort of keywords I'd need for it to be classed as body armour or how to add addition stats.

I'll get back to you on this.

Poidrac

« Reply #2 on: 03, March 2010, 16:10:08 »
Quote
get key() is not a valid identifier. I assume you mean give_key().
Quote
Need quotes (it's a string).

oops, thanks for that...  :oops:


Quote
This is in fact how qb has to work. So you need do nothing extra.

Is this meaning that what I put down was right...?  :o


you know... I was expecting more errors than that... ::)
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

smacky

« Reply #3 on: 03, March 2010, 17:12:40 »
Quote
This is in fact how qb has to work. So you need do nothing extra.

Is this meaning that what I put down was right...?  :o

Meaning I didn't even read your code as, assuming it just was to do what you asked about, it is unnecessary jumping through hoops as this is the way qb works automatically. So you don't need it. Rule of thumb: if in doubt, just assume the utility scripts (ib, qb, tl, etc) will do the sensible, right thing. ;)

Quote
you know... I was expecting more errors than that... ::)

Well the utility scripts are designed to just work out of the box, even for novice scripters, and the example scripts (cashin and fanrir ATM) are written and commented so that they can just be used as templates, with just the words and quest details changed. This is one of the major points of SENTInce, to make (quest) scripting  accessible to all mappers.

OTOH, play it on a local server before you're too relieved at lack of errors. :)

smacky

« Reply #4 on: 03, March 2010, 18:37:12 »
Finally... if I was wanting to add a special quest reward body armour, how would be the best way to go about that be? I've looked at Cashin's quest, but it doesn't quite say what I want, mainly what sort of keywords I'd need for it to be classed as body armour or how to add addition stats.

Keywords? You mean for tl? Ie, what the player types in?

Well the rule is to keep it simple. IOW if it's just body armour maybe have it recognise the words 'body', 'armour, and 'body armour' as synonyms. Also, be sure to account for the incorrect 'Merkan spelling of 'armor'.  So this gives 5 synonyms for this topic, which you would script as:

Code: [Select]
tl:AddTopics({ "body", "armou?r", "body armou?r" }, topic_foo)

See SENTInce style guide 7 for details (note the style guide is due for a bit of a tidy up).

To give your special armour boni, etc. you need to adjust its attributes. Of course it depends on exactly what you want, but say you want to give it some resistances and stat bonuses, try for example:
Code: [Select]
armour.resist_fire = 50 -- +50% fire resist to wearer
armour.strength = 3 -- +3 strength to wearer
« Last Edit: 03, March 2010, 18:39:18 by smacky »

Poidrac

« Reply #5 on: 06, March 2010, 14:21:56 »
Okay, I've been testing the maps now... so far so good... amazed myself at some of the silly things I've missed.  But what the hey :)

One thing is bothering me though.
I try to talk to one of the quest giving characters, but I'm not getting a response out of them.

The path of the talk event is correct.
However, I just can't coax an answer out of her.

/planes/Dragon_Domain/scripts/dreambow3.lua is the path I am using, which works, since it does take me to the script that I want in gridarta.

All I can guess, is that I'm missing something somewhere, but I can't figure out where.
Code: [Select]
local npc = event.me
local player = event.activator

local function give_key()
    local key

    for obj in obj_inventory(player) do
        if obj.type == game.TYPE_SPECIAL_KEY and
           obj.slaying == "AirEssence" then
            key = obj

            break
        end
    end

    if not key then
        key = player:CreateObjectInside("ornament_d", game.IDENTIFIED)

        assert(key, "Could not create key!")
        key.name = "Essence"
        key.title = "of Air"
        key.slaying = "AirEssence"
        player:Write(npc.name .. " chants a little and then hands the essence back to you.")
        player:Write("She says: You'll need this in the future, don't lose it.")
    end
end

require("interface_builder")

local ib = InterfaceBuilder()

require("quest_builder")

local qb = QuestBuilder()

local function questGoal(questnr)

    if questnr == 1 then
        local target = qb:AddQuestTarget(1, 1, 1, "scythe_war",
                                         "Earthblight Scythe")
        target:AddQuestItem(1, "quest_object", "trash_wood2.101",
                        "premium wood")

    elseif questnr == 2 then
        local target = qb:AddQuestTarget (2, 1, 1 "wyvern",
                                         "Garuda")
        target:AddQuestItem(2, "quest_object", "ornament_d",
                        "Air Essence")
    end
end

local function questReward(questnr)

    if questnr == 1 then
        player:AddMoney(0, 0, 5, 0)
    elseif questnr == 2 then
        give_key()
    end
end

qb:AddQuest("Dreambow's New Bow", game.QUEST_KILLITEM, nil, nil, nil, nil, 1,
            questGoal, questReward)
qb:AddQuest("The Garuda", game.QUEST_KILLITEM, nil, nil, nil, nil, 1,
            questGoal, questReward)

local questnr = qb:Build(player)

local function topic_default()
    ib:SetTitle("What?")
    ib:SetMsg("I'm sorry. I didn't understand.\n")
end

local function topic_greeting()
    ib:SetHeader("st_001", npc)

    if questnr == 1 and
       qb:GetStatus(1) == game.QSTAT_NO then
        ib:SetTitle("Morning")
        ib:SetMsg("Good morning to you, welcome to the Archery Hall.  I am " ..
                  npc:GetName() .. ".\n")
        ib:AddMsg("\nAh, so, you're the strange foreigner I've been hearing about.\n")
        ib:AddMsg("\nNo, don't worry, nothing goes on in this town that I " ..
                  "don't hear about, I'm sort of the unofficial leader of " ..
                  "this Domain\n")
        ib:AddMsg("\nI do actually have a favor to ask of you.")
        ib:SetLHSButton("Quest")

    else
        ib:SetMsg("Welcome Back, I trust you are well?")
        if questnr ~= 0 then
            if qb:GetStatus(questnr) == game.QSTAT_NO then
                ib:AddMsg("Oh thank you for the wood.\n")
                ib:AddMsg("\nAs you can see, my new bow is coming along nicely, " ..
                          "this one might even end up being more powerful than " ..
                          "my origial.\n"
                ib:AddMsg("|** " .. npc.name .. " looks you up and down **|\n")
                ib:AddMsg("\nThere is something else I'd like you to do, if you feel " ..
                          "up to the challenge.\n")
                ib:SetLHSButton("Quest")111
            elseif qb:GetStatus(questnr) == game.QSTAT_ACTIVE or
                   qb:GetStatus(questnr) == game.QSTAT_SOLVED then
                    ib:AddMsg("\nHow's progress on that ^quest^?")
                    ib:AddLink("I've done what you asked.", "quest complete")
                    ib:AddLink("Slow. But I'm working on it.",
                           "quest incomplete")
            end

        else

            if player:GetQuest("Earthbound Fury") == nil then
                ib:AddMsg("\nYou did well for me, up for your next challenge?\n")
                ib:AddMsg("\nMy sister, Mari Mysticblade is to the north of town " ..
                          "she's already been told of your arrival, and she'll " ..
                          "have a job for you.\n")
            else
                if player:GetQuest("Living Flame") == nil then
                    ib:AddMsg("\nNice work with the Earthbound Fury.\n")
                    ib:AddMsg("\nI'll let you in on a little secret, that was the " ..
                              "easiest of the four demon servants when they first " ..
                              "appeared some years ago.  I didn't want to lose my " ..
                              "sister, so I sent her after it.\n")
                    ib:AddMsg("\nBut that's neither here nor there now.\n")
                    ib:AddMsg("\nSara Nobles, the local garrison commander is your " ..
                              "next point of call.  She already knows you are coming.\n")
                else
                    if player:GetQuest("Embodyment of Water") == nil then
                        ib:AddMsg("\nCongratulations on your victory\n"
                        ib:AddMsg("\nSara Nobles has been a long time companion to me " ..
                                  "and Aurora Okiri over the years.  We've held back the " ..
                                  "demon for so long now.\n")
                        ib:AddMsg("\nHow long, you ask? Well, if I said I was pushing " ..
                                  "almost 750 years of age, would you believe me?\n")
                        ib:AddMsg("\nAnyway, Aurora Okiri in the castle has your next " ..
                                  "assignment.\n"
                        ib:AddMsg("\nOh, and be VERY respectful, you don't want to get " ..
                                  "on the bad side of her or her husband.|n")
                    else
                        if player:GetQuest("Tamo") == nil then
                            ib:AddMsg("\nYou have all four essences? Excellent.\n")
                            ib:AddMsg("\nOur cursed leader, the Poison Dragon, at the back " ..
                                      "of the castle has your final quest.\n")
                            ib:AddMsg("\nDon't be alarmed by his appearance.\n")
                            ib:AddMsg("\nEver since he rendered the demon inert, he's been " ..
                                      "trapped in that form.\n")
                            ib:AddMsg("\nHe's much more gentle than his appearance projects.\n")
                        else
                            ib:AddMsg("\nThank you for all your work.  This town is doomed to " ..
                                      "remain cursed until the end of days.\n")
                            ib:AddMsg("\nBut I will stay by it's side until that time.\n"
                            ib:AddMsg("\nI just wish that one day, I could find my happiness.\n")
                        end
                        ib:AddMsg(\n"Have fun in all you do.")
                    end
                end
            end
        end
    end
end

local function topic_background()
    ib:SetHeader("st_002", npc)
    ib:SetMsg("~TODO~")
end

local function topic_quest()
    ib:SetHeader("st_003", npc)

    if questnr == 0 then
        ib:SetMsg("\nNice to see you again\n")
        ib:AddMsg("\nAs you can see, all is well in the Dragon Domain\n")

    elseif questnr < 0 then
        ib:SetMsg("I have nothing for you at the moment.")

    else
        ib:SetTitle(qb:GetName(questnr))

        if questnr == 1 then
            ib:SetMsg("Yes.\n")
            ib:AddMsg("\nAs you have probably seen on the shrine outside, " ..
                      "My original bow cannot be used.\n")
            ib:AddMsg("\nIn addition, my last 10 bows have all been made " ..
                      "of less than desirable materials.\n"
            ib:AddMsg("\nWhat I would really need to craft a bow of similar " ..
                      "power to that of my original would be some Premium " ..
                      "Wood.\n")
            ib:AddMsg("\nHowever, the only other batch of this wood was " ..
                      "used to craft an Enchanted Scythe.\n")
            ib:AddMsg("\nUnfortunately, the magical properties of this " ..
                      "scythe were so powerful, it took on a life of it's " ..
                      "own and used it's power to animate the other weapons " ..
                      "in the storage chamber below.\n")
            ib:AddMsg("\nCan you please go and destroy this scythe and " ..
                      "return with it's shaft?\n")
            ib:AddMsg("\nThat will be enough to help me craft my bow.\n")

        elseif questnr == 2 then
            ib:SetMsg("This one will be a bit trickier.\n")
            ib:AddMsg("\nI'll start with a little history lesson.\n")
            ib:AddMsg("\nDon't groan like that.\n")
            ib:AddMsg("\nBack when I and my companions rendered the demon " ..
                      "inert, we had to claim the essence of 4 elementals " ..
                      "to perform the sealing.\n")
            ib:AddMsg("\nThe seal has worn away a lot over the past couple " ..
                      "of years for reasons unknown to us.\n")
            ib:AddMsg("\nI'd like you to claim victory over these elementals " ..
                      "and return with their essence so that we may fortify " ..
                      "the seal.\n")
            ib:AddMsg("\nAre you willing to help us?\n")

        end

        if qb:GetStatus(questnr) == game.QSTAT_NO then
            ib:SetAccept("Accept", "accept quest")
        end
    end
end

local function topic_questAccept()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_NO then
        ib:SetMsg("Don't go too fast.  Nothing good comes from rushing " ..
                  "ahead.")

    else
        ib:SetTitle(qb:GetName(questnr))

        if questnr == 1 then
            ib:SetMsg("Excellent.\n")
            ib:AddMsg("\nThe weapon storage is down the stairs next to me.\n")
            ib:AddMsg("\nYou will need a key however, I think I gave it to " ..
                      "the barkeep, DJ Bagnpux.\n")
            ib:AddMsg("\nSee him first about getting the key.\n")

        elseif questnr == 2 then
            ib:SetMsg("Thank you in Advance.\n")
            ib:AddMsg("\nThe Garuda makes its nest on the Sky Platform.\n")
            ib:AddMsg("\nThe rope leading up to it is just to the east of " ..
                      "town.\n")
            ib:AddMsg("\nBe careful up there.\n")
        end
    end
end

local function topic_questDecline()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_NO then
        ib:SetMsg("Don't go too fast.  Nothing good comes from rushing " ..
                  "ahead.")
    else
        ib:SetMsg("That's a shame. Oh well, your choice.\n")
        ib:AddMsg("\nIf you feel the want to give it a go though, look " ..
                  "me up\n")
    end
end

local function topic_questComplete()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_SOLVED then
        ib:SetMsg("|** " .. npc.name .. " looks you up and down **|\n")

        if qb:GetStatus(questnr) == game.QSTAT_NO then
            ib:AddMsg("\nThat's quite an achievement, as I have " ..
                      "yet to give you the ^quest^.")

        elseif qb:GetStatus(questnr) == game.QSTAT_ACTIVE then
            ib:AddMsg("\n")
            qb:AddItemList(questnr, ib)
            ib:AddMsg("\nDon't give me that... I know you haven't finished " ..
                      "yet.\n")
        end

    else
        if questnr == 1 then
            ib:SetMsg("Thank you, this enchanted wood is just what I need.\n")
            ib:AddMsg("You look like you want a reward for doing this...\n")
            ib:AddMsg("Just teasing, here you go.\n")
            ib:AddMsg("\n|** " .. npc.name .. " gives you 5 gold. **|\n")
            ib:SetCoins(0, 0, 5, 0)
            qb:Finish(1, "5 gold coins")

        elseif questnr ==2 then
            ib:SetMsg("Nice going.\n")
            ib:AddMsg("There's quite a bit of essence here.  Give me a moment.\n")
            ib:AddIcon("Essence of Air", "ornament_d", "")
            qb:Finish(2, "Essence of Air")
        end

        if questnr ~= 0 then
            if qb:GetQuestNr() > questnr and
               qb:GetStatus(questnr + 1) == game.QSTAT_NO then
                ib:SetLHSButton("Quest")
            elseif qb:GetQuestNr() == questnr then
                ib:SetLHSButton("What now?")
            end
        end
    end
end

local function topic_questIncomplete()
    ib:SetHeader("st_003", npc)

    if questnr <= 0 then
        return topic_quest()
    end

    if qb:GetStatus(questnr) ~= game.QSTAT_ACTIVE then
        ib:SetMsg("|** " .. npc.name .. " looks at you intently **|\n")

        if qb:GetStatus(questnr) == game.QSTAT_NO then
            ib:AddMsg("\nThat's quite an achievement, as I have " ..
                      "yet to give you the ^quest^.")
        elseif qb:GetStatus(questnr) == game.QSTAT_SOLVED then
            ib:SetTitle(qb:GetName(questnr))
            ib:AddMsg("\n")
            qb:AddItemList(questnr, ib)
            ib:AddMsg("\nI already know you're lying... Do you want " ..
                      "to rethink your answer?\n")
        end
    else
        ib:SetTitle(qb:GetName(questnr))
        ib:SetMsg("Good job I'm a patient person.  Get out of here.")
    end
end

local function topic_rumours()
    ib:SetHeader("st_004", npc)
    ib:SetMsg("~TODO~")
end

local function topic_services()
    ib:SetHeader("st_005", npc)
    ib:SetMsg("~TODO~")
end


require("topic_list")

local tl = TopicList()

tl:SetDefault(topic_default)
tl:AddGreeting("what now%??", topic_greeting)
tl:AddBackground(nil, topic_background)
tl:AddQuest(nil, topic_quest)
tl:AddTopics("accept quest", topic_questAccept)
tl:AddTopics("decline quest", topic_questDecline)
tl:AddTopics("quest complete", topic_questComplete)
tl:AddTopics("quest incomplete", topic_questIncomplete)
tl:AddRumours(nil, topic_rumours)
tl:AddServices(nil, topic_services)
ib:ShowSENTInce(game.GUI_NPC_MODE_NPC, tl:CheckMessage(event, true))

Can anyone help here?
*oh, and Smacky, please ignore that quest bit about the war scythe, working on that at the moment. (it is actually right ;D)
« Last Edit: 06, March 2010, 14:23:54 by Poidrac »
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

smacky

« Reply #6 on: 06, March 2010, 15:32:40 »
Quote
/planes/Dragon_Domain/scripts/dreambow3.lua is the path I am using

It is a lot better and easier for everyone if you put all your maps and scripts in your own unofficial directory (ie, /unofficial/poidrac). Within there you can set up any substructure you like.

Obviously ATM you are free to do as you please, but when you're a MW you only have access to your own unofficial dirs, so it saves you effort later if you get in the habit now.

Well you need to check the server log. This will likely have useful info about why (if) the script failed. Also, try running the script (ie, say hello to the NPC) when you are in MM mode as this will print out some error info in the message textwindow in the client (but this info and more always appears iin the server log too so on a local server this is just a convenience).

For example, in my experience 99 times out of 100 when scripts don't work it is just some stupid typo (wrong capitalisation, misplaced comma, etc). This will be noted in the above sources.

Also, you have:
Code: [Select]
tl:AddGreeting("what now%??", topic_greeting)

You probably want to get rid of that string in the trigger argument (just use nil). That's a special case for Fanrir. tl:AddGreeting(), ...Background, ...Quest, ...Rumours, and ...Services always add the default standard topic triggers. So nil means just use the defaults.

Poidrac

« Reply #7 on: 06, March 2010, 20:12:21 »
back again...

okay, did as you said, Smacky, however, I'm not actually getting any error info...
All that happens is that the panel doesn't come up.

What I'm guessing that means is that there's a pathing issue.  Would that be a fair assumption?
(new path is '/unofficial/poidrac/scripts/dreambow3.lua')

problem, is I can't see where I've got it wrong...
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

smacky

« Reply #8 on: 06, March 2010, 21:21:40 »
Well it may be a wrong path. As MM stand on the NPC (or its spawn point) and find the event object. Examine this and it'll dump out the attributes of the object. Is the path correct (IIRC it is on race? Also is the event number correct (should be 13 but I forget which attribute it is).

Going back to the logs, is there anything there? There should be at least this (assuming this is the firstlrun of the scripit after a server restart) (but obviously with different  names and paths):
Code: [Select]
LUA - event:13 file:>postoffice.lua< o1:>Testo< o2:>Postmaster< o3:>>NULL PTR<< text:>hello< i1:0 i2:0 i3:0 i4:2
LUA: normalized script path: /unofficial/grommit/postoffice/postoffice.lua
LUA - Script not in cache, loading '../maps//unofficial/grommit/postoffice/postoffice.lua' from file
LUA - Script not in cache, loading '../maps/lua/topic_list.lua' from file
LUA - Script not in cache, loading '../maps/lua/interface_builder.lua' from file

Error output looks like this:
Code: [Select]
LUA - ..../maps//unofficial/grommit/postoffice/postoffice.lua:383: No such class member: Game.GetTime
stack traceback:
../maps/lua/plugin_init.lua:149: in function <../maps/lua/plugin_init.lua:148>
[C]: ?
[C]: ?
..../maps//unofficial/grommit/postoffice/postoffice.lua:383: in function `setGreeting'
..../maps//unofficial/grommit/postoffice/postoffice.lua:1317: in main chunk
LUA - Terminating context due to runtime error (/unofficial/grommit/postoffice/postoffice.lua)

Poidrac

« Reply #9 on: 06, March 2010, 22:15:44 »
event settings:
Code: [Select]
sub_type 13
race /unofficial/poidrac/scripts/dreambow3.lua
name Lua
face event.101
no_pick 1
no_drop 1
sys_object 1
type 118

also, I'm not getting either of those in my log.

also, just tried with the shorter 'scripts/dreambow3.lua'  still nothing
« Last Edit: 06, March 2010, 22:17:46 by Poidrac »
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

smacky

« Reply #10 on: 06, March 2010, 22:49:50 »
The object is correct, but nothing in your log means the script is not being triggered at all for some reason. Must be a map problem.

You say other scripts you've written are running? Well even if not, try changing the path on Fanrir's event object to point to your script. Does it run now when you say hello to him?

(You might also try the opposite -- your NPC's event to point to Fanrir's script. Either way, if your script on Fanrir does run (at least logs) or Fanrir's script on your NPC doesn't run, we know there is some map problem on your map).

The most obvious problem would be your event object is in the wrong place. It should be in the inv of your NPC, like this:

Poidrac

« Reply #11 on: 07, March 2010, 01:46:02 »
Thank you for your patience with me :S

Once I get the jist of things, I might actually not need your help so much... *hopefully* ;)

okay, tried what you said, swapped the path of Fanrir's for mine.  Nothing.  However, Fanrir's will work on my character.

If I was thinking about that... it would be something in the code.
but I'm sort of damned, I can't find what I've got wrong.

*on a side note, when I talk to anyone *including people where the lua's do work *basically the standard ones already made* I'm not getting anything on the log file.  Is that normal? or am I missing something there?.  All I'm getting is the encode commands*
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

_people_

« Reply #12 on: 07, March 2010, 06:00:51 »
If something is wrong in the code, the code will run, crash, and then say something in the log file. If the code isn't being executed, nothing will be posted in the logs. Try a different trigger maybe, just to experiment? By any chance, did you disable logging in the server? I think it is defaulted to on, and I have no idea why you would disable it, but...
-- _people_ :)

smacky

« Reply #13 on: 07, March 2010, 12:53:13 »
* smacky glances at Poidrac.

Hm, I copied your script to fanrir.lua and got errors in the log (each error kills the script so needs to be fixed to get the next one, I stopped after 3 but there are more):

Code: [Select]
LUA - event:13 file:>guildhall/fanrir.lua< o1:>Smacky< o2:>Advisor Fanrir< o3:>>NULL PTR<< text:>hi< i1:0 i2:0 i3:0 i4:2
LUA: normalized script path: /planes/human_plane/castle/guildhall/fanrir.lua
LUA - Script not in cache, loading '../maps//planes/human_plane/castle/guildhall/fanrir.lua' from file
LUA - ../maps//planes/human_plane/castle/guildhall/fanrir.lua:45: `)' expected near `"wyvern"'
LUA - Terminating context due to runtime error (/planes/human_plane/castle/guildhall/fanrir.lua)

Code: [Select]
LUA - event:13 file:>guildhall/fanrir.lua< o1:>Smacky< o2:>Advisor Fanrir< o3:>>NULL PTR<< text:>hi< i1:0 i2:0 i3:0 i4:2
LUA: normalized script path: /planes/human_plane/castle/guildhall/fanrir.lua
LUA - Script not in cache, loading '../maps//planes/human_plane/castle/guildhall/fanrir.lua' from file
LUA - ../maps//planes/human_plane/castle/guildhall/fanrir.lua:96: `)' expected (to close `(' at line 93) near `ib'
LUA - Terminating context due to runtime error (/planes/human_plane/castle/guildhall/fanrir.lua)

Code: [Select]
LUA - event:13 file:>guildhall/fanrir.lua< o1:>Smacky< o2:>Advisor Fanrir< o3:>>NULL PTR<< text:>hi< i1:0 i2:0 i3:0 i4:2
LUA: normalized script path: /planes/human_plane/castle/guildhall/fanrir.lua
LUA - Script not in cache, loading '../maps//planes/human_plane/castle/guildhall/fanrir.lua' from file
LUA - ../maps//planes/human_plane/castle/guildhall/fanrir.lua:99: unexpected symbol near `111'
LUA - Terminating context due to runtime error (/planes/human_plane/castle/guildhall/fanrir.lua)

EDIT:
BTW I strongly recommend using a decent text editor with syntax highlighting for editing your scripts as this will show you many errors immediately (because things after the error will be the wrong colour).

Although it is jumping in at the deep end, you might try Vim. I wrote some syntax highlighting for Vim for arches, artefacts, anims, and maps as well (in project_tools somewhere). Lua (and C  and dozens of others) come as standard.
« Last Edit: 07, March 2010, 13:52:17 by smacky »

Poidrac

« Reply #14 on: 07, March 2010, 19:30:02 »
thanks Smacky... *cringes from the glances*

I think Person might be right.  I must have disabled logging somewhere.  with out actually knowing I did.

How would I go about checking/reenabling it?  It would make things much easier if I could get what I was measnt to get on the screen.
[img:e618cc32ae]http://img384.imageshack.us/img384/9149/sbannercopy3kr.jpg[/img:e618cc32ae]

Tags:
 

Related Topics

  Subject / Started by Replies Last post
3 Replies
1238 Views
Last post 18, December 2005, 01:35:07
by Slash_Wraith
21 Replies
3553 Views
Last post 26, December 2005, 14:07:30
by carasoph
4 Replies
1268 Views
Last post 08, March 2006, 03:07:34
by Comith
6 Replies
1607 Views
Last post 26, July 2006, 21:59:02
by Unislash
4 Replies
1950 Views
Last post 27, January 2013, 20:33:08
by B5_Misidian