Difference between revisions of "Command an NPC/Creature to Attack"
Command an NPC/Creature to Attack (edit)
Revision as of 12:09, 26 December 2009
, 12:09, 26 December 2009no edit summary
imported>Phinix |
imported>Phinix |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
This tutorial will explain how to set up a script on a custom NPC/creature so that by activating it you will be able to command it to attack nearby actors (including friendlies.) | This tutorial will explain how to set up a script on a custom NPC/creature so that by activating it you will be able to command it to attack nearby actors (including friendlies.) | ||
== Create a Global variable == | == Create a Global variable == | ||
Line 31: | Line 29: | ||
begin ScriptEffectUpdate | begin ScriptEffectUpdate | ||
if | if globalvar1 == 1 | ||
SetAV Aggression 50 | SetAV Aggression 50 | ||
elseif | elseif globalvar1 == 2 | ||
SetAV Aggression 10 | SetAV Aggression 10 | ||
endif | endif | ||
Line 39: | Line 37: | ||
begin ScriptEffectFinish | begin ScriptEffectFinish | ||
SetAV Aggression 10 | |||
end | end | ||
Line 54: | Line 52: | ||
Now right-click the space on the right and select "New" to bring up the box to add a new spell effect. | Now right-click the space on the right and select "New" to bring up the box to add a new spell effect. | ||
For the effect choose "Script Effect" and give it a duration | For the effect choose "Script Effect" and give it a duration of 0, since we're adding it as an Ability which remains constant. | ||
Give it an "Effect Name," then choose any school and visual. Do not check "Effect is Hostile." | Give it an "Effect Name," then choose any school and visual. Do not check "Effect is Hostile." | ||
Line 99: | Line 97: | ||
set activestat to 0 | set activestat to 0 | ||
elseif button == 1 | elseif button == 1 | ||
set timer to 1.5 | |||
set globalvar1 to 2 | set globalvar1 to 2 | ||
set activestat to 0 | set activestat to 0 | ||
Line 105: | Line 104: | ||
endif | endif | ||
endif | endif | ||
endif | endif | ||
if globalvar1 == 2 | if globalvar1 == 2 | ||
if | if timer == 0 | ||
set | set globalvar1 to 0 | ||
elseif timer > 0 | |||
set timer to timer - getSecondsPassed | |||
StopCombatAlarmOnActor | |||
elseif timer < 0 | |||
set timer to 0 | |||
endif | endif | ||
endif | endif | ||
Line 130: | Line 118: | ||
That should do it. I set my summons to have '''aggression''' at 10 in their AI setup by default. That way they’ll fight when attacked but won’t go after friendlies unless you command them to. | That should do it. I set my summons to have '''aggression''' at 10 in their AI setup by default. That way they’ll fight when attacked but won’t go after friendlies unless you command them to. | ||
'''UPDATE:''' The reason I use the timer for setting the defensive state to 2 and then back to 0 (waiting state) is so that if multiple NPC/Creatures are watching this same global variable status to change their hostility (using the Ability script we added), we want to give the game a few frames to think about it so all of them get the message. | |||
This is something I have discovered in troubleshooting some issues with actor scripts seemingly losing the ability to effect the global through their menu. I believe this has been resolved by adding the Ability to their spell list directly in the editor rather than attempting to do so on-the-fly via additional scripting. This method eliminates some unnecessary complexity, and seems to work better. Your mileage may vary. | |||
Best of luck! | Best of luck! | ||