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

TFS 1.X+ Help with script (HoTa Instruments)

Cloow

Active Member
Joined
May 10, 2010
Messages
1,086
Reaction score
35
Hello, I am once again asking for your Lua scripting support 🙃

I'm trying to figure out whats wrong with this script for the HoTa instruments part and im using TFS 1.3 Nekiro downgrade 8.6.
You need to use the musical instruments in a certain order to get access through the door and if you use an instrument in wrong order it will reset and you receive damage.
The Ancient Tombs Quest, Vashresamun - TibiaWiki


The script loads fine with no errors, and I got no errors while calling its functions either.
Lua:
local config = {
    [2367] = 1,
    [2373] = 2,
    [2370] = 3,
    [2372] = 4,
    [2369] = 5,
    [1241] = 5
}
local storage = 12109

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them wrong, now you must begin with first again!')
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end

    if player:getStorageValue(storage) == targetTable and targetTable < 4 then
        player:setStorageValue(storage, math.max(1, player:getStorageValue(storage)) + 1)
        fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
    else
        player:setStorageValue(storage, 5)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them in correct order and got the access through door!')
    end

    if item.itemid == 1241 and player:getStorageValue(storage) == 5 then
        player:teleportTo(toPosition, true)
        item:transform(item.itemid + 1)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You first must play the instruments in correct order to get the access!")
    end
    return true
end


This part seems to work fine:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them wrong, now you must begin with first again!')
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end

Heres the part that I suspect smth wrong:
Lua:
    if player:getStorageValue(storage) == targetTable and targetTable < 4 then
        player:setStorageValue(storage, math.max(1, player:getStorageValue(storage)) + 1)
        fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
    else
        player:setStorageValue(storage, 5)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them in correct order and got the access through door!')
    end

especially this, if I have storage "config[item.itemid]" and "config[item.itemid]" < 4 ?? I don't know how this is even supposed to work but somehow I need to call the storage values for each itemid and thats what im stuck on and can't figure out how.
Lua:
 if player:getStorageValue(storage) == targetTable and targetTable < 4 then




As you can see in this gif it's like the script just jumps over the part I mentioned above

probmehota.gif
 
Last edited:
Solution
😍😍Thank you!

It works as intended I did a small change tho

Changed this:
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Script setup incorrectly. Contact GM.")
        return true
    end

To:
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You played them wrong, now you must begin with first again!")
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end
so it resets the procedure when the player use the wrong instrument
else everything perfect !



What is...
Hello, I am once again asking for your Lua scripting support 🙃

I'm trying to figure out whats wrong with this script for the HoTa instruments part and im using TFS 1.3 Nekiro downgrade 8.6.
You need to use the musical instruments in a certain order to get access through the door and if you use an instrument in wrong order it will reset and you receive damage.
The Ancient Tombs Quest, Vashresamun - TibiaWiki


The script loads fine with no errors, and I got no errors while calling its functions either.
Lua:
local config = {
    [2367] = 1,
    [2373] = 2,
    [2370] = 3,
    [2372] = 4,
    [2369] = 5,
    [1241] = 5
}
local storage = 12109

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them wrong, now you must begin with first again!')
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end

    if player:getStorageValue(storage) == targetTable and targetTable < 4 then
        player:setStorageValue(storage, math.max(1, player:getStorageValue(storage)) + 1)
        fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
    else
        player:setStorageValue(storage, 5)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them in correct order and got the access through door!')
    end

    if item.itemid == 1241 and player:getStorageValue(storage) == 5 then
        player:teleportTo(toPosition, true)
        item:transform(item.itemid + 1)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You first must play the instruments in correct order to get the access!")
    end
    return true
end


This part seems to work fine:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them wrong, now you must begin with first again!')
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end

Heres the part that I suspect smth wrong:
Lua:
    if player:getStorageValue(storage) == targetTable and targetTable < 4 then
        player:setStorageValue(storage, math.max(1, player:getStorageValue(storage)) + 1)
        fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
    else
        player:setStorageValue(storage, 5)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You played them in correct order and got the access through door!')
    end

especially this, if I have storage "config[item.itemid]" and "config[item.itemid]" < 4 ?? I don't know how this is even supposed to work but somehow I need to call the storage values for each itemid and thats what im stuck on and can't figure out how.
Lua:
 if player:getStorageValue(storage) == targetTable and targetTable < 4 then




As you can see in this gif it's like the script just jumps over the part I mentioned above

View attachment 56783
Try this.

I changed it quite a bit.. so uhh, sorry about that.
Lua:
local config = {
    [2367] = 1,
    [2373] = 2,
    [2370] = 3,
    [2372] = 4,
    [2369] = 5
}
local storage = 12109

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

	local currentStorageValue = player:getStorageValue(storage)
	currentStorageValue = currentStorageValue == -1 and 0 or currentStorageValue
	
	-- if using door
	if item.itemid == 1241 then
		if currentStorageValue == 5 then
			player:teleportTo(toPosition, true)
			item:transform(item.itemid + 1)
		else
			player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You first must play the instruments in correct order to get the access!")
		end
		return true

	-- if using instrument and already played instruments in correct order
	elseif currentStorageValue == 5 then
		player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've already played them in correct order. Go and access the door!")
		return true
	end
	
	local targetTable = config[item.itemid]
	if not targetTable then
		player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Script setup incorrectly. Contact GM.")
		return true
	end
	
	currentStorageValue = currentStorageValue + 1
	
	-- playing instruments
	if currentStorageValue == targetTable then
		player:setStorageValue(storage, currentStorageValue)
		fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
	else
		player:setStorageValue(storage, 0)
		player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You played them wrong, now you must begin with first again!")
		doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
	end
	return true
end
 
😍😍Thank you!

It works as intended I did a small change tho

Changed this:
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Script setup incorrectly. Contact GM.")
        return true
    end

To:
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You played them wrong, now you must begin with first again!")
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end
so it resets the procedure when the player use the wrong instrument
else everything perfect !



What is this magic? 🤯
Lua:
local currentStorageValue = player:getStorageValue(storage)
    currentStorageValue = currentStorageValue == -1 and 0 or currentStorageValue
 
😍😍Thank you!

It works as intended I did a small change tho

Changed this:
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Script setup incorrectly. Contact GM.")
        return true
    end

To:
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You played them wrong, now you must begin with first again!")
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
        return true
    end
so it resets the procedure when the player use the wrong instrument
else everything perfect !



What is this magic? 🤯
Lua:
local currentStorageValue = player:getStorageValue(storage)
    currentStorageValue = currentStorageValue == -1 and 0 or currentStorageValue
I would advise you to use the script I posted as-is.
Your modification is wrong and that scenario is already covered in the script at lines 43-46.
Post automatically merged:

What is this magic? 🤯
Lua:
local currentStorageValue = player:getStorageValue(storage)
    currentStorageValue = currentStorageValue == -1 and 0 or currentStorageValue
This get's the current storage value.
If the storage value is -1 (a default value) it assumes it is 0 instead.
If it's not -1, then it uses the current value.
Post automatically merged:

I would advise you to use the script I posted as-is.
Your modification is wrong and that scenario is already covered in the script at lines 43-46.
Post automatically merged:


This get's the current storage value.
If the storage value is -1 (a default value) it assumes it is 0 instead.
If it's not -1, then it uses the current value.
Nvm.. I just checked the wiki.. and understand why you edited it like that.

Now that I understand the full scope of the script.. let me show you the more correct way to do it.
Lua:
local config = {
    [2367] = 1,
    [2373] = 2,
    [2370] = 3,
    [2372] = 4,
    [2369] = 5
}
local storage = 12109

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

	local currentStorageValue = player:getStorageValue(storage)
	currentStorageValue = currentStorageValue == -1 and 0 or currentStorageValue
	
	-- if using door
	if item.itemid == 1241 then
		if currentStorageValue == 5 then
			player:teleportTo(toPosition, true)
			item:transform(item.itemid + 1)
		else
			player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You first must play the instruments in correct order to get the access!")
		end
		return true
	-- if using instrument and already played instruments in correct order
	elseif currentStorageValue == 5 then
		player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've already played them in correct order. Go and access the door!")
		return true
	end
	
	currentStorageValue = currentStorageValue + 1
	
	local targetTable = config[item.itemid]
	if targetTable and currentStorageValue == targetTable then
		player:setStorageValue(storage, currentStorageValue)
		fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
	else
		player:setStorageValue(storage, 0)
		player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You played them wrong, now you must begin with first again!")
		doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
	end
	
	return true
end
 
Last edited:
Solution
Thank you so much for explaining, it's still amazing you can even do such thing in lua had no idea

The problem if I use
Lua:
    local targetTable = config[item.itemid]
    if not targetTable then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Script setup incorrectly. Contact GM.")
        return true
    end

Is that if I use any of these 3 I will get that error, but I want it to reset the procedure and dmg the player
Untitled.png
Post automatically merged:

I would advise you to use the script I posted as-is.
Your modification is wrong and that scenario is already covered in the script at lines 43-46.
Post automatically merged:


This get's the current storage value.
If the storage value is -1 (a default value) it assumes it is 0 instead.
If it's not -1, then it uses the current value.
Post automatically merged:


Nvm.. I just checked the wiki.. and understand why you edited it like that.

Now that I understand the full scope of the script.. let me show you the more correct way to do it.
Lua:
local config = {
    [2367] = 1,
    [2373] = 2,
    [2370] = 3,
    [2372] = 4,
    [2369] = 5
}
local storage = 12109

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

    local currentStorageValue = player:getStorageValue(storage)
    currentStorageValue = currentStorageValue == -1 and 0 or currentStorageValue
   
    -- if using door
    if item.itemid == 1241 then
        if currentStorageValue == 5 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You first must play the instruments in correct order to get the access!")
        end
        return true
    -- if using instrument and already played instruments in correct order
    elseif currentStorageValue == 5 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've already played them in correct order. Go and access the door!")
        return true
    end
   
    currentStorageValue = currentStorageValue + 1
   
    local targetTable = config[item.itemid]
    if targetTable and currentStorageValue == targetTable then
        player:setStorageValue(storage, currentStorageValue)
        fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE)
    else
        player:setStorageValue(storage, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You played them wrong, now you must begin with first again!")
        doTargetCombat(0, player, COMBAT_PHYSICALDAMAGE, -20, -500, CONST_ME_GROUNDSHAKER)
    end
   
    return true
end

YUP ♥️♥️♥️

Thanks alot your great!
 
Last edited:
Back
Top