• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Looking for script that: Adds time to cooldown when player casts before cooldown is up.

Tysoch86

New Member
Joined
Jan 8, 2016
Messages
81
Reaction score
1
Hi everyone, I'm new here so hopefully I can explain this properly.

I am looking to add a punishment to players who spam or even incorrectly cast a spell. The script could add time to the cooldown that the player is attempting to use. I feel that this would add a large amount of skill and thus play to the game.

I hope this scrip exists or can exist. If it does I am sorry I could not find it..

I am using TFS 1.1-win32 on Windows 8.

Please let me know if you need any more info or if there is anything I can do to help.
Thank you!
 
if someone are interested in making it, here is my tip:
(it must be done in C++)

add a key in spells xml which represent the extra cooldown
in something like that:
if (player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, group)
get the remaining cooldown time, remove it and put on player the new condition remaining + extra cooldown
you can ofc choose a default value, so you dont need to configure every spell or dont even have a individual cooldown
 
Why do it in c++?
Wouldn't it be easier to parse the spells file to generate a list of spell words and then add a check in channel for the last few words executed in that channel and if they don't match the spell words, then hit them with an exhaust.

Not everything requires a source edit.
 
why dont do it in c++???

if using a default value for the extra cooldown, the code will have like 3 lines
doing it through Lua requires more CPU usage and lot of lines of coding

everything works better with some source edit
 
why dont do it in c++???

if using a default value for the extra cooldown, the code will have like 3 lines
doing it through Lua requires more CPU usage and lot of lines of coding

everything works better with some source edit
But its easier to trouble shoot if its a script than it is if you are editing the source.
Well I am decent scripter so i would attempt it with a script, if you are better with c++ then edit the source.
 
doing that way is just a jerry-rig

i'm also better with Lua but I care about efficiency, Lua is a scripting language and were designed to configure complex systems not build them

As this request got some attention but without constructive posts and actually its a pretty cool feature I'm going to build and release it.
 
doing that way is just a jerry-rig

i'm also better with Lua but I care about efficiency, Lua is a scripting language and were designed to configure complex systems not build them

As this request got some attention but without constructive posts and actually its a pretty cool feature I'm going to build and release it.
I like the idea that you will build and release it.
Although lua isn't designed by itself to build systems, it can if you are using a proper framework.

I have worked in frameworks using lua where we had to build absolutely everything, interface, colors, map, 3d, animation, sound etc.. is things like this possible with tfs not everything but its a probability if you use your imagination.

Btw, how is an opinion not constructive?

All these forums are not just about providing answers, a discussion is an important part of development.
 
Why you think it takes more CPU power though? Because here is what I think.
When you execute a spell, it will go trough Lua anyway to get the spell function.

I guess when you do it in spells.xml it will just read trough the parameters and checks if player can even cast it in first place ignoring the Lua function to do something with spell.
But don't think the difference is more than 0.01 seconds to execute function. (just talking about executing it, regardless how big script the spell itself is)
And if you simply add Lua way of adding exhaust time to spell. It will take same amount of time like in source.
Because the Lua functions are loaded to memory anyway, they will be simply executed.

So doesn't matter do you ask the question: "is spell under cooldown?" in c++ or Lua, should be same speed.
and executing function: "set exhaust time" also would take same amount of CPU power.
Only difference was that with Lua you used Lua libraries to find the source function. But since they are in memory anyway, It will be fast.


Besides I think spells.xml is horrible place to make spells anyway. way too many restrictions.
Talkaction for player spells and onThink() for creature spells.

If you use spell.xml then less time consuming option for this particular feature is source edit. Else you would have to edit every single spell.

But with talkactions. All you have to do is add else statement to cooldown question and then simply another line to increase cooldown and you can even config for particular spell that some give 1 sec less or some give 2 sec more cooldown, etc etc.

I use talkaction to cast spell and here is how it would look for me.
Code:
if os.time() < spellCD then
                    playerPos:sendMagicEffect(3)
                    return false, player:sendTextMessage(GREEN, "Spell under Cooldown.")
                else
                    addSV(player, t.storageID+20000, t.cdPenalty or 1)
                end

If I don't edit my spells now, ALL spells have this effect that if I spell is under cooldown then it will add 1 second to cooldown.

And it took me 1 minute to do this. (opening the coding program > find the file > doublecheck variables > write the line)
That's why i recommend moving away from spell folder and not make any spells there.
 
Last edited:
So doesn't matter do you ask the question: "is spell under cooldown?" in c++ or Lua, should be same speed.
how would you check if spell is under cooldown? probably you will compare the word given to a list containing all the spell words.
are you sure it should be the same speed? i'd bet 30x slower

well if you dont like tfs' spells style its ok
 
doing the same thing doesnt mean they have the same efficiency

moreover, im not doing any check in the sources, i'm just including in a ALREADY DONE CHECK the requested feature
 
You guys are awesome.
All of this is so far above my head, I had no idea how complex such a little rule change could be in a game :). I am glad there seems to be some interest in the thread, and I do feel like the rule change, as small as it is, would make playing a spell caster that much more satisfying!

Thank you all for your posts, and I am very interested in seeing how this all works out!
If I can help at all let me know! :D
 
Why do it in c++?
Wouldn't it be easier to parse the spells file to generate a list of spell words and then add a check in channel for the last few words executed in that channel and if they don't match the spell words, then hit them with an exhaust.

Not everything requires a source edit.
And how would you "check in channel for the last few words"? There is no function in lua to do that. The only way you can add more cooldown to the spell is indeed using C++, its not possible using lua. Not if you are going to use the current spell system, ofcourse you could rebuild every shit from spells and do them with talkaction or edit every spell to have 0 cooldown and send the NetworkMessage to set the CD thing in the client and save them in some table and do the cooldown in lua, its not impossible but I don't think anyone want to do that when you can do it with just 10 lines of code in C++:p

forgot about it.

found this:
spells.cpp
Code:
if (player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, group) || player->hasCondition(CONDITION_SPELLCOOLDOWN, spellId) || (secondaryGroup != SPELLGROUP_NONE && player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, secondaryGroup))) {
        player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED);

add this:
Code:
        Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, 2, 0, false, group);
        player->addCondition(condition);
change 2 to the intended punishment time


this is a very simple code that doesnt allows to set punishment time individually


(didnt tested must work)

This will update the previous condition and set the ticks to 2 (its not 2 seconds) and erase the time that was set before so you have to get the previous condition and set the ticks based on the endtime of that previous condition.
 
Last edited:
And how would you "check in channel for the last few words"? There is no function in lua to do that. The only way you can add more cooldown to the spell is indeed using C++, its not possible using lua. Not if you are going to use the current spell system, ofcourse you could rebuild every shit from spells and do them with talkaction or edit every spell to have 0 cooldown and send the NetworkMessage to set the CD thing in the client and save them in some table and do the cooldown in lua, its not impossible but I don't think anyone want to do that when you can do it with just 10 lines of code in C++:p
TL DR
1st off get a life, a girl friend or something productive, secondly you have 0 imagination, it is no wondering you have yet to release anything you thought of yourself 1st.
 
Last edited:
new try:

spells.cpp
find:
Code:
if (player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, group) || player->hasCondition(CONDITION_SPELLCOOLDOWN, spellId) || (secondaryGroup != SPELLGROUP_NONE && player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, secondaryGroup))) {
        player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED);

insert:
Code:
Condition* condition = getCondition(CONDITION_SPELLCOOLDOWN, spellId);
        int64_t endTime = condition->getEndTime();
        int64_t newTicks = endTime - OTSYS_TIME() + 2000;
     
         condition->setTicks(newTicks);

creature.cpp:
find:
Code:
Condition* Creature::getCondition(ConditionType_t type) const
{
    for (Condition* condition : conditions) {
        if (condition->getType() == type) {
            return condition;
        }
    }
    return nullptr;
}

insert:
Code:
Condition* Creature::getCondition(ConditionType_t type, uint32_t subId/* = 0*/) const
{
    for (Condition* condition : conditions) {
        if (condition->getType() == type && condition->getSubId() == subId) {
            return condition;
        }
    }
    return nullptr;
}

creature.h
find:
Code:
Condition* getCondition(ConditionType_t type) const;

insert:
Code:
Condition* getCondition(ConditionType_t type, uint32_t subId = 0) const;


I couldnt test it again, hope works
 
Back
Top