• 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 Quest NPC giving item with actionID

arthuraio

Member
Joined
Apr 9, 2015
Messages
123
Reaction score
13
hello forumers,

I normally know how to write a basic quest npc script, but is it possible to make a npc "doplayeradditem" with a special action ID? if yes, how can I do that "special action ID" add a storage if it is used on a certain item (tile).... amm.... I guess this will be simpler if I tell what quest I'm trying to make.


A MEGA similar, almost the same quest, but how the script would look like?
 
Both TFS 1.x
What i did: Item(player:addItem(herbs[tostring("herb "..x)].itemID, 1):getUniqueId()):setActionId(herbs[tostring("herb "..x)].itemAID)
or little simpler to understand: doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 100) --copper key
 
Both TFS 1.x
What i did: Item(player:addItem(herbs[tostring("herb "..x)].itemID, 1):getUniqueId()):setActionId(herbs[tostring("herb "..x)].itemAID)
or little simpler to understand: doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 100) --copper key
The function addItem returns an item userdata, so there is no need to recompile it: https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp#L8940

Code:
local targetItem = player:addItem(itemid)
targetItemid:setActionId(actionid)
 
Both TFS 1.x
What i did: Item(player:addItem(herbs[tostring("herb "..x)].itemID, 1):getUniqueId()):setActionId(herbs[tostring("herb "..x)].itemAID)
or little simpler to understand: doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 100) --copper key

Didn't work.... But thanks.

The function addItem returns an item userdata, so there is no need to recompile it: https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp#L8940

Code:
local targetItem = player:addItem(itemid)
targetItemid:setActionId(actionid)

What? Sorry I didn't understand what you said...

@Topic

Can someone put an example of the script, so I can see what I'm doing wrong? Here is my script:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


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

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if msgcontains(msg, "key") then
        if player:getStorageValue(2455) <= 1 then
            npcHandler:say("oh! Vc estah testando script? NICE! tomara q de certo o/", player)
            npcHandler.topic[cid] = 1
        else
            npcHandler:say("deu certo yay", player)               
        end
    elseif msgcontains(msg, "da logo") then
        if npcHandler.topic[cid] == 1 then
                npcHandler:say("Ah, right! toma saporra.", player)
                player:setStorageValue(2455, 2)
                player:doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 1001) --copper key
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                npcHandler.topic[cid] = 0
        end
    return true
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Didn't work.... But thanks.



What? Sorry I didn't understand what you said...

@Topic

Can someone put an example of the script, so I can see what I'm doing wrong? Here is my script:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end

local player = Player(cid)

if msgcontains(msg, "key") then
if player:getStorageValue(2455) <= 1 then
npcHandler:say("oh! Vc estah testando script? NICE! tomara q de certo o/", player)
npcHandler.topic[cid] = 1
else
npcHandler:say("deu certo yay", player)
end
elseif msgcontains(msg, "da logo") then
if npcHandler.topic[cid] == 1 then
npcHandler:say("Ah, right! toma saporra.", player)
player:setStorageValue(2455, 2)
player:doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 1001) --copper key
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
npcHandler.topic[cid] = 0
end
return true
end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local player = Player(cid)
    if msgcontains(msg, "key") then
        if player:getStorageValue(2455) <= 1 then
            npcHandler:say("oh! Vc estah testando script? NICE! tomara q de certo o/", player)
            npcHandler.topic[cid] = 1
        else
            npcHandler:say("deu certo yay", player) 
        end
    elseif msgcontains(msg, "da logo") then
        if npcHandler.topic[cid] == 1 then
            npcHandler:say("Ah, right! toma saporra.", player)
            player:setStorageValue(2455, 2)
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
           
            local key = player:addItem(2089, 1)
            key:setActionId(1001) --copper key
           
            npcHandler.topic[cid] = 0 
        end
        return true
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
player:doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 1001) --copper key

Such function does not exist like player:doSetItemActionId | player:addItem does.

if you want to use the function doSetItemActionId then. the player metatable has to be mentioned as parameter inside the function.

this is your main function: You have player metatable inside it. cid
function creatureSayCallback(cid, type, msg)
Use that same parameter inside the function
doSetItemActionId(doPlayerAddItem(cid, itemId, itemCount), itemActionId)
 
Last edited:
player:doSetItemActionId(doPlayerAddItem(cid, 2089, 1), 1001) --copper key

Such function does not exist like player:doSetItemActionId | player:addItem does.

if you want to use the function doSetItemActionId then. the player metatable has to be mentioned as parameter inside the function.

this is your main function: You have player metatable inside it. cid
function creatureSayCallback(cid, type, msg)
Use that same parameter inside the function doSetItemActionId(cid, itemId, itemCount), itemActionId)

NPC functions does not return userdata values, they still return the cid value insted, due to that we still use Player(cid).
doSetItemActionId does not require the cid value, it requires the item's unique id value, the new function item:setActionId() uses the userdata value insted, that it gets from the player:addItem() function.

Also noticed now that you used the spoiler insted of [.code]code[/.code] without the dots, you have to replace:
Code:
:eek:

For
Code:
:o
 
NPC functions does not return userdata values, they still return the cid value insted, due to that we still use Player(cid).
doSetItemActionId does not require the cid value, it requires the item's unique id value, the new function item:setActionId() uses the userdata value insted, that it gets from the player:addItem() function.

Also noticed now that you used the spoiler insted of [.code]code[/.code] without the dots, you have to replace:
Code:
:eek:

For
Code:
:o
I know im typo master. going to fix them now.
And metadata ~= userdata
 
Hey guys, got it to work, both were right, I just combined what you guys said and it's workin.

Now please help me with the second part of the quest... I need to use the item that the NPC gave me on a specific item tile, like using fishing rod on the water. BUT the item that the NPC gave must be removed on use, as also giving the next level of the same storage.
 
Last edited:
If I understand correctly, you want to use the item from the npc on a specific tile. When this happens, remove the item from the npc. Set storage value one higher. If that's the case, perhaps something like this:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local targetId = target.itemid
local tile = xxxx
    if targetId ~= tile then then
        return false
    end
player:removeItem(item)
player:setStorageValue(YOUR_STORAGE, player:getStorageValue(YOUR_STORAGE) + 1)
return true
end
 
If I understand correctly, you want to use the item from the npc on a specific tile. When this happens, remove the item from the npc. Set storage value one higher. If that's the case, perhaps something like this:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local targetId = target.itemid
local tile = xxxx
    if targetId ~= tile then then
        return false
    end
player:removeItem(item)
player:setStorageValue(YOUR_STORAGE, player:getStorageValue(YOUR_STORAGE) + 1)
return true
end

Don't I have to specify the actionID set on the "npc item"? I don't want to every "itemID npc's item" have the same effect. Only the one with the actionID. That's my question... =)

Amm... To make it simple,

I want to use the item with the actionID 1234 on an item 8000 (example), and after using, the item with actionID 1234 is removed and setStorageValue = ([queststorage]+1). But this will only work if the said item with actionID has THAT actionID or else nothing happens even if the same "actionID item" without actionID is used.
 
Last edited:
in actions.xml:
Code:
<action actionid="1234" script="your_script.lua"/>
in your_script.lua:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local targetId = target.itemid
local tile = 8000
if targetId ~= tile then then
return false
end
player:removeItem(item)
player:setStorageValue(YOUR_STORAGE, player:getStorageValue(YOUR_STORAGE) + 1)
return true
end

This will only work with an item that has action id 1234. If the item does not have actionid 1234, the script will not run at all and so it won't remove the wrong item.

Code:
local tile = 8000
if targetId ~= tile then then
return false
end
This ensures that if the tile is not item id 8000, it will end the function returning false, so it won't run the things after it.
 
Back
Top