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

[7.72] OTHire 0.0.1b - Based in OTServ Trunk (Latest)

I have made a task system, but can't place/load the npc because theres still a misstake in the npc's.lua

data/npc/scripts/tasknpc_rook.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- actual task monster id is stored in 46999, kill count is stored in 47000
-- if task is done monster storage value+1000 is 1 if the task has been rewarded it is 2
local monsters = {
    ["rat"] = 47001,
    ["troll"] = 47002,
}

local reqKills = {
    ["rat"] = 3,
    ["troll"] = 5,
}

-- reward array
-- reward monster = { exp, gold, itemsrewardedamount -> item[0]id, item[0]amount, item[0]stackable ... }
local reward = {
    ["rat"] = { 4000, 1000, 1, 2400, 1, 0 },
    ["troll"] = { 2000, 3000, 1, 2147, 30, 1 }
}

-- OTServ event handling functions start
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 talkState = {}
local Mob = {}

npcHandler:setMessage(MESSAGE_FAREWELL, "Come back in one piece!")

function onPlayerGreet(cid)
    npcHandler:setMessage(MESSAGE_GREET, "Hey |PLAYERNAME|. What do you need?")
    return true
end

npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "Hey, |PLAYERNAME|. Wait some, okay?")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Yeah, run... Go ahead and run away like the chicken that you are!")

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end
  
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, "job") then
        npcHandler:say("I'm sitting on welfare money, bitch.")
        talkState[talkUser] = 0
        return true
    end
    if msgcontains(msg, "name") then
        npcHandler:say("How about I ask for your mother's name, faggot.")
        talkState[talkUser] = 0
        return true
    end
    -- task stuff
    if msgcontains(msg, "list") then
        npcHandler:say("Following monster populations must be decreased: rats, trolls.")
        talkState[talkUser] = 0
        return true
    end
    if msgcontains(msg, "task") then
        npcHandler:say("Which task would you like to do?")
        talkState[talkUser] = 1
        return true
    end
    if msgcontains(msg, "reward") then
        npcHandler:say("Did you finish your task?")
        talkState[talkUser] = 3
        return true
    end
    -- we asked to do a task, now need to tell the monster name
    if (talkState == 1) then
        local task = string.lower(msg)
        local monster = monsters[task]
      
        if (monster) then
            npcHandler:say("Would you like to hunt down " .. reqKills[monster] .. " " .. task .. "s?")
            talkState[talkUser] = 2
            Mob[talkUser] = monster
        end
        else
            npcHandler:say("There is no " .. task .. "s task available. You can ask me for a list of monsters that need to be slain.")
            talkState[talkUser] = 0
            Mob[talkUser] = 0
        end
        return true
    end
    -- been asked if you really want to hunt that monster
    if msgcontains(msg, "yes") and (talkState == 2) then
        if (getPlayerStorageValue(cid, Mob) <= 0) then
            if (getPlayerStorageValue(cid, 46999) <= 47000) then
                setPlayerStorageValue(cid, 46999, Mob)
                setPlayerStorageValue(cid, 47000, 0)
                setPlayerStorageValue(cid, Mob, 0)
                npcHandler:say("Good luck on your hunt!")
          
        end
        if (getPlayerStorageValue(cid, Mob) == 1) then
            npcHandler:say("If you want your reward for your completed task just ask me for it.")
        end
        if (getPlayerStorageValue(cid, Mob) == 2) then
            npcHandler:say("You already did that task and got rewarded for it.")
        end
        else
            npcHandler:say("TASK SYSTEM ERROR: Please contact a GM with a detailed explanation!")
        end
        talkState[talkUser] = 0
        Mob[talkUser] = 0
        return true
    end
    if msgcontains(msg, "no") and (talkState == 2) then
        npcHandler:say("Forget about it then...")
        talkState[talkUser] = 0
        Mob[talkUser] = 0
        return true
    end
    -- asked for a reward, been asked if we finished our task
    if msgcontains(msg, "yes") and (talkState == 2) then
        local completed = getPlayerStorageValue(cid, 46999)
        doPlayerAddExp(cid, reward[completed][0])
        doPlayerAddMoney(cid, reward[completed][1])
        if (reward[completed][2] == 1) then
            if (reward[completed][5] == 0) then
                doPlayerAddItem(cid, reward[completed][3], 1)
              
            else
                doPlayerAddItem(cid, reward[completed][3], reward[completed][4])
          
        end
        npcHandler:say("Okay, let me give you a reward for your efforts...")
        setPlayerStorageValue(cid, completed, 2)
        setPlayerStorageValue(cid, 46999, 0)
        setPlayerStorageValue(cid, 47000, 0)
        talkState[talkUser] = 0
        return true
    end
    if msgcontains(msg, "no") and (talkState == 2) then
        npcHandler:say("Go on and finish your task then...")
        talkState[talkUser] = 0
        return true
    end
    -- task stuff end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

local focus = FocusModule:new()
npcHandler:addModule(focus)

and the creature script that goes along:
data/creaturescripts/scripts/task_kill.lua
Code:
-- actual task monster id is stored in 46999, kill count is stored in 47000
-- if task is done monster storage value+1000 is 1 if the task has been rewarded it is 2
local monsters = {
    ["cave rat"] = 47001,
    ["troll"] = 47002,
    ["orc"] = 47003,
    ["rotworm"] = 47004,
}

local reqKills = {
    ["cave rat"] = 3,
    ["troll"] = 30,
    ["orc"] = 30,
    ["rotworm"] = 150,
}

function onKill(cid, target)
    if(isPlayer(target) ~= TRUE) then
        local name = getCreatureName(target)
        local monster = monsters[string.lower(name)]
        local actual = getPlayerStorageValue(cid, 46999)
      
        if(actual and monster) then
            local kills = getPlayerStorageValue(cid, 47000)
          
            if(kills == -1) then
                kills = 1
            end
          
            if(kills >= 1) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You've killed " .. killedMonsters .. " out of " .. reqKills[string.lower(name)] .. " " .. name .. "s.")
                setPlayerStorageValue(cid, 47000, kills + 1)
                if(kills > reqKills[string.lower(name)]) then
                    setPlayerStorageValue(cid, monster+1000, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You have killed enough " .. name .. "s.")
                end
            end
        end
    end
    return true
end

Note: This was my first attempt for the task stuff and if I remember correctly there's an error when I tried to summon the npc, the console said something like: Expected string but got nil @ some function #of keywordhandler...
If anyone is quick to find and fix the misstake this system should work...
 
Well the problem is I dont know where the problem is, I am quite new to programming and this is my first lua attempt so I kinda got a bad overview in otserv still
 
But a friend of me sended me the fix code, thanks @Vanderlay

In game.cpp, find the function
Code:
bool Game::combatChangeHealth(CombatType_t combatType, MagicEffectClasses customHitEffect, TextColor_t customTextColor, Creature* attacker, Creature* target, int32_t healthChange)

Below that lines:
Code:
const Position& targetPos = target->getPosition();
const SpectatorVec& list = getSpectators(targetPos);

Add this:
Code:
    Player* targetPlayer = target->getPlayer();
    Player* attackerPlayer;
  
    if (attacker) {
        attackerPlayer = attacker->getPlayer();
    } else {
        attackerPlayer = nullptr;
    }

    if(!attackerPlayer && !targetPlayer) {
        return false;
    }

Enjoy it ;)
 
Did you guys stopped with this project ??

Another thing that I noticed in that engine:

* Monster can damage other monsters, that's not the correct, they can't damage other monsters

Where do you get these facts of monsters not damaging each other? Like really.
 
That feature of monsters damaging each other isn't cool, if you gonna make a easy/hard quest with alot of monsters, you'll not have so much problem to kill then, since they do that job.

Quest Example: Demon Helmet Quest (Demons can kill Banshee)
 
That feature of monsters damaging each other isn't cool, if you gonna make a easy/hard quest with alot of monsters, you'll not have so much problem to kill then, since they do that job.

Quest Example: Demon Helmet Quest (Demons can kill Banshee)

Why do you even say that now? You already said "that's not the correct, they can't damage other monsters"
 
If someone need it, here's all lua functions (from luascript.cpp)

Code:
getOTSYSTime()
getConfigValue(key)
getPlayerFood(cid)
getPlayerMana(cid)
getPlayerMaxMana(cid)
getPlayerLevel(cid)
getPlayerMagLevel(cid)
getPlayerAccess(cid)
getPlayerSkill(cid, skillid)
getPlayerMasterPos(cid)
getPlayerTown(cid)
getPlayerVocation(cid)
getPlayerItemCount(cid, itemid, subtype)
getPlayerSoul(cid)
getPlayerFreeCap(cid)
getPlayerIp()
getCreatureLight(cid)
getCreatureLookDir(cid)
getPlayerSlotItem(cid, slot)
getPlayerItemById(cid, deepSearch, itemId, <optional> subType)
getPlayerDepotItems(cid, depotid)
getPlayerGuildId(cid)
getPlayerGuildName(cid)
getPlayerGuildRank(cid)
getPlayerGuildNick(cid)
getPlayerGuildLevel(cid)
getPlayerSex(cid)
getPlayerGUID(cid)
getPlayerNameByGUID(guid)
getPlayerFlagValue(cid, flag)
getPlayerLossPercent(cid, lossType)
getPlayerPremiumDays(cid)
getPlayerSkullType(cid, <optional> viewer)
setPlayerSkullType(cid, skull_type)
getPlayerSkullEndTime(cid)
getPlayerUnjustKills(cid)
getPlayerAccountBalance(cid)
getPlayerByNameWildcard(name)
playerLearnInstantSpell(cid, name)
canPlayerLearnInstantSpell(cid, name)
getPlayerLearnedInstantSpell(cid, name)
getPlayerInstantSpellInfo(cid, index)
getPlayerInstantSpellCount(cid)
getInstantSpellInfoByName(cid, name)
getInstantSpellWords(name)
getPlayerStorageValue(cid, valueid)
setPlayerStorageValue(cid, valueid, newvalue)
doErasePlayerStorageValue(cid, valueid)
isPremium(cid)
getPlayerLastLogin(cid)
getGlobalStorageValue(valueid)
setGlobalStorageValue(valueid, newvalue)
doEraseGlobalStorageValue(valueid)
doErasePlayerStorageValueByName(name, key)
setPlayerStorageValueByName(name, key, newValue)
getPlayerStorageValueByName(name, key)
getTilePzInfo(pos)
getTileHouseInfo(pos)
getItemRWInfo(uid)
getThingDefaultDescription(uid, lookDistance, <optional> canSeeXRay)
getItemTypeDefaultDescription(itemid, <optional> count)
getItemSpecialDescription(uid)
getThingFromPos(pos)
getThing(uid)
queryTileAddThing(uid, pos, <optional> flags)
getThingPos(uid)
getTileStackItemsSize(pos)
getTileItemById(pos, itemId, <optional> subType)
getTileItemByType(pos, type)
getTileThingByPos(pos)
getTileThingByTopOrder(pos, topOrder)
getTopCreature(pos)
getAllCreatures(pos, <optional> flag)
getWaypointPositionByName(name)
doRemoveItem(uid, <optional> count)
doPlayerFeed(cid, food)
doPlayerSendCancel(cid, text)
doPlayerSendDefaultCancel(cid, ReturnValue)
doPlayerSetIdleTime(cid, time, warned)
doTeleportThing(uid, newpos)
doTransformItem(uid, toitemid, <optional> count/subtype)
doCreatureSay(cid, text, type)
doSendMagicEffect(pos, type[, player])
doSendDistanceShoot(frompos, topos, type)
doChangeTypeItem(uid, newtype)
doSetItemActionId(uid, actionid)
doSetItemText(uid, text)
doSetItemSpecialDescription(uid, desc)
doSendAnimatedText(pos, text, color)
doPlayerAddInFightTicks(cid, ticks, <optional: default: 0> pzLock)
doPlayerAddSkillTry(cid, skillid, n, <optional: default: 0> useMultiplier)
doPlayerAddManaSpent(cid, mana, <optional: default: 0> useMultiplier)
doCreatureAddHealth(cid, health, <optional: default: 1> filter))
doPlayerAddMana(cid, mana, <optional: default: 1> withoutAnimation)
doPlayerAddSoul(cid, soul)
doPlayerAddItem(uid, itemid, <optional: default: 1> count/subtype)
doPlayerAddItem(cid, itemid, <optional: default: 1> count, <optional: default: 1> canDropOnMap, <optional: default: 1>subtype)
doPlayerAddItemEx(cid, uid, <optional: default: 0> canDropOnMap, <optional> slot)
doPlayerSendTextMessage(cid, MessageClasses, message)
doPlayerRemoveMoney(cid, money)
doPlayerAddMoney(cid, money)
doPlayerWithdrawMoney(cid, money)
doPlayerDepositMoney(cid, money)
doPlayerTransferMoneyTo(cid, target, money)
doShowTextWindow(cid, maxlen, canWrite)
doShowTextDialog(cid, itemid, text)
getTownIdByName(townName)
getTownNameById(townId)
getTownTemplePosition(townId)
doDecayItem(uid)
doCreateItem(itemid, <optional> type/count, pos)
Returns uid of the created item, only works on tiles.
doCreateItemEx(itemid, <optional> count/subtype)
doTileAddItemEx(pos, uid)
doAddContainerItemEx(uid, virtuid)
doRelocate(pos, posTo, <optional: default: false> moveUnmoveable, <optional: default: 0> maxAmount)
doCreateTeleport(teleportID, positionToGo, createPosition)
doSummonCreature(name, pos, <optional> extendedPosition, <optional> forceSpawn)
doPlayerSummonCreature(cid, name, pos, <optional> extendedPosition, <optional> forceSpawn)
doRemoveCreature(cid)
doMoveCreature(cid, direction, <optional>flags)
doSetCreatureDirection(cid, direction)
doPlayerSetMasterPos(cid, pos)
doPlayerSetTown(cid, townid)
doPlayerSetVocation(cid, voc)
doPlayerSetSex(cid, sex)
doPlayerRemoveItem(cid, itemid, count, <optional> subtype, <optional> ignoreEquipped)
doPlayerAddExp(cid, exp, <optional: default: 0> useRate, <optional: default: 0> useMultiplier)
doPlayerRemoveExp(cid, exp, <optional: default: 0> useRate, <optional: default: 0> useMultiplier)
getPlayerExperience(cid)
doPlayerSetGuildRank(cid, rank)
doPlayerSetGuildNick(cid, nick)
doSetCreatureLight(cid, lightLevel, lightColor, time)
doPlayerSetLossPercent(cid, lossType, newPercent)
doSetCreatureDropLoot(cid, doDrop)
isValidUID(uid)
isCreatureImmuneToCondition(cid, conditionType)
isCreature(cid)
isItemTwoHandedByUID(uid)
isItemTwoHanded(uid)
isContainer(uid)
isCorpse(uid)
isMoveable(uid)
getPlayerGUIDByName(name)
registerCreatureEvent(uid, eventName)
getContainerSize(uid)
getContainerCap(uid)
getContainerItem(uid, slot)
doAddContainerItem(uid, itemid, <optional> count/subtype)
getDepotId(uid)
getHouseOwner(houseid)
getHouseName(houseid)
getHouseEntry(houseid)
getHouseRent(houseid)
getHouseTown(houseid)
getHouseAccessList(houseid, listid)
getHouseByPlayerGUID(playerGUID)
getHouseTilesSize(houseid)
getHouseDoorCount(houseid)
getHouseBedCount(houseid)
isHouseGuildHall(houseid)
setHouseAccessList(houseid, listid, listtext)
setHouseOwner(houseid, ownerGUID)
getHouseList(townid)
cleanHouse(houseid)
getWorldType()
getWorldTime()
getWorldLight()
getWorldCreatures(type) -- 0 players, 1 monsters, 2 npcs, 3 all
getWorldUpTime()
getPlayersOnlineList()
doPlayerBroadcastMessage(cid, message)
getGuildId(guild_name)
setCombatArea(combat, area)
setCombatCondition(combat, condition)
setCombatParam(combat, key, value)
setConditionParam(condition, key, value)
addDamageCondition(condition, rounds, time, value)
addOutfitCondition(condition, lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet)
setCombatCallBack(combat, key, function_name)
setCombatFormula(combat, type, mina, minb, maxa, maxb)
setConditionFormula(combat, mina, minb, maxa, maxb)
doCombat(cid, combat, param)
doAreaCombatHealth(cid, type, pos, area, min, max, effect)
doTargetCombatHealth(cid, target, type, min, max, effect)
doAreaCombatMana(cid, pos, area, min, max, effect)
doTargetCombatMana(cid, target, min, max, effect)
doAreaCombatCondition(cid, pos, area, condition, effect)
doTargetCombatCondition(cid, target, condition, effect)
doAreaCombatDispel(cid, pos, area, type, effect)
doTargetCombatDispel(cid, target, type, effect)
doChallengeCreature(cid, target)
doConvinceCreature(cid, target)
getMonsterTargetList(cid)
getMonsterFriendList(cid)
doSetMonsterTarget(cid, target)
doMonsterChangeTarget(cid)
doAddCondition(cid, condition)
doRemoveCondition(cid, type, <optional> subId)
doChangeSpeed(cid, delta)
doCreatureChangeOutfit(cid, outfit)
doSetMonsterOutfit(cid, name, time)
doSetItemOutfit(cid, item, time)
doSetCreatureOutfit(cid, outfit, time)
getCreatureOutfit(cid)
getCreaturePosition(cid)
getCreatureName(cid)
getCreatureSpeed(cid)
getCreatureBaseSpeed(cid)
getCreatureTarget(cid)
getCreatureHealth(cid)
getCreatureMaxHealth(cid)
getCreatureByName(name)
getCreatureMaster(cid)
returns the creature's master or itself if the creature isn't a summon
getCreatureSummons(cid)
returns a table with all the summons of the creature
getSpectators(centerPos, rangex, rangey, multifloor)
getPartyMembers(cid)
hasCondition(cid, conditionid)
hasProperty(uid)
isItemStackable(itemid)
isItemRune(itemid)
isItemDoor(itemid)
isItemContainer(itemid)
isItemFluidContainer(itemid)
isItemMoveable(itemid)
getItemName(itemid)
getItemDescriptions(itemid)
getItemWeight(uid)
getItemIdByName(name)
isSightClear(fromPos, toPos, floorCheck)
getFluidSourceType(type)
isIntegerInArray(array, value)
addEvent(callback, delay, ...)
stopEvent(eventid)
addPlayerBan(playerName = 0xFFFFFFFF[, length = 0[, admin = 0[, comment = "No comment"]]])
addAccountBan(accounNumber = 0xFFFFFFFF[, length = 0[, admin = 0[, comment = "No comment"]]])
addIPBan(ip[, mask = 0xFFFFFFFF[, length = 0[, admin = 0[, comment = "No comment"]]]])
removePlayerBan(playerName)
removeAccountBan(account)
removeIPBan(ip[, mask])
getPlayerBanList()
getAccountBanList()
getIPBanList()
getPlayerByAccountNumber(account)
getPlayerAccountId(cid)
getAccountNumberByPlayerName(name)
getIPByPlayerName(name)
getPlayersByIPNumber(ip)
getDataDir()
doPlayerSetRate(cid, type, value)
doPlayerSetVipLimit(cid, quantity)
doPlayerSetDepotLimit(cid, quantity)
isPzLocked(cid)
doSaveServer(payHouses)
doSetGameState(gameState)
doReloadInfo(info)
doRefreshMap()
debugPrint(text)
isMonsterName(name)
isValidItemId(itemid)
isNpcName(name)
getMonsterParameter(name, key)
getNpcParameterByName(name, key)
getItemWeaponType(itemid)
getItemAttack(itemid)
getItemDefense(itemid)
getItemExtraDef(itemid)
getItemArmor(itemid)
getItemWeaponTypeByUID(uid)
getItemAttackByUID(uid)
getItemDefenseByUID(uid)
getItemExtraDefByUID(uid)
getItemArmor(uid)
isGmInvisible(cid)
doPlayerToogleGmInvisible(cid)
doPlayerAddPremiumDays(cid, days)
doPlayerRemovePremiumDays(cid, days)
getFirstItemFromInventory(cid, id/name, <optional> reportError)
getCreatureConditionInfo(cid, conditionType, <optional: default: 0> subId, <optional: default: CONDITIONID_DEFAULT> conditionId)
getCreatureCondition(cid, conditionType, <optional: default: 0> subId, <optional: default: CONDITIONID_DEFAULT> conditionId)
getPlayerModes(cid)
doSavePlayer(cid)
 
i get error all time.. i dont know how solve someoone can help ?¿
 

Attachments

i get error all time.. i dont know how solve someoone can help ?¿

You're using wrong items.otb from RME.
Please do use this one: http://www.speedy*****malware.localhost/AaJ97/items.otb
 
Back
Top