• 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 I need help with a quest

jordi10

New Member
Joined
Jun 15, 2009
Messages
11
Reaction score
2
Dear scripters,

My idea:
A NPC asks you to kill a monster. If you accept the mission, you have to kill the monster in order to get your reward from the NPC.

That's quite simple, isn't it? Well, I tried figuring it out myself, but I couldn't. The scripts I wrote left me with an infinite number of errors, frustration and desperation. I do understand most of the scripts that I can use for mine, but it seems that understanding is harder than scripting it yourself.

So PLEASE, dear scripters, help me out!

Yours sincerely,

Jordi.
 
Put in data/creatureevents/scripts/npcmission.lua:
Code:
local config = {
['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1}
}
function onKill(cid, target)
local monster = config[getCreatureName(target):lower()]
if isPlayer(target) or not monster or isSummon(target) then
return true
end

if getPlayerStorageValue(cid, monster.storage) >= -1 and (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
end
if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
end
return true
end

Add in data/creatureevents/creatureevents.xml:
Code:
    <event type="kill" name="NpcMission" event="script" value="npcmission.lua"/>

Add in data/creatureevents/scripts/login.lua:
Code:
    registerCreatureEvent(cid, "NpcMission")
below
Code:
    registerCreatureEvent(cid, "AdvanceSave")

Add in data/npc/scripts/npcmission.lua:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 storage = 5002

function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if msgcontains(msg, "mission") then
if getPlayerStorageValue(cid, storage) == -1 then
selfSay("I have a mission for you to kill 5 dragons and 3 dragon lords, do you accept?", cid)
talkState[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 1 then
selfSay("Did you kill 5 dragons and 3 dragon lords?", cid)
talkState[talkUser] = 1
else
selfSay("You already did the mission.", cid)
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, storage) == -1 then
selfSay("Good, come back when you killed them.", cid)
setPlayerStorageValue(cid, storage, 1)
else
if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
selfSay("Good job, here is your reward.", cid)
doPlayerAddItem(cid, 2160, 5) -- GIVES 5 CRYSTAL COINS
doPlayerAddExp(cid, 50000) -- GIVES 50000 EXP
setPlayerStorageValue(cid, storage, 2)
else
selfSay("You didn't kill them all.", cid)
end
end
talkState[talkUser] = 0
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
selfSay("Ok then.", cid)
talkState[talkUser] = 0
end
return true
end

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

(Example Code) Now create an npc in data/npc/npcmission.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NPC Mission" nameDescription="NPC Mission" script="npcmission.lua" walkinterval="0" floorchange="0" skull="green">
    <health now="100" max="100"/>
    <look type="128" head="114" body="132" legs="0" feet="114" addons="3"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|!. I got missions!"/>
    </parameters>
</npc>

Excuse me if I did something wrong. Haven't slept for 3 days.
 
Put in data/creatureevents/scripts/npcmission.lua:
Code:
local config = {
['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1}
}
function onKill(cid, target)
local monster = config[getCreatureName(target):lower()]
if isPlayer(target) or not monster or isSummon(target) then
return true
end

if getPlayerStorageValue(cid, monster.storage) >= -1 and (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
end
if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
end
return true
end

Add in data/creatureevents/creatureevents.xml:
Code:
    <event type="kill" name="NpcMission" event="script" value="npcmission.lua"/>

Add in data/creatureevents/scripts/login.lua:
Code:
    registerCreatureEvent(cid, "NpcMission")
below
Code:
    registerCreatureEvent(cid, "AdvanceSave")

Add in data/npc/scripts/npcmission.lua:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 storage = 5002

function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if msgcontains(msg, "mission") then
if getPlayerStorageValue(cid, storage) == -1 then
selfSay("I have a mission for you to kill 5 dragons and 3 dragon lords, do you accept?", cid)
talkState[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 1 then
selfSay("Did you kill 5 dragons and 3 dragon lords?", cid)
talkState[talkUser] = 1
else
selfSay("You already did the mission.", cid)
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, storage) == -1 then
selfSay("Good, come back when you killed them.", cid)
setPlayerStorageValue(cid, storage, 1)
else
if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
selfSay("Good job, here is your reward.", cid)
doPlayerAddItem(cid, 2160, 5) -- GIVES 5 CRYSTAL COINS
doPlayerAddExp(cid, 50000) -- GIVES 50000 EXP
setPlayerStorageValue(cid, storage, 2)
else
selfSay("You didn't kill them all.", cid)
end
end
talkState[talkUser] = 0
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
selfSay("Ok then.", cid)
talkState[talkUser] = 0
end
return true
end

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

(Example Code) Now create an npc in data/npc/npcmission.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NPC Mission" nameDescription="NPC Mission" script="npcmission.lua" walkinterval="0" floorchange="0" skull="green">
    <health now="100" max="100"/>
    <look type="128" head="114" body="132" legs="0" feet="114" addons="3"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|!. I got missions!"/>
    </parameters>
</npc>

Excuse me if I did something wrong. Haven't slept for 3 days.

Thank you! The server doesn't give any errors, but when I've killed the monsters the NPC doesn't see that I killed the monsters. So it doesn't give me the rewards. Could you (or someone else) please revise the script(s)?
 
Back
Top