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

Lua Quest chest help

darkangel1

New Member
Joined
Oct 31, 2023
Messages
53
Reaction score
4
Lua:
--[[

    Anni-style chests.
  
    This script goes into data/scripts as a .lua file

    1) Place 2+ chests into map editor
    2) Place Same ActionId onto all chests. (example: 45000)
    3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
    4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
    5) Update table with itemId's, count's and an unused storage number
    6) Restart Server, and test

]]--

local index = rewardChests[ActionId] = {
----[actionId] = {
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    storage = #####
----},
    [45000] = {
        [45001] = {itemId = 2190, count = 1},
        storage = 45000
    },
    [45002] = {
        [45003] = {itemId = 2191, count = 1},
        storage = 45002
    }
}

local anni_style_chest = Action()

function anni_style_chest.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChests[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
  
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local reward = ItemType(index.itemId)
    local rewardWeight = reward:getWeight() * index.count
    if rewardWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
        return true
    end
  
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
  
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
    return true
end

for v, k in pairs(rewardChests) do
    anni_style_chest:aid(v)
end
anni_style_chest:register()
121313.png
 
Lua:
--[[

    Anni-style chests.
 
    This script goes into data/scripts as a .lua file

    1) Place 2+ chests into map editor
    2) Place Same ActionId onto all chests. (example: 45000)
    3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
    4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
    5) Update table with itemId's, count's and an unused storage number
    6) Restart Server, and test

]]--

local index = rewardChests[ActionId] = {
----[actionId] = {
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    storage = #####
----},
    [45000] = {
        [45001] = {itemId = 2190, count = 1},
        storage = 45000
    },
    [45002] = {
        [45003] = {itemId = 2191, count = 1},
        storage = 45002
    }
}

local anni_style_chest = Action()

function anni_style_chest.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChests[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
 
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local reward = ItemType(index.itemId)
    local rewardWeight = reward:getWeight() * index.count
    if rewardWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
        return true
    end
 
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
 
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
    return true
end

for v, k in pairs(rewardChests) do
    anni_style_chest:aid(v)
end
anni_style_chest:register()
View attachment 79792
Change line 16 to local rewardChests = {.
I think you could have figured that out though.
 
Last edited:
У вас файл находится не в той директории. Измените местоположение с данные/действия/скрипты на данные/скрипты/действия
New error =D

1213135.png
Post automatically merged:

You have the file in the wrong directory. Change the location from data/actions/scripts to data/scripts/actions
I corrected the script by deleting anni_style_chest
but for some reason only 1 chest works for me, and the rest are empty... Can you tell me what I'm doing wrong?

Lua:
--[[

    Anni-style chests.
  
    This script goes into data/scripts as a .lua file

    1) Place 2+ chests into map editor
    2) Place Same ActionId onto all chests. (example: 45000)
    3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
    4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
    5) Update table with itemId's, count's and an unused storage number
    6) Restart Server, and test

]]--

local rewardChests = {
----[actionId] = {
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    storage = #####
----},
    [45000] = {
        [45001] = {itemId = 2190, count = 1},
        storage = 45000
    },
    [45002] = {
        [45003] = {itemId = 2191, count = 1},
        storage = 45002
    },
    [45004] = {
        [45005] = {itemId = 2399, count = 100},
        storage = 45004
    }
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChests[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
  
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local reward = ItemType(index.itemId)
    local rewardWeight = reward:getWeight() * index.count
    if rewardWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
        return true
    end
  
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
  
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
    return true
end
Post automatically merged:

You have the file in the wrong directory. Change the location from data/actions/scripts to data/scripts/actions
action.xml
Lua:
<action fromid="45000" script="script_starring_weapon.lua" />
 

Attachments

Last edited:
New error =D

View attachment 79800
Post automatically merged:


I corrected the script by deleting anni_style_chest
but for some reason only 1 chest works for me, and the rest are empty... Can you tell me what I'm doing wrong?

Lua:
--[[

    Anni-style chests.
 
    This script goes into data/scripts as a .lua file

    1) Place 2+ chests into map editor
    2) Place Same ActionId onto all chests. (example: 45000)
    3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
    4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
    5) Update table with itemId's, count's and an unused storage number
    6) Restart Server, and test

]]--

local rewardChests = {
----[actionId] = {
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    storage = #####
----},
    [45000] = {
        [45001] = {itemId = 2190, count = 1},
        storage = 45000
    },
    [45002] = {
        [45003] = {itemId = 2191, count = 1},
        storage = 45002
    },
    [45004] = {
        [45005] = {itemId = 2399, count = 100},
        storage = 45004
    }
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChests[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
 
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local reward = ItemType(index.itemId)
    local rewardWeight = reward:getWeight() * index.count
    if rewardWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
        return true
    end
 
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
 
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
    return true
end
Post automatically merged:


action.xml
Lua:
<action fromid="45000" script="script_starring_weapon.lua" />
It wasn't an error, you had added the script using actions.xml, but as you deleted the file from the actions folder, you should have also deleted the mention of it in the actions.xml file, use the script as it was given to you, it may not seem like it, but using revscript makes everything faster and simpler, besides that in a single file you can put everything together.

now about the way you decided to do it, it seems to me that you should use ACTIONID and not ID, so I believe your tag should look like this:
XML:
<action fromaid="45000" toaid="45004" script="script_starring_weapon.lua" />

I could be wrong, but that's the idea, it's been a long time since I've used this means of scripting

Remember to add AID and UID to the chests using MapEditor
 
(For the first script you posted)
You dont want anything in your action.xml, just put the script in data/scripts/actions
And if you want to only be able to use 1 of 3 chests you are configuring it wrong

Lua:
local rewardChests = {
    [45000] = { -- 45000 as Action id on ALL 3 chests
        [45001] = {itemId = 2190, count = 1}, --45001 as UNIQUE id on chest for item 2190
        [45002] = {itemId = 2191, count = 1}, --45002 as UNIQUE id on chest for item 2191
        [45003] = {itemId = 2399, count = 100}, --45003 as UNIQUE id on chest for item 2399
        storage = 45000
    }
}
 
(For the first script you posted)
You dont want anything in your action.xml, just put the script in data/scripts/actions
And if you want to only be able to use 1 of 3 chests you are configuring it wrong

Lua:
local rewardChests = {
    [45000] = { -- 45000 as Action id on ALL 3 chests
        [45001] = {itemId = 2190, count = 1}, --45001 as UNIQUE id on chest for item 2190
        [45002] = {itemId = 2191, count = 1}, --45002 as UNIQUE id on chest for item 2191
        [45003] = {itemId = 2399, count = 100}, --45003 as UNIQUE id on chest for item 2399
        storage = 45000
    }
}
Something doesn't work, all the chests are empty

Lua:
local rewardChests = {
----[actionId] = {
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    storage = #####
----},
    [45000] = { -- 45000 as Action id on ALL 3 chests
        [45001] = {itemId = 2190, count = 1}, --45001 as UNIQUE id on chest for item 2190
        [45002] = {itemId = 2191, count = 1}, --45002 as UNIQUE id on chest for item 2191
        [45003] = {itemId = 2399, count = 100}, --45003 as UNIQUE id on chest for item 2399
        storage = 45000
    }
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChests[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
  
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local reward = ItemType(index.itemId)
    local rewardWeight = reward:getWeight() * index.count
    if rewardWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
        return true
    end
  
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
  
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
    return true
end
 

Attachments

If the script looks like this, add it to data/actions/scripts
and add to action.xml:
Lua:
<action fromuid="45001" touid="45003" script="script_starring_weapon.lua" />
<action actionid="45000" script="script_starring_weapon.lua" />
 
If the script looks like this, add it to data/actions/scripts
and add to action.xml:
Lua:
<action fromuid="45001" touid="45003" script="script_starring_weapon.lua" />
<action actionid="45000" script="script_starring_weapon.lua" />
Very good, it really works, but only if I take throwing star, it gives 1, but I wanted it to give 100
Post automatically merged:

If the script looks like this, add it to data/actions/scripts
and add to action.xml:
Lua:
<action fromuid="45001" touid="45003" script="script_starring_weapon.lua" />
<action actionid="45000" script="script_starring_weapon.lua" />
 

Attachments

Back
Top