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

Solved Improve mission after killing a monster

Exoltes

Novia OTserv Developer
Joined
Jul 2, 2009
Messages
563
Reaction score
47
Location
Belgium
I've been checking like 20 threads of killing in the name of quest etc and I can't seem to fix it :s

What I'm trying to do is learn this step by step.
I've created 50 missions and in each mission the number of killed monsters will increase.
But I can't seem to find a way to make the mission actually increase after killing the monster.

So first of all I'm looking for a script that just simply adds a mission value after killing a monster and secondly I would love to see a script that stops increasing the mission state after x kills.

I'm working on a 8.54 Open Tibia Server using The Forgotten Server - Version 0.2.7 (Mystic Spirit).

Thanks in advance.
 
I mean from creaturescripts.xml for example. Normally if it doesn't load, it should give an error (except from if it isn't registered, then it just doesn't load).

Btw, if you add print in login.lua, do you see that message when you login?
 
Code:
function onLogin(cid)
    registerCreatureEvent(cid, "PlayerDeath")
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"Test")
    registerCreatureEvent(cid, "Kill")
    return TRUE
end

the msg part works yes.

added the same line below the onkill function and that also works.
 
So figures that the problem should be somewhere in this script; Server\data\creaturescripts\scripts\kill.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
 
removed
Code:
     if isPlayer(target) or not monster or isSummon(target) then
         return true
     end
and now it works


But how do we fix the summon and player problem?

Tested these and they also don't work
Code:
     if not monster or isSummon(target) then
         return true
     end
Code:
     if isPlayer(target) or isSummon(target) then
         return true
     end
Code:
     if isPlayer(target) or not monster then
         return true
     end
Code:
     if isPlayer(target) then
         return true
     end
Code:
     if not monster then
         return true
     end
Code:
     if isSummon(target) then
         return true
     end
 
Last edited:
You can add this in global.lua
Code:
function isSummon(cid)
   return (isCreature(cid) == TRUE and (getCreatureMaster(cid) ~= cid)) and TRUE or FALSE
end

The function isPlayer exists in TFS 0.2.7 and also the "not monster" part is needed else you will get alot of errors and bugs when killing other monsters.
 
added it and included the code again into the kill.lua
but now it doesn't work anymore. unless I remove the code below again
Code:
if isPlayer(target) or not monster or isSummon(target) then
return true
end
 
You can also just remove
Code:
or isSummon(target)
If the monsters can't be summons.

If you get errors in your console, post them and post the full script.
 
I already removed the
Code:
or isSummon(target)
part and that didn't change a thing.

as long as any part of this code is in there the script doesn't work
Code:
if isPlayer(target) or not monster or isSummon(target) then
return true
end

Getting no errors in my console.
 
Server\data\creaturescripts\scripts\dragons.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 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

Server\data\creaturescripts\scripts\login.lua
Code:
function onLogin(cid)
    registerCreatureEvent(cid,"PlayerDeath")
    registerCreatureEvent(cid,"Dragons")
    return TRUE
end

Server\data\creaturescripts\creaturescripts.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
    <event type="login" name="PlayerLogin" script="login.lua"/>
    <event type="login" name="FirstItems" script="firstitems.lua"/>
    <event type="death" name="PlayerDeath" script="playerdeath.lua"/>
    <event type="kill" name="Dragons" script="dragons.lua"/>
</creaturescripts>

Server\data\npc\kill mission npc.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Kill NPC" script="data/npc/scripts/kill.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="139" head="114" body="114" legs="114" feet="114" addons="3"/>
</npc>

Server\data\npc\scripts\kill.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)
                 doPlayerAddExp(cid, 50000)
                 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())

These are all the scripts and everything that was altered. (+ the edit in the global.lua)
 
removed
Code:
     if isPlayer(target) or not monster or isSummon(target) then
         return true
     end
and now it works


But how do we fix the summon and player problem?

Tested these and they also don't work
Code:
     if not monster or isSummon(target) then
         return true
     end
Code:
     if isPlayer(target) or isSummon(target) then
         return true
     end
Code:
     if isPlayer(target) or not monster then
         return true
     end
Code:
     if isPlayer(target) then
         return true
     end
Code:
     if not monster then
         return true
     end
Code:
     if isSummon(target) then
         return true
     end


Kinda already said this :D

Also retested it all now with the edit in the 'global.lua' but still no change.

As long as anything related to this line of code is within the 'dragons.lua' file, the script wont work.
 
If the line isn't in the right place, it will give errors and won't work.
isPlayer is a function in TFS 0.2.7, the "not monster" part is Lua, so this part can't not work unless it's added incorrect.

Make sure you restart your server after you make the changes.
 
Last edited:
dragons.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 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

I always restart after every edit just to make sure.

Still not working
 
If you add a textmessage above return true in that part, do you get it when you kill something?
Code:
if isPlayer(target) or not monster then
     -- textmessage here
     return true
end
 
Btw what does the 'not monster' check for?
Since I can block all player names to be the same as monsters and if needed I can remove the summon creature spell since I'm going 70% custom anyway or make the monsters from tasks impossible to summon or convince.
 
Tested with TFS 0.2.7, this works for me.
Code:
if isPlayer(target) == TRUE or not monster or isSummon(target) == TRUE then
   return true
end

The not monster part to check if the monster someone is killing is added to the table, without that the monsters that are not added to the table won't die when people kill them and you will get alot of errors.
 
works thx :)

Had to disable a script i made last night to make it work now.

any idea how i can activate this beside it?

Code:
function onKill(cid, target)
    if getCreatureName(Demodras) then
        setPlayerStorageValue(cid,7200,1)
        setPlayerStorageValue(cid,7201,1)
    else
        return FALSE
    end
    return TRUE
end

I want people to be able to keep track of the bosses they killed in their questlog, so if u kill it u get the playerstoragevalue and if u kill it again u can get it again since it has no mission states orso so there will be no difference
 
Last edited:
Back
Top