• 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 Script to "replace" source spell cooldown

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hey guys, I would like a script that when you kill a monster with a specific weapon, you have a % of reducing spell cooldown by x seconds. But in order to do so, I would need a script to replace the source spell cooldown using table or storage value. However this is too complex for me to do, could somebody help?

TFS 1.3
 
Last edited:
Solution
Here I will show you an example of how it is done with pure lua, but you must bear in mind that it is not something clean and it is not a complete code, but I will give you an example to see if you dare to complete it or if someone wants to finish it for you

data/scripts/spellcooldownsystem.lua
Lua:
SpellCooldownSystem = {
    storages = {},
    cooldowns = {},
    reduction = 0.10 -- 10%
}

local spellCooldownEvent = CreatureEvent("SpellCooldownSystemLogin")
function spellCooldownEvent.onLogin(player)
    SpellCooldownSystem.storages[player:getId()] = {}
    player:registerEvent("SpellCooldownSystemReduction")
    return true
end
spellCooldownEvent:register()

local spellCooldownEvent =...
Hey guys, I would like a script that when you kill a monster with a specific weapon, you have a % of reducing spell cooldown by x seconds. But in order to do so, I would need a script to replace the source spell cooldown using table or storage value. However this is too complex for me to do, could somebody help?

TFS 1.3
Not possible in pure Lua. You would need source edits, just fyi.
 
Let's say we put exevo flam hur with a cooldown of 6 seconds and add storage number 5555 to be on the player for 6 seconds everytime the player cast exevo flam hur. Then we create a script that everytime a monster is killed it has 10% chance of removing the storage 5555

Let's say player can only uses exevo flam hur if he hasn't storage number 5555; Also let's say everytime player cast exevo flam hur, the storage 5555 is added to him; And maybe we can create a script for the storage to last for 6 seconds. That way we would have a cooldown system.

Now let's say we can create a script that when a player kill a monster, it has 10% chance of removing storage 5555 from that player. In that way, we would have a reduce cooldown system, right?

I don't understand much about script, so let me know if I'm saying impossible stuff.
 
With pure lua it can be done, as long as all the spells are rewritten so that they have 0 seconds of cooldown, and then a reuse system is manually added in lua, with which you can manage the time and therefore implement any system you can imagine, but if you ask me, I really wouldn't do it like that, I prefer to edit the source code a bit and achieve it
 
With pure lua it can be done, as long as all the spells are rewritten so that they have 0 seconds of cooldown, and then a reuse system is manually added in lua, with which you can manage the time and therefore implement any system you can imagine, but if you ask me, I really wouldn't do it like that, I prefer to edit the source code a bit and achieve it
Yup... That's not a good, efficient idea :p
 
With pure lua it can be done, as long as all the spells are rewritten so that they have 0 seconds of cooldown, and then a reuse system is manually added in lua, with which you can manage the time and therefore implement any system you can imagine, but if you ask me, I really wouldn't do it like that, I prefer to edit the source code a bit and achieve it
My server is full custom, I'm doing all spells from 0, so it wouldn't be more work to put 0 seconds cooldown at spell.xml and do the new spell cooldown manually. I don't know how to edit sources. I do have a friend that edit my source, however he is very busy, so it takes like 1 month for him to edit a single thing at my source. In that way, it's faster if I do it manually by lua.
 
If you want to apply it to all spells then:

CONDITION_SPELLCOOLDOWN
CONDITION_SPELLGROUPCOOLDOWN
CONDITIONID_DEFAULT

(hasCondtion) -> getCondition
setTicks -> reducedValue

else you need the src modifications/the lua cooldown system you specified.
 
If you want to apply it to all spells then:

CONDITION_SPELLCOOLDOWN
CONDITION_SPELLGROUPCOOLDOWN
CONDITIONID_DEFAULT

(hasCondtion) -> getCondition
setTicks -> reducedValue

else you need the src modifications/the lua cooldown system you specified.
I think the way you said I wouldn't be able to reduce the cooldown after killing a monster. But thanks for the contribution
 
I think the way you said I wouldn't be able to reduce the cooldown after killing a monster. But thanks for the contribution
You can, why wouldn't you?
The only problem is the fact that it won't only affect flam hur but all spells that belong to this cooldown.
 
You can, the only problem is the fact that it won't only affect flam hur but all spells that belong to this cooldown.
No. He wants to reduce cooldown of all spells that are currently on cooldown when he kills a monster. You can't just set cooldown condition because it will affect only spells that are going to be cast while this condition works.
Either do Sarah's way (not recommended) or get someone to help you edit sources or wait for someone to help you here.
 
You can, the only problem is the fact that it won't only affect flam hur but all spells that belong to this cooldown.
That wouldn't be a problem. The exori flam hur was only a example. What I entend to do is for that 10% chance reduce all spells cooldowns of all spells that are with cooldown counting
Post automatically merged:

Is it a bad idea to set storage value everytime player cast spell? I would add a different storage to every spell, and than at creature script, when the 10% chance works, it would remove all the storages that I put in each spell of that player.
Can I put a storage to be on a player for x amount of seconds?
 
No. He wants to reduce cooldown of all spells that are currently on cooldown when he kills a monster. You can't just set cooldown condition because it will affect only spells that are going to be cast while this condition works.
Either do Sarah's way (not recommended) or get someone to help you edit sources or wait for someone to help you here.
What?
Now let's say we can create a script that when a player kill a monster, it has 10% chance of removing storage 5555 from that player. In that way, we would have a reduce cooldown system, right?
He wanted to shorten/remove the cooldown after a kill - what's wrong with changing/removing the cooldown condition to do so?
 
I get that is easier to edit source, however that's the last option for me. I haven't seem anybody say to me that the storage idea is impossible to do.
 
What?

He wanted to remove the cooldown after a kill - what's wrong with changing/removing the cooldown condition to do so?
It was his example of doing it but it's not exactly how it should be done (as always, people are overusing storages). He clearly wants to contract remaining cooldowns from spells that are currently on cooldown. Cooldown reduction condition won't work here.
 
It was his example of doing it but it's not exactly how it should be done (as always, people are overusing storages). He clearly wants to contract remaining cooldowns from spells that are currently on cooldown. Cooldown reduction condition won't work here.
I mean removing/shortening the condition that blocks the spells from being cast here

I get that is easier to edit source, however that's the last option for me. I haven't seem anybody say to me that the storage idea is impossible to do.
Its not impossible
Can I put a storage to be on a player for x amount of seconds?
You can just store the time of an event (a timestamp) and compare it with the current time.
 
Last edited:
I mean removing/shortening the condition that blocks the spells from being cast here
That's actually true. Cooldowns are saved as conditions, forgot about that. You can check them and overwrite in Lua.
I had cooldown reduction condition in my head, which is not a thing in TFS and so all that talking about conditions confused the hell out of me.
 
So I would set:

Code:
local condition = Condition(CONDITION_SPELLCOOLDOWN)

condition:setParameter(CONDITION_PARAM_TICKS, 6 * 1000)


function onCastSpell(creature, variant)

    return creature:addCondition(combat, variant, condition, 6)

end

at the spell and it would have a 6 seconds cooldown?
 
So I would set:

Code:
local condition = Condition(CONDITION_SPELLCOOLDOWN)

condition:setParameter(CONDITION_PARAM_TICKS, 6 * 1000)


function onCastSpell(creature, variant)

    return creature:addCondition(combat, variant, condition, 120)

end

at the spell and it would have a 6 seconds cooldown?
No. You have to set subId which is spellId and you have to set that condition after onCastSpell is executed otherwise source will overwrite that condition.
 
No. You have to set subId which is spellId and you have to set that condition after onCastSpell is executed otherwise source will overwrite that condition.
Can you show me what you mean by doing on the script?
And ok, after we put the cooldown to work on the spell, how could we reduce the cooldown by killing monsters?

Lua:
function onCastSpell(creature, variant)

local condition = Condition(CONDITION_SPELLCOOLDOWN)

condition:setParameter(CONDITION_PARAM_TICKS, 6 * 1000)
    return creature:addCondition(combat, variant, condition, 120)

end

That subId part I didn't get
 
Can you show me what you mean by doing on the script?
And ok, after we put the cooldown to work on the spell, how could we reduce the cooldown by killing monsters?
You don't have to set the cooldown when someone casts the spell, it's already done by TFS. If you want to reduce current cooldows when you kill monster then you need kill event, id of spell you want to reduce that cooldown for and use of creature:getCondition and creature:addCondition.
 
Back
Top