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

Whi World NPC "Task Master" [TFS 1.0]

@Vanderlay I would like to assist you by providing you some help in understanding what a tutorial is.

Tutorial: A tutorial is a method of transferring knowledge and may be used as a part of a learning process. More interactive and specific than a book or a lecture; a tutorial seeks to teach by example and supply the information to complete a certain task.

What did his how to skip out on here?
 
i gave up making this a tutorial. But i polished it with up to date Scripts. (leaving out the newest NPC brain im testing on my server atm)
I hope it works.
 
I really enjoyed this thread =)

Just wanted to say nice script man thanks
 

2 guys a party, one do the most damage, the other get the last hit. Only one monster is counted twice. I'm trying something here based on your onKill creaturescript and got that problem.
 
2 guys a party, one do the most damage, the other get the last hit. Only one monster is counted twice. I'm trying something here based on your onKill creaturescript and got that problem.
i moved the task counter to onDeath creaturescript.

too tired to check is the party function working correctly on post 1.
Posted the one I have currently in my compat.lua
Code:
function getPartyMembers(player, distance) -- finds all party members in the distance or lower
local party = player:getParty()
local partyMembers = {}

    if party then
        table.insert(partyMembers, party:getLeader():getId())
        for _, member in ipairs(party:getMembers()) do
            if distance then
                if getDistanceBetween(player:getPosition(), Player(member:getId()):getPosition()) < distance then
                    table.insert(partyMembers, member:getId())
                end
            else
                table.insert(partyMembers, member:getId())
            end
        end
    else
        table.insert(partyMembers, player:getId())
    end
return partyMembers
end
 
Last edited:
i moved the task counter to onDeath creaturescript.
Any chance to post it? I had to change a lot of stuff, since party:getMembers() don't get the leader, and you where counting the lasthitter twice. I'm sure it will be much more complex, since you need to handle a higher number of situations not contemplated by your first draft.
 
You registered the event for each creature?
with notepad++ and p much all good text editors u can add some lines to all of your monsters but using onkill is best i suppose no need to add anything in monsters then

and rly nice function for party members whitevo, i will add it to my compat xD
 
yes. (easy for me since I got total 13 monsters xD)
You can register the effect on hit too though.
What you mean, how would you do that?

with notepad++ and p much all good text editors u can add some lines to all of your monsters but using onkill is best i suppose no need to add anything in monsters then

and rly nice function for party members whitevo, i will add it to my compat xD

How would you handle this:
2 guys a party, one do the most damage, the other get the last hit. Only one monster is counted twice. I'm trying something here based on your onKill creaturescript and got that problem.
 
im not entirely sure what this means
"2 guys a party, one do the most damage, the other get the last hit. Only one monster is counted twice. "

u want all players in party should get the kill? because just use whitevos function for that.

or only the guy that did the most damage to the monsters and the guy who last hitted the

or is there some error that it counts kills twice?
 
im not entirely sure what this means
"2 guys a party, one do the most damage, the other get the last hit. Only one monster is counted twice. "

u want all players in party should get the kill? because just use whitevos function for that.
or only the guy that did the most damage to the monsters and the guy who last hitted the
onKill event is triggered by both the last hitter and the most damage dealer, if both are in the same party they will be rewarded twice, as the entire party.
 
onKill event is triggered by both the last hitter and the most damage dealer, if both are in the same party they will be rewarded twice, as the entire party.

ahh i understand now, in 0.4 there was a lasthit parameter that could solve this issue but seems its removed from 1.x
so yeah ondeath should be easiest solution.
there's also 1 sneaky solution @zbisu did: https://otland.net/threads/tfs-1-1-extra-loot-system.230102/
in events he added this
Code:
if not self then return true end
if self:isPlayer() and target:isMonster() then
target:registerEvent("extra_loot_d")
end
so when players would attack the monsters it would register the onDeath event onto them.
 
I changed whitevo function a bit.
Code:
function getPartyMembers(player, distance) -- finds all party members in the distance or lower
   local party = player:getParty()
   local partyMembers = {}

  if party then
     if distance then
       if getDistanceBetween(player:getPosition(), party:getLeader():getPosition()) < distance then
         table.insert(partyMembers, party:getLeader():getId())
       end
     else
       table.insert(partyMembers, party:getLeader():getId())
     end
     for _, member in ipairs(party:getMembers()) do
       if distance then
         if getDistanceBetween(player:getPosition(), Player(member:getId()):getPosition()) < distance then
           table.insert(partyMembers, member:getId())
         end
       else
         table.insert(partyMembers, member:getId())
       end
     end
   else
     table.insert(partyMembers, player:getId())
   end

   return partyMembers
end
and went with this
Code:
local config = {
    ['troll'] = {amount = 80, storage = 1000, startstorage = 1001, startvalue = 1, mission = 'trolls', creature = 'troll'},
}

function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)

   local monster = config[creature:getName():lower()]
   if creature:isPlayer() or not monster or creature:getMaster() then
     return true
   end

   local partyMembers = getPartyMembers(killer, 9)
   local rewardDamage = true
 
   for x=1, #partyMembers do
     local partyMember = Player(partyMembers[x])
     local stor = partyMember:getStorageValue(monster.storage)+1
     if (stor+1) < monster.amount and partyMember:getStorageValue(monster.startstorage) == monster.startvalue then
       partyMember:setStorageValue(monster.storage, stor)
       partyMember:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, ''..(stor+1)..' out of '..monster.amount..' '..monster.creature..'s killed.')
     end
     if (stor+1) == monster.amount and partyMember:getStorageValue(monster.startstorage) == monster.startvalue then
       partyMember:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations, you have killed '..(stor+1)..' '..monster.creature..'s and completed the '..monster.mission..' mission.')
       partyMember:setStorageValue(monster.storage, stor)
       partyMember:setStorageValue(monster.startstorage, monster.startvalue+1)
     end
     if partyMember:getId() == mostDamageKiller:getId() then
       rewardDamage = false
     end
   end
 
   if rewardDamage == true then
     local partyMembers = getPartyMembers(mostDamageKiller, 9)
     for x=1, #partyMembers do
       local partyMember = Player(partyMembers[x])
       local stor = partyMember:getStorageValue(monster.storage)+1
       if (stor+1) < monster.amount and partyMember:getStorageValue(monster.startstorage) == monster.startvalue then
         partyMember:setStorageValue(monster.storage, stor)
         partyMember:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, ''..(stor+1)..' out of '..monster.amount..' '..monster.creature..'s killed.')
       end
       if (stor+1) == monster.amount and partyMember:getStorageValue(monster.startstorage) == monster.startvalue then
         partyMember:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations, you have killed '..(stor+1)..' '..monster.creature..'s and completed the '..monster.mission..' mission.')
         partyMember:setStorageValue(monster.storage, stor)
         partyMember:setStorageValue(monster.startstorage, monster.startvalue+1)
       end
     end
   end

   return true
 
end
Opened all monsters with notepad++, replaced </flags> with
Code:
</flags><script><event name="TaskDeath"/></script>
 
Last edited:
kinda awkward that I overlooked something like that for so long xD (never bothered to look the function again after I made it)

untested, but here is the new party member function:
Code:
function getPartyMembers(player, distance) -- finds all party members in the distance or lower
local party = player:getParty()
local partyMembers = {}

    if party then
        local playerPos = player:getPosition()
        table.insert(party, party:getLeader())
        for _, member in ipairs(party:getMembers()) do
            if distance then
                if getDistanceBetween(playerPos, member:getPosition()) < distance then
                    table.insert(partyMembers, member:getId())
                end
            else
                table.insert(partyMembers, member:getId())
            end
        end
    else
        table.insert(partyMembers, player:getId())
    end
return partyMembers
end
 
kinda awkward that I overlooked something like that for so long xD (never bothered to look the function again after I made it)

untested, but here is the new party member function:
Code:
function getPartyMembers(player, distance) -- finds all party members in the distance or lower
local party = player:getParty()
local partyMembers = {}

    if party then
        local playerPos = player:getPosition()
        table.insert(party, party:getLeader())
        for _, member in ipairs(party:getMembers()) do
            if distance then
                if getDistanceBetween(playerPos, member:getPosition()) < distance then
                    table.insert(partyMembers, member:getId())
                end
            else
                table.insert(partyMembers, member:getId())
            end
        end
    else
        table.insert(partyMembers, player:getId())
    end
return partyMembers
end

Dude, that stills don't check for Leader distance before adding it to the table. I want to thank you for sharing your code and also the solution to my problem, helped a lot!
 
Dude, that stills don't check for Leader distance before adding it to the table. I want to thank you for sharing your code and also the solution to my problem, helped a lot!
How about now?

Code:
function getPartyMembers(player, distance) -- finds all party members in the distance or lower
local party = player:getParty()
local partyMembers = {}

    if party then
        local playerPos = player:getPosition()
        local entireParty = party:getMembers()
        table.insert(entireParty, party:getLeader())
        for _, member in ipairs(entireParty) do
            if distance then
                if getDistanceBetween(playerPos, member:getPosition()) < distance then
                    table.insert(partyMembers, member:getId())
                end
            else
                table.insert(partyMembers, member:getId())
            end
        end
    else
        table.insert(partyMembers, player:getId())
    end
return partyMembers
end
 
Back
Top