• 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!

Lua [QUEST] Quests, Movements and Actions

Druid Elf

Member
Joined
Oct 18, 2009
Messages
226
Reaction score
12
Location
Kiranthyl
Here's the problem:
I managed how to work with NPCs and the quests.xml, but it also involves a movement and an action :p

1st - There is a hole close to the NPC. I want it so the player can't go down unless he/she started the quest: "You are not yet prepared to enter this cave."
So, player talks to NPC to start the quest, now he/she can go down the cave.

2nd - In the cave, there is another NPC the player must talk and return to the first to complete the quest and get his/her reward.

3rd - Ok, quest finished, now in the cave there is a pickhole, only when the quest IS finished, the player can Pick it, when walking on it (going down), it closes back.


Still haven't figured how to do all that, been reading the forum for a while now o_O

----------

The NPCs are finished
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Robin" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="128" head="41" body="17" legs="90" feet="1" addons="3" mount="379"/>

    <interaction range="5" idletime="150" idleinterval="300" defaultpublic="0">
    
    <interact keywords="hi" focus="1"><keywords>hello</keywords>
        <response>
        <action name="script">
        <![CDATA[
            if (getPlayerStorageValue(cid, 40001)) == 2 then
                selfSay("Hello, " .. getCreatureName(cid) .. "! Would you like to buy some fishes?", cid)
            else
                selfSay("Hello, " .. getCreatureName(cid) .. "! Oh my... My {brother}... My brother is missing!", cid)
            end
        ]]>
        </action>
        </response>
    </interact>
    
    <interact keywords="bye" focus="0"><keywords>farewell</keywords>
        <response>
        <action name="script">
        <![CDATA[
            if (getPlayerStorageValue(cid, 40001)) == 2 then
                selfSay("Good bye.", cid)
            else
                selfSay("Good bye and if you see him...", cid)
            end
        ]]>
        </action>
        </response>
    </interact>
    
    <interact event="onBusy">
        <response text="Please, wait your turn.">
        <action name="addqueue" value="|NAME|"/>
        </response>
    </interact>
    
    <interact event="onPlayerLeave">
        <response text="Bye then..."/>
    </interact>
    
    <interact keywords="brother" storageId="40001" storageValue="0" storageComp="less">
        <response text="Oh my... My brother is missing... Could you help me find him?">
            <interact keywords="yes">
                <response text="Thank you, thank you! I'm so happy someone is going to help me... I've heard there is a small hole near this place, perhaps he fell in there? Could you go and take a look?">
                <interact keywords="yes">
                    <response text="Thank you! If you see him, report back immediatly, I'm sooooo worried!">
                        <action name="storage" key="40000"  value="1"/>
                        <action name="storage" key="40001"  value="0"/>
                        <action name="script">
                        <![CDATA[
                            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                        ]]>
                        </action>
                    </response>
                </interact>
                </response>
            </interact>
        </response>
    </interact>
    
    <interact keywords="report" storageId="40001" storageValue="1" storageComp="equal">
        <response text="Did you find my brother?!">
            <interact keywords="yes">
                <response text="Oh my! What? He is... HIDING from me?! I can't believe him! Anyway, thank you very much for helping me, here is your reward!">
                    <action name="storage" key="40001" value="2"/>
                    <action name="script">
                    <![CDATA[
                        doPlayerAddExp(cid, 500)
                        doPlayerGiveItem(cid, 2152, 3)
                        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                    ]]>
                    </action>
                </response>
            </interact>
        </response>
    </interact>
    
    <interact keywords="reward" storageId="40001" storageValue="2" storageComp="equal">
        <response><action name="script">
            <![CDATA[
                doPlayerAddExp(cid, 500)
                doPlayerGiveItem(cid, 2152, 3)
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
            ]]>
        </action></response>
    </interact>
    
    <itemlist listid="fishes">
        <item keywords="fish" id="2667" sellprice="2" buyprice="5"/>
        <item keywords="salmon" id="2668" sellprice="0" buyprice="10"/>
    </itemlist>
    
    <interact keywords="trade">
        <list>fishes</list>
        <response text="Check these delicious fishes!">
        <action name="script">
            <![CDATA[
                if (getPlayerStorageValue(cid, 40001)) == 2 then
                    openShopWindow(cid, itemlist, -1, -1)
                else
                    selfSay("I am too busy now to make any business.", cid)
                end
            ]]>
        </action>
        </response>
    </interact>
    
    <interact event="onPlayerShopSell">
        <response>
            <action name="price" value="|SELLPRICE|"/>
            <action name="script">
            <![CDATA[
                if(doPlayerRemoveItem(cid, _state.itemid, _state.amount, _state.subtype) == TRUE) then
                    doPlayerAddMoney(cid, _state.price * _state.amount)
                    selfSay("Here you are.", cid)
                else
                    selfSay("Sorry, you do not have one.", cid)
                end
            ]]>
            </action>
        </response>
    </interact>
        
    <interact event="onPlayerShopBuy">
        <response>
            <action name="price" value="|BUYPRICE|"/>
            <action name="script">
            <![CDATA[
                if(getPlayerMoney(cid) >= _state.amount * _state.price) then
                    --doSellItem(cid, itemid, amount, <optional> subtype, <optional> actionid, <optional: default: 1> canDropOnMap)
                    local sellAmount = doSellItem(cid, _state.itemid, _state.amount, _state.subtype, 0, 0)

                    if(sellAmount ~= _state.amount) then
                        if(sellAmount == 0) then
                            selfSay("Sorry, but you don't have room to take it.", cid)
                            return
                        elseif(sellAmount > 0) then
                            selfSay("I've sold some for you, but it seems you can't carry more than this. I won't take more money than necessary.", cid)
                            doPlayerRemoveMoney(cid, sellAmount * _state.price)
                            return
                        end
                    end

                    selfSay("Here you are.", cid)
                    doPlayerRemoveMoney(cid, _state.price * _state.amount)
                else
                    selfSay("Sorry, you do not have enough gold.", cid)
                end
            ]]>
            </action>
        </response>
    </interact>

    <interact event="onPlayerShopClose" focus="0">
        <response text="It was a pleasure to help you."/>
    </interact>
    </interaction>
    
</npc>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Brangoth" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="153" head="2" body="41" legs="110" feet="33" addons="3" mount="379"/>

    <interaction range="3" idletime="150" idleinterval="300" defaultpublic="0">
    
        <interact keywords="hi" focus="1"><keywords>hello</keywords>
        <response text="Shhhh, |NAME|. My brother cannot know I am here.">
        </response>
        </interact>
    
    <interact keywords="bye" focus="0"><keywords>farewell</keywords>
        <response text="Good bye, |NAME|! Do not tell my brother I'm here.">
        </response>
    </interact>
    
    <interact event="onBusy">
        <response text="Please, be quiet.">
        <action name="addqueue" value="|NAME|"/>
        </response>
    </interact>
    
    <interact event="onPlayerLeave">
        <response text="Shhh!"/>
    </interact>
    
    <interact keywords="brother" storageId="40001" storageValue="0" storageComp="less">
        <response text="Shhhhh! Don't let my brother know I'm here... Why are you here, did he send you?">
            <interact keywords="yes" focus="0">
                <response text="Argh... Anyway, my brother is an... can't say, sorry. I don't want to see him for a while.">
                    <action name="storage" key="40001"  value="1"/>
                    <action name="script">
                    <![CDATA[
                        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                    ]]>
                    </action>
                </response>
            </interact>
        </response>
    </interact>
    
    </interaction>
</npc>

However, the problem is within the damn hole (id 293 and 294)
In my movements.xml I found this line:
Code:
<moveevent event="StepIn" itemid="293" script="increment.lua" />
So, I created a new one:
Code:
<moveevent event="StepIn" uniqueid="4001" script="fishhole.lua" />
and created a LUA file similar to "increment.lua"
Code:
function onStepIn(cid, item, pos)
    if item.uid == 4001 and getPlayerStorageValue(cid, 40001) < 0 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You are not yet prepared to enter this place.")
        doPlayerSendCancel(cid, "")
    end
    return true
end

When I step on the hole (293) I do get the green message, but... I still go down ¬¬"

Haven't tried the PICK yet, but I guess when this one is fixed, I'll be able to do it with the PICK :D
 
Yea, I thought about it, but couldn't find the code for the hole, do you know where I can find it? The sources? I tried looking at 'em searching for "stepin" but no success at all.
 
I managed to fix the first hole \o/

So here's the script:
Code:
function onStepIn(cid, item, pos, fromPos)
	if item.uid == 4001 and getPlayerStorageValue(cid, 40001) < 0 then
		doTeleportThing(cid, fromPos)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You are not yet prepared to enter this place.")
	end
	return true
end
Easy fix I didn't notice at first...

Next thing, the Pick!
First, let's add an unique ID to our pickhole, I chose 4002 (to follow the quest) and create another movement for it, like the first! Since the player has to finish the quest in order to go down, storage value higher than 2!
PHP:
<moveevent event="StepIn" itemid="392" script="fishhole2.lua" />
Code:
function onStepIn(cid, item, pos, fromPos)
	if item.uid == 4002 and getPlayerStorageValue(cid, 40001) < 2 then
		doTeleportThing(cid, fromPos)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You are not yet prepared to enter this place.")
	end
	return true
end
Now we have to make the PICK work with the quest!
Open pick.lua and find this line
Code:
if(isInArray(ROPE_SPOT, itemGround.itemid) and isMoveable(itemEx.uid) == false and isCorpse(itemEx.uid) == false) then
under it you add
Code:
if itemEx.uid == 4002 and getPlayerStorageValue(cid, 40001) < 2 then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It seems you found something, but you are not yet prepared for it.")
		else
We don't want our players to find out about this pickhole very often, so let's change the time it remains open? Default is 5 minutes, what about 10 seconds?
Code:
if itemEx.uid == 4002 then
			duration = 10000
			addEvent(__doTransformHole__, duration, {oldType = itemEx.itemid, pos = toPosition})
		else
		addEvent(__doTransformHole__, duration, {oldType = itemEx.itemid, pos = toPosition})
		end
And don't forget to add another END after "return true", before the Fragile_Ice part :p
 
Back
Top