Jump to content

Simple Script request


ReverendFelix

Recommended Posts

I am trying to learn scripting. I learn best from things that are similar to my needs. But right now I need a script that makes an npc cast a friendly spell at you when approached. Then not cast it again for 5 minutes.

 

So basically get within 150 units they'll cast. And only cast again 5 minutes later,or longer, only if you go near them again.

Link to comment
Share on other sites

Will they cast again only when you went away and returned more than 5 minutes later? Or will they constantly re-cast every 5 minutes while you're in range?

For distance checks you can use GetDistance, and a 5 minutes timer is usually created using GetSecondsPassed.

So an example bare-bone Object script running on the NPC would contain:

float fTimer
float fDistance
 
Begin GameMode
    If 0 < fTimer
        Set fTimer to fTimer - GetSecondsPassed
        Return
    Else
        Set fDistance to GetDistance player
        If 150 > fDistance
            Cast MyFriendlySpell player
            Set fTimer to 300
        Endif
    Endif
End

But its final form still depends on your answers to my questions.

Link to comment
Share on other sites

Will they cast again only when you went away and returned more than 5 minutes later?

This way. With the initial cast being activated by close proximity to the npc. (150 units)

Edited by ReverendFelix
Link to comment
Share on other sites

Hmm, then I'd try with a state variable instead:

float fTimer
float fDistance
short sState
 
Begin GameMode

    If 0 < fTimer
        Set fTimer to fTimer - GetSecondsPassed
    Endif

    If 1 == sState ;within range once, wait for outside
        Set fDistance to GetDistance player
        If 150 < fDistance
            Set sState to 0
        Endif
        Return
    Else ;initial/outside again, wait for within
        Set fDistance to GetDistance player
        If 150 >= fDistance && 0 >= fTimer
            Cast MyFriendlySpell player
            Set fTimer to 300
            Set sState to 1
        Endif
    Endif
End

You should be able to go into and out of range however you like, while the timer is counting down. The script will track if you went out, and once you return after the timer is up, or the timer runs up while you're again in range, then it will cast again.
It won't cast again once the timer is up and you're still in range, because after the last cast you're in state 1, and you won't leave state 1 without first leaving the range.

Link to comment
Share on other sites

Well I typed it up in the cse and after making the spells I needed, it saved and compiled! I have only done a preliminary test at this point, but the results so far are perfect. I verily thank you for this and will credit you when the mod is released.
Link to comment
Share on other sites

Just thought I'd post that the script performs perfectly. The only oddity is if combat gets too close to the script user. However, that is on my end due to npc settings. This script is great for anyone else that wants to accomplish a similar goal.

 

Thanks a bunch to DrakeTheDragon,

 

Rev.

Link to comment
Share on other sites

  • 2 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...