Skip to content

Setting a local var for 60 seconds?

FinalStandFinalStand Member Posts: 87
edited March 2018 in Builders - Scripting
I want to set a local var and delete it after 60 seconds. DelayCommand doesn't work on DeleteLocalInt. Any ideas on how to do this?

Basically, I have a special potion. The player drinks it and for 60 seconds they have double XP rewards. If they drink it again, it should reset the timer.

In my XP script I can check for if a LocalInt is set, but not sure how to get it deleted after 60 seconds unless I want to get into a bunch of calendar math. Is there a simple way to do this ?

I could deincrement on heart beat script, but wondering if there is any other ways?



Comments

  • squattingmonksquattingmonk Member Posts: 59
    edited March 2018

    DelayCommand doesn't work on DeleteLocalInt.

    It does, actually. DelayCommand() can have some funkyness with when its arguments are evaluated, though. Mind posting the relevant section of your script?

    In the meantime, here's a sample function that does what you need it to.
    void SetTemporaryInt(object oTarget, string sVarName, int nValue, float fDelay) { SetLocalInt(oTarget, sVarName, nValue); DelayCommand(fDelay, DeleteLocalInt(oTarget, sVarName)); }

    EDIT: D'oh! Forgot that you wanted to refresh the duration of the potion.

    Post edited by squattingmonk on
  • HimmelweissHimmelweiss Member Posts: 72
    edited March 2018
    Once you call DelayCommand() there is no way to refresh/kill that one call even after your player drinks another potion. Atleast not that i know of.
    The only way is to kill the calling object :p


    I guess with some workarround you could make sure to eliminate previous DelayCommand() calls.
    Something like (not tested):

    void DeleteTemporaryInt(object oTarget, string sVarName, int iScriptID) { if (iScriptID == GetLocalInt(oTarget, "CURRENT_SCRIPT_ID")) DeleteLocalInt(oTarget, sVarName); } void main() { object oTarget = OBJECT_SELF; string sVarName = "XP_POTION"; SetLocalInt(oTarget , "CURRENT_SCRIPT_ID", GetLocalInt(oTarget , "CURRENT_SCRIPT_ID") + 1); int iScriptID = GetLocalInt(oTarget , "CURRENT_SCRIPT_ID"); SetLocalInt(oTarget, sVarName, 1); DelayCommand(60.0, DeleteTemporaryInt(oTarget, sVarName, iScriptID)); }


    Basically the CURRENT_SCRIPT_ID local var just makes sure to always only execute the latest DelayCommand call.
    If you worry about an overflow you can always reset CURRENT_SCRIPT_ID whenever it reaches 2,147,483,647 :D But i seriously wouldn't really worry about it for now :D

  • BalkothBalkoth Member Posts: 157
    Just increment the LocalInt when you first drink the potion and then decrement it after 60 seconds. Then simply check if the LocalInt is true (aka, not 0). So if you drink three potions every 20 seconds, you'll get...

    00-20: 1
    20-40: 2
    40-60: 3
    60-80: 2
    80-100: 1
    120+: 0

    So then your code would look something like

    if (GetLocalInt(OBJECT_SELF, "doublexp")) then give double xp
  • HimmelweissHimmelweiss Member Posts: 72
    Yup.
    Above example is much simpler.

    No need to fuzzle arround with deleting variables.
  • FinalStandFinalStand Member Posts: 87
    Thanks that is what I am looking for.
  • ProlericProleric Member Posts: 1,281
    Heartbeat runs every 6 seconds - a very reliable event to use when decrementing timers.

    Gives you more control than DelayCommand, which is fire-and-forget.
  • FinalStandFinalStand Member Posts: 87
    DelayCommand works. But what happens if I want to attach this to an effect? Or remove on sleep.

    I can script it, but hoping there is easy way to attach on effect so can work like that. (or make a simple effect with custom var or something).

    The problem:


    Player drinks potion, set var =1
    DelayCommand1 (deletevar, 60 )

    At 30 seconds Player sleeps, deletevar

    wakes up, Drinks new potion

    DelayCommand 2(deletevar, 60 )


    Delaycommand1 deletes it after 30 seconds




  • shadguyshadguy Member Posts: 154
    Have you tried treating it as a custom spell effect? I think your xp code would then just need to check for the existence of the appropriate spell effect when deciding if xp is increased. Resting would nuke the effect.

    Dave
  • FinalStandFinalStand Member Posts: 87
    edited March 2018
    shadguy said:

    Have you tried treating it as a custom spell effect? I think your xp code would then just need to check for the existence of the appropriate spell effect when deciding if xp is increased. Resting would nuke the effect.

    Dave

    that sounds like what I want. Any guides for this? Do I just add new spell to spells.2da or can do though just scripting?

  • shadguyshadguy Member Posts: 154
    You'd need to add a line to spells.2da to support your new spell-like item ability. You'd also want to add a corresponding line to iprop_spells.2da to support adding your new spell to an item, in this case a potion.

    If you've never done this before, I'd start with reading the Spells section of Eligio's Custom Content Guide:

    https://neverwintervault.org/project/nwn1/other/custom-content-guide-v30

    There are some wrinkles you may bump into, but you can make this work. Give it a shot, see what you can figure out with Eligio's write up, and feel free to follow up with any questions.

    -Dave
Sign In or Register to comment.