croix
Member
- Joined
- Aug 26, 2011
- Messages
- 123
- Reaction score
- 13
Part 5 - Different kinds of missions
Monster mission
When you want a mission that's not about items, for example with killing monsters, it's not so much different than an items mission.
Only now instead of checking if a player has an item, you check if a player killed monsters.
There are functions to find out if a player has items, but there is no function to find out if a player has killed monsters, that's why you have to add storagevalues when killing the monsters, so you can check for that storagevalue in the NPC.
This can't be done in an NPC, since an NPC has no influence on what you kill, so you have to make an extra script in creaturescripts with function onKill.
For example you want a mission where someone has to kill 5 dragons and 3 dragons lords (if you want more or less monsters, you can just add or remove lines in local config).
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) < 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
The startstorage is the storage from the NPC with value 1, so this means the script will start counting after accepting the mission.
The other storage, named storage, is to count the monsters.
Now in the NPC, instead of checking if a player has an item, you check for the value of the storage you use used to count the monsters.
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())
Any chance you have this creaturescript updated to TFS 1.3?