• 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 Help please, Many ActionIds in one code?? theres possible?

origamidoizin

Member
Joined
Jan 2, 2024
Messages
19
Reaction score
6
Hi guys, i have a code of a item that when u use it u have 1% chance to get a reward, this item is a rock that is on whole map, i put a different action id on each one of that rocks.
Now i dont want to create 100+ files for each rock action id.
Theres a way to do that without havin to create hundread files?
 

Attachments

Solution
ty dude, ill try this one and report if worked ty
Post automatically merged:


brother now it has no cooldown, i can use every rock with no cd :( but ty anyway
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local posIndex = toPosition.x .. ":" .. toPosition.y .. ":" .. toPosition.z
    local cooldown = cooldownTable[posIndex]
    local now = os.time()
    
    if cooldown and now < cooldown then
        doPlayerSendCancel(cid, "It is on cooldown, wait.")
        return true
    end
    
    cooldownTable[posIndex] = now + 10
    
    if math.random(1, 10) ~= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not...
Hi guys, i have a code of a item that when u use it u have 1% chance to get a reward, this item is a rock that is on whole map, i put a different action id on each one of that rocks.
Now i dont want to create 100+ files for each rock action id.
Theres a way to do that without havin to create hundread files?
Just use the same script, there are countless examples of that in actions.xml ...

Can u explain it better?
You want different actionID's for different rocks?
I am afraid he cannot be clearer on that
different action id on each one of that rocks.
Don't do drugs kids
 
From reading the script, it doesn't have a requirement to use only 1 actionid. So it should already work with multiple action id's the way the script is written. The problem would be with registration. There is no way around having to register the action, and you have to register it to an action id. You didn't share your server distro, but looking at the code its obviously something older than tfs1.0, so yeah you don't really have many options afaik.

If you still want to use actionid's for determining the cooldown. One workaround would be to register the action to a "unique id" instead, and then you can still use the the action id's for cooldown, but every rock will need the exact same unique id, with different action id's. Which I think will give you errors for both the map editor and server, but could possibly still work.
 
Ill try to be clearer, my code is for a rock that when uses the player have chance to gain a reward, this rock have a cd of 10 minutes, on that code was 10s cause i was testing, but it would be 10 minutes cd, the problem with this is the cd is impacting every rocks, the only way each rock have it own cd is puting different action id on each one, so i would need to create hundread of codes, one for each rock lol my server is tfs 1.2 what i want is a way to put all the action ids in one code instead of creating hundread codes on actions lol
Post automatically merged:

Ill try to be clearer, my code is for a rock that when uses the player have chance to gain a reward, this rock have a cd of 10 minutes, on that code was 10s cause i was testing, but it would be 10 minutes cd, the problem with this is the cd is impacting every rocks, the only way each rock have it own cd is puting different action id on each one, so i would need to create hundread of codes, one for each rock lol my server is tfs 1.2 what i want is a way to put all the action ids in one code instead of creating hundread codes on actions lol
example, action id 123, action id 1234, when i use the rock 123 it get cd, and the 1234 i did not use get cd too and its wrong beacuse it was not used, but if a create a file for 123 and a file for 1234, then when i use 123 it get cd, then 1234 is not on cd, and i can use it too and it will be on cd. This is the way it should work, each one of the 100+ rocks on the map must have it own cd, not use one rock and all 100 get cd lol i want it to be individual, rock 1 used so rock 1 is on cd, rock 2 used then rock 2 is on cd. Not use rock 1 and all rocks get cd(its the way it is now) lol
 
Last edited:
Here, updated your code to use the rock position, instead of the actionId.
So just register in actions.xml with a single actionId, and put it on every rock.
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

local function positionToString(position)
	return "x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local cooldown = cooldownTable[positionToString(toPosition)]
	if cooldown and os.time() < cooldown then
		doPlayerSendCancel(cid, "It is on cooldown, wait.")
		return true
	end
	cooldown = os.time() + 10
	
	if math.random(1, 10) ~= 1 then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not find anything.")
		return true
	end
	
	doPlayerAddItem(cid, rewardItemID, 1)
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received a reward!")
	return true
end
 
Here, updated your code to use the rock position, instead of the actionId.
So just register in actions.xml with a single actionId, and put it on every rock.
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

local function positionToString(position)
    return "x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cooldown = cooldownTable[positionToString(toPosition)]
    if cooldown and os.time() < cooldown then
        doPlayerSendCancel(cid, "It is on cooldown, wait.")
        return true
    end
    cooldown = os.time() + 10
   
    if math.random(1, 10) ~= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not find anything.")
        return true
    end
   
    doPlayerAddItem(cid, rewardItemID, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received a reward!")
    return true
end
ty dude, ill try this one and report if worked ty
Post automatically merged:

Here, updated your code to use the rock position, instead of the actionId.
So just register in actions.xml with a single actionId, and put it on every rock.
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

local function positionToString(position)
    return "x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cooldown = cooldownTable[positionToString(toPosition)]
    if cooldown and os.time() < cooldown then
        doPlayerSendCancel(cid, "It is on cooldown, wait.")
        return true
    end
    cooldown = os.time() + 10
   
    if math.random(1, 10) ~= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not find anything.")
        return true
    end
   
    doPlayerAddItem(cid, rewardItemID, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received a reward!")
    return true
end
brother now it has no cooldown, i can use every rock with no cd :( but ty anyway
 
Last edited:
ty dude, ill try this one and report if worked ty
Post automatically merged:


brother now it has no cooldown, i can use every rock with no cd :( but ty anyway
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local posIndex = toPosition.x .. ":" .. toPosition.y .. ":" .. toPosition.z
    local cooldown = cooldownTable[posIndex]
    local now = os.time()
    
    if cooldown and now < cooldown then
        doPlayerSendCancel(cid, "It is on cooldown, wait.")
        return true
    end
    
    cooldownTable[posIndex] = now + 10
    
    if math.random(1, 10) ~= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not find anything.")
        return true
    end
    
    doPlayerAddItem(cid, rewardItemID, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received a reward!")
    return true
end
 
Solution
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local posIndex = toPosition.x .. ":" .. toPosition.y .. ":" .. toPosition.z
    local cooldown = cooldownTable[posIndex]
    local now = os.time()
   
    if cooldown and now < cooldown then
        doPlayerSendCancel(cid, "It is on cooldown, wait.")
        return true
    end
   
    cooldownTable[posIndex] = now + 10
   
    if math.random(1, 10) ~= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not find anything.")
        return true
    end
   
    doPlayerAddItem(cid, rewardItemID, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received a reward!")
    return true
end
tested little quick because im goint out but it looks like worked, tried with 5 rocks and that worked, ty man really apreciate it s2
 
Here, updated your code to use the rock position, instead of the actionId.
So just register in actions.xml with a single actionId, and put it on every rock.
Lua:
local rewardItemID = 17209
local cooldownTable = {} -- Tabela para controlar o cooldown dos itens

local function positionToString(position)
    return "x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cooldown = cooldownTable[positionToString(toPosition)]
    if cooldown and os.time() < cooldown then
        doPlayerSendCancel(cid, "It is on cooldown, wait.")
        return true
    end
    cooldown = os.time() + 10
   
    if math.random(1, 10) ~= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You did not find anything.")
        return true
    end
   
    doPlayerAddItem(cid, rewardItemID, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received a reward!")
    return true
end
I thought you stopped helping you maniac! How is your game development going? ;p
 
ty dude, ill try this one and report if worked ty
Post automatically merged:


brother now it has no cooldown, i can use every rock with no cd :( but ty anyway
mm the problem is on line 14.
need to change cooldown = os.time() + 10 to cooldownTable[positionToString(toPosition)] = os.time() + 10

You already have a solution though, so just posting for posterity's sake.

I thought you stopped helping you maniac! How is your game development going? ;p
It's going.. xD
I've been playing real tibia recently, streaming it all. lol
So game dev is taking a bit of a back seat.
 
mm the problem is on line 14.
need to change cooldown = os.time() + 10 to cooldownTable[positionToString(toPosition)] = os.time() + 10

You already have a solution though, so just posting for posterity's sake.


It's going.. xD
I've been playing real tibia recently, streaming it all. lol
So game dev is taking a bit of a back seat.
ty brother, the othe guy helped and it worked but anyway ty so much for ur time
 
Back
Top