• 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.
 
Code:
if getCreatureName(target):lower() == "demodras" then
Remove the return false part, if function onKill returns false, the monster or player people kill won't die.
 
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"/>
    <event type="kill" name="Bosses" script="Bosses.lua"/>
</creaturescripts>

login.lua
Code:
function onLogin(cid)
    registerCreatureEvent(cid,"PlayerDeath")
    registerCreatureEvent(cid,"Dragons")
    registerCreatureEvent(cid,"Bosses")
    return TRUE
end

Bosses.lua
Code:
function onKill(cid, target)
if getCreatureName(target):lower() == "demodras" then
        setPlayerStorageValue(cid,7200,1)
        setPlayerStorageValue(cid,7201,1)
end
end

dragons.lua
Code:
local config = {
     ['rat'] = {amount = 500, 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) == TRUE or not monster or isSummon(target) == TRUE 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
 
Do you get errors? you can also try to do some tests with textmessages, or you can add the second script to the first one.
Under function onKill.
Code:
if getCreatureName(target):lower() == "demodras" then
     setPlayerStorageValue(cid,7200,1)
     setPlayerStorageValue(cid,7201,1)
end
 
Works perfectly, thx! :)

Now one more thing. instead of getting a msg everytime you kill a monster I would also like to make the following:
Checks mission state, if you kill the monster you advance to the next mission state. And then again it checks the mission state of the player and if you kill the next monster you advance a mission again.
This way it will be visible in the quest log how many monsters you already killed. And then after for example 50 times mission advance you stop advancing missions once you kill the monster and you have to report back to the npc.

Can be a repeat code that has to be copied for every mission again with edited mission numbers.

Any ideas? :)
 
The storage that is added is already doing that, the message is just as extra.
Code:
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
You can use the storage in the questlog.
 
Ran into a small complication using the questlog system.

I get this msg after killing the first rat
17:10 Task message: 2 of 50 Rats killed.

Server\data\creaturescripts\scripts\kill.lua
Code:
local config = {
     ['rat'] = {amount = 50, storage = 6701, startstorage = 6700, startvalue = 1},
}
function onKill(cid, target)
if getCreatureName(target):lower() == "demodras" then
     setPlayerStorageValue(cid,7200,1)
     setPlayerStorageValue(cid,7201,1)
end
     local monster = config[getCreatureName(target):lower()]
if isPlayer(target) == TRUE or not monster or isSummon(target) == TRUE 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

Server\data\creaturescripts\scripts\login.lua
Code:
function onLogin(cid)
    registerCreatureEvent(cid,"PlayerDeath")
    registerCreatureEvent(cid,"Kill")
    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="kill" script="kill.lua"/>
</creaturescripts>

Server\data\XML\quests.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<quests>
<quest name="In The Name Of The King" startstorageid="6700" startstoragevalue="1">
        <mission name="Sewer Problem" storageid="6701" startvalue="0" endvalue="52">
        <missionstate id="0" description="You have killed 0/50 rats."/> 
        <missionstate id="1" description="You have killed 1/50 rats."/> 
        <missionstate id="2" description="You have killed 2/50 rats."/> 
        <missionstate id="3" description="You have killed 3/50 rats."/> 
        <missionstate id="4" description="You have killed 4/50 rats."/> 
        <missionstate id="5" description="You have killed 5/50 rats."/> 
        <missionstate id="6" description="You have killed 6/50 rats."/> 
        <missionstate id="7" description="You have killed 7/50 rats."/> 
        <missionstate id="8" description="You have killed 8/50 rats."/> 
        <missionstate id="9" description="You have killed 9/50 rats."/> 
        <missionstate id="10" description="You have killed 10/50 rats."/> 
        <missionstate id="11" description="You have killed 11/50 rats."/> 
        <missionstate id="12" description="You have killed 12/50 rats."/> 
        <missionstate id="13" description="You have killed 13/50 rats."/> 
        <missionstate id="14" description="You have killed 14/50 rats."/> 
        <missionstate id="15" description="You have killed 15/50 rats."/> 
        <missionstate id="16" description="You have killed 16/50 rats."/> 
        <missionstate id="17" description="You have killed 17/50 rats."/> 
        <missionstate id="18" description="You have killed 18/50 rats."/> 
        <missionstate id="19" description="You have killed 19/50 rats."/> 
        <missionstate id="20" description="You have killed 20/50 rats."/> 
        <missionstate id="21" description="You have killed 21/50 rats."/> 
        <missionstate id="22" description="You have killed 22/50 rats."/> 
        <missionstate id="23" description="You have killed 23/50 rats."/> 
        <missionstate id="24" description="You have killed 24/50 rats."/> 
        <missionstate id="25" description="You have killed 25/50 rats."/> 
        <missionstate id="26" description="You have killed 26/50 rats."/> 
        <missionstate id="27" description="You have killed 27/50 rats."/> 
        <missionstate id="28" description="You have killed 28/50 rats."/> 
        <missionstate id="29" description="You have killed 29/50 rats."/> 
        <missionstate id="30" description="You have killed 30/50 rats."/> 
        <missionstate id="31" description="You have killed 31/50 rats."/> 
        <missionstate id="32" description="You have killed 32/50 rats."/> 
        <missionstate id="33" description="You have killed 33/50 rats."/> 
        <missionstate id="34" description="You have killed 34/50 rats."/> 
        <missionstate id="35" description="You have killed 35/50 rats."/> 
        <missionstate id="36" description="You have killed 36/50 rats."/> 
        <missionstate id="37" description="You have killed 37/50 rats."/> 
        <missionstate id="38" description="You have killed 38/50 rats."/> 
        <missionstate id="39" description="You have killed 39/50 rats."/> 
        <missionstate id="40" description="You have killed 40/50 rats."/> 
        <missionstate id="41" description="You have killed 41/50 rats."/> 
        <missionstate id="42" description="You have killed 42/50 rats."/> 
        <missionstate id="43" description="You have killed 43/50 rats."/> 
        <missionstate id="44" description="You have killed 44/50 rats."/> 
        <missionstate id="45" description="You have killed 45/50 rats."/> 
        <missionstate id="46" description="You have killed 46/50 rats."/> 
        <missionstate id="47" description="You have killed 47/50 rats."/> 
        <missionstate id="48" description="You have killed 48/50 rats."/> 
        <missionstate id="49" description="You have killed 49/50 rats."/> 
        <missionstate id="50" description="You killed all the rats, now XXX knows that you helped solving the sewer problem."/>
        <missionstate id="51" description="You succesfully completed XXX first task."/>
        </mission>
        <mission name="mission 2" storageid="5572" startvalue="1" endvalue="1">
            <missionstate id="1" description="..."/>
        </mission>
        <mission name="mission 0" storageid="43313" startvalue="1" endvalue="1">
            <missionstate id="1" description="..."/>
        </mission>
    </quest>
</quests>

Server\data\creaturescripts\scripts\firstitems.lua
Code:
local firstItems =
{
    2050
}

function onLogin(cid)
              setPlayerStorageValue(cid,6700,1)
              setPlayerStorageValue(cid,6701,0)
    if getPlayerStorageValue(cid, 30001) == -1 then
        for i = 1, table.maxn(firstItems) do
            doPlayerAddItem(cid, firstItems[i], 1)
        end
        if getPlayerVocation(cid) == 1 then
            doPlayerAddItem(cid, 2186, 1)
        elseif getPlayerVocation(cid) == 2 then
            doPlayerAddItem(cid, 2182, 1)
        end
        local bag = doPlayerAddItem(cid, 1988, 1)
        doAddContainerItem(bag, 2674, 1)
        setPlayerStorageValue(cid, 30001, 1)
    end
    return TRUE
end
 
Actually you can, but you can also change it in the script, just remove the +1 from the getPlayerStorageValue parts (not in the setPlayerStorageValue lines).
 
Weirdest thing just happened :s
Restarted my server without changing anything and now the following script doesn't work anymore.

Code:
local config = {
     ['rat'] = {amount = 50, storage = 6701, startstorage = 6700, startvalue = 1},
}
function onKill(cid, target)
if getCreatureName(target):lower() == "demodras" then
     setPlayerStorageValue(cid,7200,1)
     setPlayerStorageValue(cid,7201,1)
end
     local monster = config[getCreatureName(target):lower()]
if isPlayer(target) == TRUE or not monster or isSummon(target) == TRUE 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
 
You can do all kinds of tests to find out what's wrong, like adding print or textmessages.
Something you add right under function onKill will always happen if you kill something, so you can do that to find out if it loads the script for example.
 
Added a dosentmessage below the onKill function and is does not give any message so clearly the script isn't being loaded.

Only things I did while the server was online was create a character with the mission state -1 but I already deleted that character
 
Code:
function onKill(cid, target)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Test")
end

changed the kill.lua to that and still no response.

removed the kill.lua file and got the following error
[31/07/2014 18:29:55] Warning: [Event::checkScript] Can not load script. /scripts/kill.lua
[31/07/2014 18:29:55] cannot open data/creaturescripts/scripts/kill.lua: No such file or directory
[31/07/2014 18:29:55] Reloaded creature events.
 
Did you change something in creaturescripts.xml? or did you rename the script?

Also better restart your server instead of reload if you make changes in creaturescripts, in several older versions of TFS this reload type doesn't work properly.
 
Last edited:
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="kill" script="kill.lua"/>
</creaturescripts>

login.lua
Code:
function onLogin(cid)
    registerCreatureEvent(cid,"PlayerDeath")
    registerCreatureEvent(cid,"Kill")
    return TRUE
end

Renamed it back to kill.lua but changed it in 'creaturescripts.xml' and 'login.lua'
Also renamed it back to 'dragons.lua' and it still didn't work.

Further I restart my server each time i make a change and it doesn't work after reloading it.
 
Back
Top