Aeronx
Intermediate OT User
- Joined
- Dec 17, 2015
- Messages
- 746
- Solutions
- 9
- Reaction score
- 125
Hello otlanders. I've started doing some testing with party buffs and such.
And I got to this.
What does this do? When I cast a spell i register this event to all party members or to caster if not party.
If there no party. It works perfectly! The problem comes with party. Let's say there are 3 members on the party, after casting the spell, it registers to all at the same time BUT only player1 of the party will get the buff for 25 seconds, after 25 seconds, player2 will get the buff, and after 25 seconds, player3.
I've been doing some testing and tested with interval > 1.
If i do that, player1 get like tons of executions of this function, after 1 second player2 starts getting many executions of this function and so on.
If i dont set an interval check "if ((os.time()) - last_interval) > 25 then", they all get the buff at the same time and many executions of the function.
What i am trying to accomplish? Execute this function once for all players affected at same time.
I understand the idea behind the os.time with the storage. Just trying to learn a bit here.
So how should i approach this to accomplish what i am looking for? All explanations and exemples are more than welcome.
Thank you for your time!
And I got to this.
Code:
local times = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
function shine9(cid)
local cid = Creature(cid)
local position = cid:getPosition()
position:sendMagicEffect(19)
end
function storagesnil(cid)
local cid = Creature(cid)
cid:setStorageValue(60245, cid:getStorageValue(60245)-10)
cid:setStorageValue(6902, 0)
cid:unregisterEvent('partycrit')
end
function onThink(cid, interval)
if last_interval == nil then
last_interval = os.time()
end
if ((os.time()) - last_interval) > 25 then
cid:setStorageValue(60245, cid:getStorageValue(60245) + 10)
cid:setStorageValue(6902,1)
addEvent(storagesnil, 25 * 1000, cid.uid)
for i = 1, #times do
addEvent(shine9, times[i] * 2500, cid.uid)
end
last_interval = os.time()
end
return false
end
What does this do? When I cast a spell i register this event to all party members or to caster if not party.
If there no party. It works perfectly! The problem comes with party. Let's say there are 3 members on the party, after casting the spell, it registers to all at the same time BUT only player1 of the party will get the buff for 25 seconds, after 25 seconds, player2 will get the buff, and after 25 seconds, player3.
I've been doing some testing and tested with interval > 1.
If i do that, player1 get like tons of executions of this function, after 1 second player2 starts getting many executions of this function and so on.
If i dont set an interval check "if ((os.time()) - last_interval) > 25 then", they all get the buff at the same time and many executions of the function.
What i am trying to accomplish? Execute this function once for all players affected at same time.
I understand the idea behind the os.time with the storage. Just trying to learn a bit here.
So how should i approach this to accomplish what i am looking for? All explanations and exemples are more than welcome.
Thank you for your time!