• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Quest] An Uneasy Alliance

rwxsu

Computer Engineer
Joined
Mar 31, 2018
Messages
121
Solutions
5
Reaction score
169
GitHub
rwxsu
An Uneasy Alliance - RL - TFS: 1.2

Quest Wiki:
An Uneasy Alliance Quest/Spoiler



Add to data/lib/core/quests/uneasy_alliance.lua folder:
Code:
UneasyAlliance = {
    storage = {
        [1] = {
            onMission    = 80770,
            complete     = 80771,
            rewarded     = 80772,
        },
        [2] = {
            onMission    = 80773,
            complete     = 80774,
            rewarded     = 80775,
        },
    },
    item = {
        [1] = {
            name = "tome of knowledge",
            id = 11134,
        },
        [2] = {
            name = "scrying crystal ball",
            id = 7493,
        },
    }
}

UneasyAlliance.__index = UneasyAlliance


function UneasyAlliance:setMission(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].onMission, val)
        return
    elseif mission == 2 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].onMission, val)
        return
    end       
    print("[DEBUG] UneasyAlliance:setMission has failed.")
end

function UneasyAlliance:setCompleted(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].complete, val)
        return
    elseif mission == 2 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].complete, val)
        return
    end       
    print("[DEBUG] UneasyAlliance:setCompleted has failed.")
end

function UneasyAlliance:setRewarded(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    elseif mission == 2 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    end
    print("[DEBUG] UneasyAlliance:setRewarded has failed.")
end

-- onMission checks if player is already on the mission for the mission provided
function UneasyAlliance:onMission(cid, mission)
    if Player(cid):getStorageValue(UneasyAlliance.storage[mission].onMission) == 1 then
        return true
    end
    return false
end

-- isCompleted checks if the required tasks are finished for the mission provided
function UneasyAlliance:isCompleted(cid, mission)
    if Player(cid):getStorageValue(UneasyAlliance.storage[mission].complete) == 1 then
        return true
    end
    return false
end

-- isRewarded checks if player has received a reward for the mission provided
function UneasyAlliance:isRewarded(cid, mission)
    if Player(cid):getStorageValue(UneasyAlliance.storage[mission].rewarded) == 1 then
        return true
    end
    return false
end



Remember to add this in: data/lib/core/core.lua
Code:
dofile('data/lib/core/quest/uneasy_alliance.lua')

Add to data/npc/curos.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Curos" script="curos.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="29" corpse="5983" />
    <parameters>
        <parameter key="message_greet" value="Be greeted blank skin." />
    </parameters>
</npc>


Add to data/npc/scripts/curos.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                          npcHandler:onThink()                        end

npcHandler:addModule(FocusModule:new())


function start(cid, mission) 
    UneasyAlliance:setMission(cid, 1, mission)
end

function reward(cid, mission)
    UneasyAlliance:setRewarded(cid, 1, mission)
    UneasyAlliance:setMission(cid, 0, mission)
   
    -- Reward 'Tome of Knowledge'
    if mission == 2 then
        Player(cid):addItem(UneasyAlliance.item[1].id, 1)
        Player(cid):sendTextMessage(MESSAGE_EVENT_ORANGE, "You received a " .. UneasyAlliance.item[1].name .."!")
    end
end


function creatureSayCallback(cid, type, msg)

    if msgcontains(msg, "mission") then

        -- If player has started mission 1
        if UneasyAlliance:onMission(cid, 1) then           

            -- If the player has completed mission 1,
            -- and hasn't received the reward,
            -- give the player a reward
            if UneasyAlliance:isCompleted(cid, 1) then
                selfSay("With the death of their leader, the rebels return to our camps one by one, deeply humiliated. It might be a wise decision to let a useful tool like you continue to exist.", cid)
                reward(cid, 1)
                return
            end

            selfSay("You are already doing your first mission. Kill Renegade Orc!", cid)
            return
        end

        -- If player has started mission 2
        if UneasyAlliance:onMission(cid, 2) then
           
            -- If the player has completed mission 2,
            -- and hasn't received the reward,
            -- give the player a reward
            if UneasyAlliance:isCompleted(cid, 2) then
                selfSay("Finally, our enemy's vision is obscured. Now we can move in for some more daring raids until they replace their scrying device. You have proven yourself brave and useful so far. With that, you bought your allies some more days to live.", cid)
                selfSay("Here is a reward. It's a strange tome that we've found in the lizard ruins. Maybe it is of some value for you or your allies.", cid)
                reward(cid, 2)
                return
            end

            selfSay("You are already doing your second mission. Break the stone!", cid)
            return
        end

        -- If player has completed both missions
        if UneasyAlliance:isRewarded(cid, 2) then
            selfSay("You have already completed both missions", cid)
            return
        end

        -- If player has completed mission 1
        -- Then start mission 2
        if UneasyAlliance:isRewarded(cid, 1) then
           
            selfSay("We are aware that the lizards use magic to spy on us. In the Dragonblaze Mountains north of here, there is a tower which can only be entered through one of their underground fortresses.", cid)
            selfSay("In this tower, there must be some accessory used for magical scrying. Some pond, a crystal ball, or a mirror maybe - it has to be something shiny.", cid)
            selfSay("Usually we would send one of our youngsters on such a mission, but we are few and there is little new blood in our ranks.", cid)
            selfSay("We can't send a Mooh'Tah master on such a trivial assignment, neither can we use orcs for an infiltration mission.", cid)
            selfSay("This is your chance to show us your potential. Infiltrate this tower and destroy their scrying device. Once you have blinded our enemy, we might respect you somewhat more.", cid)

            start(cid, 2)
            return
        end

        -- Otherwise start mission 1
        selfSay("So you still think you can be of any use for us? Words are cheap and easy. Admittedly, you've passed our first test but even some resilient beast might have accomplished that.", cid)
        selfSay("Your actions will tell if you are only yelping for attention like a puppy or if you have the teeth of a wolf.", cid)
        selfSay("A first tiny step was taken. You survived the test and ensured the survival of your allies for a while. Now it is time to make the next step.", cid)
        selfSay("So listen human: Our rule over the orcs is not unchallenged. Of course now and then someone shows up who thinks he can defeat us. Usually these fights end fast and bloody in the ring.", cid)
        selfSay("Right now, some coward from our midst, who is too afraid to face us in single combat, has gathered a group of followers, hoping more will follow and change sides.", cid)
        selfSay("With your help, his defeat will not only be deadly but also humiliating and so discourage others to follow his example.", cid)
        selfSay("You will seek out this rebel commander in his hideout and kill him. We will show them that not even a Mooh'Tah master is needed to get rid of such wannabe leaders but that a mere human can handle them.", cid)
        selfSay("Find him in the mountain north-west of here and kill him. If you find any loot, you can keep it.", cid)

        start(cid, 1)
        return
    end


    -- Use only for testing purposes
    -- Comment it out when going live
    if msgcontains(msg, "reset") then

        UneasyAlliance:setMission(cid, 0, 1)
        UneasyAlliance:setCompleted(cid, 0, 1)
        UneasyAlliance:setRewarded(cid, 0, 1)
        UneasyAlliance:setMission(cid, 0, 2)
        UneasyAlliance:setCompleted(cid, 0, 2)
        UneasyAlliance:setRewarded(cid, 0, 2)
        Player(cid):registerEvent("UneasyAlliance")

        selfSay("[TESTING]: reseted.", cid)
        return
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)


Add to data/creaturescripts/scripts/uneasy_alliance.lua
Code:
function onKill(creature, target)

    message = "You killed the Renegade Orc! Talk to Curos to claim your reward."
    mission = 1

    if target:getName() == 'Renegade Orc' then
        UneasyAlliance:setCompleted(creature:getId(), 1, mission)
        creature:sendTextMessage(MESSAGE_EVENT_ORANGE, message)
       
        -- Unregisters the event to increase server performance
        -- And also that you don't get the message when killing
        -- 'Renegade Orc' several times
        creature:unregisterEvent("UneasyAlliance")
    end
    return
end


Remember to add in data/creaturescripts/creaturescripts.xml
Code:
<event type="kill" name="UneasyAlliance" script="uneasy_alliance.lua" />


Add in data/actions/quests/uneasy_alliance.lua
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    -- Check if player is on the second mission
    if UneasyAlliance:onMission(player:getId(), 2) and not UneasyAlliance:isCompleted(player:getId(), 2) then       
        player:sendTextMessage(MESSAGE_EVENT_ORANGE, "You destroyed the " .. UneasyAlliance.item[2].name .. "! Report back to Curos to claim your reward.")
        UneasyAlliance:setCompleted(player:getId(), 1, 2)
        return true
    end

    return false
end


Remember to add in data/actions/actions.xml
Code:
<action itemid="7493" script="quests/uneasy_alliance.lua" />


This is the functionality for mission 1 and mission 2 in 'An Uneasy Alliance'.

Hope you enjoy it,
rwxsu
 
100% perfect! Totally recommended!

Btw I would recommend to remove the "reset" part.
 
Last edited by a moderator:
You could do this parte:
Code:
function UneasyAlliance:setRewarded(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    elseif mission == 2 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    end
    print("[DEBUG] UneasyAlliance:setRewarded has failed.")
end

like this:

Code:
[code]function UneasyAlliance:setRewarded(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    end
    print("[DEBUG] UneasyAlliance:setRewarded has failed.")
end
[/code]

right? there are other parts like this... or am i missing something?

I'm sorry for the double post but I can't edit the first one

I've seen this in some scripts but I can't figure out how and what it does

this part:
Code:
Player(cid):registerEvent("UneasyAlliance")

What kind of event is that and what does it do?
 
Last edited by a moderator:
You could do this parte:
Code:
function UneasyAlliance:setRewarded(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    elseif mission == 2 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    end
    print("[DEBUG] UneasyAlliance:setRewarded has failed.")
end

like this:

Code:
function UneasyAlliance:setRewarded(cid, val, mission)
    if mission == 1 then
        Player(cid):setStorageValue(UneasyAlliance.storage[mission].rewarded, val)
        return
    end
    print("[DEBUG] UneasyAlliance:setRewarded has failed.")
end

right? there are other parts like this... or am i missing something?

I'm sorry for the double post but I can't edit the first one

I've seen this in some scripts but I can't figure out how and what it does

this part:
Code:
Player(cid):registerEvent("UneasyAlliance")

What kind of event is that and what does it do?
Sorry for the late answer, didn't see your post until now.
Can't remember why I made it like that, it's correct what you're saying (DRY). You can omit the if mission == x part completely, but you should check if it's a valid mission in some way.


The registerEvent activates the onKill in creaturescripts
 
how i can add your script with the script a already have ? npc curos.lua

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)           npcHandler:onCreatureAppear(cid)           end
function onCreatureDisappear(cid)       npcHandler:onCreatureDisappear(cid)           end
function onCreatureSay(cid, type, msg)       npcHandler:onCreatureSay(cid, type, msg)       end
function onThink()       npcHandler:onThink()       end

local function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
       return false
   end

   local player = Player(cid)
   if(msgcontains(msg, "mission")) then
       if(player:getStorageValue(Storage.TheNewFrontier.Questline) == 17) then
           npcHandler:say("You come here to ask us to spare your people? This land has no tolerance for the weak, we have it neither. If you want us to consider you as useful for us, you'll have to prove it in a {test} of strength and courage. ", cid)
           npcHandler.topic[cid] = 1
       elseif(player:getStorageValue(Storage.TheNewFrontier.Questline) == 19) then
           npcHandler:say({
               "We have seen that you can fight and survive. Yet, it will also need cleverness and courage to survive in these lands. We might see later if you've got what it takes. ...",
               "However, I stand to my word - our hordes will spare your insignificant piece of rock for now. Time will tell if you are worthy living next to us. ...",
               "Still, it will take years until we might consider you as an ally, but this is a start at least."
           }, cid)
           player:setStorageValue(Storage.TheNewFrontier.Questline, 20)
           player:setStorageValue(Storage.TheNewFrontier.Mission06, 3) --Questlog, The New Frontier Quest "Mission 06: Days Of Doom"
       end
   elseif(msgcontains(msg, "test")) then
       if(npcHandler.topic[cid] == 1) then
           npcHandler:say({
               "First we will test your strength and endurance. You'll have to face one of the most experienced Mooh'Tah masters. As you don't stand a chance to beat such an opponent, your test will be simply to survive. ...",
               "Face him in a battle and survive for two minutes. If you do, we will be willing to assume that your are prepared for the life in these lands. Enter the ring of battle, close to my quarter. Return to me after you have passed this test."
           }, cid)
           npcHandler.topic[cid] = 0
           player:setStorageValue(Storage.TheNewFrontier.Questline, 18)
           player:setStorageValue(Storage.TheNewFrontier.Mission06, 2) --Questlog, The New Frontier Quest "Mission 06: Days Of Doom"
       end
   end
   return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Someone can help me ? /\
 
Last edited by a moderator:
Back
Top