Adding spells at start of combat?

Post » Fri May 27, 2011 3:58 pm

I've been wondering how to add abilities to NPCs and creatures whenever they begin combat with either the player or another NPC/creature. Then have those same abilities removed when the combat ends. I know how to use the basic MWSE script functions for players, but not for NPCs and creatures getting into combat. I'm wanting to add one basic ability that kicks in at the start of a fight to the NPCs and then another different ability for creatures. Is this possible with MWSE functions and if so how would I go about doing it? Thanks in advance for any help provided by you.
User avatar
Dan Endacott
 
Posts: 3419
Joined: Fri Jul 06, 2007 9:12 am

Post » Fri May 27, 2011 11:55 pm

As far as I know, you can use xGetCombat on npcs and creatures as well, not just the player.

However, most companion scripts use non-MWSE ways to detect combat. GetWeaponDrawn and GetSpellReadied is one way combat is detected, as well as attack voices, which is the most reliable. Making a new attack voice for your npc and setting a variable in that voice entry to trigger whatever you want to do with their scripting is how companions like Julan and others can be forced to stay passive if they're in pacifist mode, so I'm sure you can adapt that to your uses with an npc. Those won't work for a creature though unfortunately.
User avatar
lucy chadwick
 
Posts: 3412
Joined: Mon Jul 10, 2006 2:43 am

Post » Fri May 27, 2011 7:05 pm

Yes that was the problem I was running into. I was going to use the GetWeaponDrawn function for the PC. And then try the xGetCombat script on both Creatures and NPCs. The only problem was that I don't know of a way to use that function on creatures and NPCs correctly. The main thing is that I want this to work without having to place a script on each individual actor in the construction set in order to ensure compatibility with other mods. That's why I was wondering if MWSE could help me out on that front.
User avatar
Josh Lozier
 
Posts: 3490
Joined: Tue Nov 27, 2007 5:20 pm

Post » Fri May 27, 2011 9:17 pm

You can use xGetRef and xSetRef to call a specific creature or npc without having to make a script for each creature/npc.

So I think its:

long refID ;call it anything you like, this is a string that is set to whatever creatures/npcs you want later in the scriptlong tmp ;temporary/junk refsetx refID to xGetRef "creature_or_npc_ID"set tmp to xGetCombat refIDif ( tmp ) ;combat is detected     refID->AddSpell "spell_ID"else ;not in combat     refID->RemoveSpell "spell_ID"endif;continue to do this for all your creatures/npcs


I think that should work. I'm fairly new to MWSE myself. You shouldn't need to make separate variables for each creature or npc, as it overwrites the variable as its called down the script.

If you're talking about adding this to all npcs or creatures and not specific ones, it gets slightly more complicated. You then have to check the entire cell for creatures or npcs using xGetRefType, and if the script is constantly running, it can cause a bit of an fps hit.
User avatar
Brandon Wilson
 
Posts: 3487
Joined: Sat Oct 13, 2007 1:31 am

Post » Fri May 27, 2011 2:30 pm

If you're talking about adding this to all npcs or creatures and not specific ones, it gets slightly more complicated. You then have to check the entire cell for creatures or npcs using xGetRefType, and if the script is constantly running, it can cause a bit of an fps hit.

It isn't noticeable. In other words no-one has complained about it yet. :)
User avatar
Robyn Lena
 
Posts: 3338
Joined: Mon Jan 01, 2007 6:17 am

Post » Fri May 27, 2011 12:42 pm

That's good because I was wanting it to work on all creatures and NPCs constantly throughout the game :) . Sorry for not clarifying Stuperstar.

So how would I be able to give new abilities through the xGetRefType function? I've tried a few months back at trying to get cell based scripts to work but had never been successful.

And just to help prevent confusion, my goal for this part of the mod is to have a Fortify Attack ability automatically given to all NPCs that get into a fight. Maybe creatures as well if fortify attack works on them too, but I'm not sure it does so I was planning on adding some agility buffs to them with the same script as a substitute. Then for the PC I already have a script that adds a fortify attack ability to the player each time his/her weapon is drawn and then it removes the ability when the weapon is sheathed. This is essentially to make all strikes have a 100% chance to hit in the game without messing with the actual weapon skills. Then I plan to add player controlled blocking like Oblivion which I already have partially implemented ( mostly to eliminate the need of MWE for such a skill ).

Btw, thanks again for the help you have given me.
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Fri May 27, 2011 11:08 am

Ah ok, thanks for clarifying. I've done a similar check in one of my own scripts, so here's what you do:

long npcRef ;change the variables to whatever you wantlong tmpifx ( npcRef )   setx npcRef to xNextRef npcRef ;finds the next NPC or creature in the cellelse   setx npcRef to xFirstNPC ;finds the first NPC or creature in the cellendifif ( npcRef == 0 )   ;end of list or empty cell   returnendifsetx tmp to npcRef->xRefTypeif ( tmp != 1598246990 ) ;if not type NPC   if ( tmp != 1095062083 ) ;if not type Creature      return   endifendif;now do something like I wrote above to add and remove spells. You'll have to use those numbers again to check if it's an npc or creature


@Yacoby: Thanks for letting me know that. I was a little worried about my own scripts that is running constantly to check for npcs in a cell and do stuff.
User avatar
Chantelle Walker
 
Posts: 3385
Joined: Mon Oct 16, 2006 5:56 am

Post » Fri May 27, 2011 12:19 pm

Thank you soooo much Stuporstar! I just ran a quick test and it works perfectly on both creatures and NPCs :foodndrink: . I'll be sure to put your name down in the credits for your addition to the mod when I get this thing complete.

I'll be fine tuning the rest of the mod over the weekend but while I'm at it I was wondering if you knew of a way to temporarily disable attacking through scripts? With the new blocking on command button I've put in, I'm wanting to prevent the player from being able to attack while at the same time block but I haven't gotten it to work correctly yet. I believe another modder a long time ago managed to do this even without MWSE (although it was a bit buggy) but I'm not sure how he did it. Any ideas?
User avatar
no_excuse
 
Posts: 3380
Joined: Sun Jul 16, 2006 3:56 am

Post » Fri May 27, 2011 4:02 pm

Thank you soooo much Stuporstar! I just ran a quick test and it works perfectly on both creatures and NPCs :foodndrink: . I'll be sure to put your name down in the credits for your addition to the mod when I get this thing complete.

I'll be fine tuning the rest of the mod over the weekend but while I'm at it I was wondering if you knew of a way to temporarily disable attacking through scripts? With the new blocking on command button I've put in, I'm wanting to prevent the player from being able to attack while at the same time block but I haven't gotten it to work correctly yet. I believe another modder a long time ago managed to do this even without MWSE (although it was a bit buggy) but I'm not sure how he did it. Any ideas?


Ah, that's easy.Use DisablePlayerFighting and DisablePlayerMagic.It, along with other DisableControls prevents the player to use certain parts of Morrowind.Mainly used in chargen and cutscenes.You'll have to make NPCs and creatures weapon skill and/or agility drained to 0,though,or if the blind effect actually works use it(Reports indicate blind works on NPCs and creatures but not on the player, but i'm not sure) as there is no DisableNPCControls command (Yes, you have a command which disables them all at once too).

EDIT:Forgot to say that you should use EnablePlayerFighting and EnablePlayerMagic to turn them back on.
Full info here:
http://content1.uesp.net/wiki/Tes3Mod:DisableControls
http://content1.uesp.net/wiki/Tes3Mod:EnableControls
User avatar
Siidney
 
Posts: 3378
Joined: Fri Mar 23, 2007 11:54 pm

Post » Fri May 27, 2011 9:14 pm

I've already tried that function a long time ago. The problem with it was that is only disabled drawing/sheathing your weapon.What I'm actually trying to do is disable swinging with the weapon once it's out. Again sorry for not being clear enough ;) . Any other thoughts on how to accomplish this? Btw thanks for the help (Insert name here) .
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm

Post » Fri May 27, 2011 12:54 pm

I've already tried that function a long time ago. The problem with it was that is only disabled drawing/sheathing your weapon.What I'm actually trying to do is disable swinging with the weapon once it's out. Again sorry for not being clear enough ;) . Any other thoughts on how to accomplish this? Btw thanks for the help (Insert name here) .



That's impossible, even with MWE (I use both extenders).I'm a user of Aerelorn's Blocking Enhanced and when you block you can still swing your weapon around, you just never hit.I suppose you want the player's weapon drawn for that fortify attack script?
You're going to have to settle for removing the fortify attack effect and draining the weapon skill of the player, and blinding NPCs and creatures and removing their fortify attack effect.As far as I know, fortify attack works on both creatures, NPCs and the player, and blind on creatures and NPCs, but not the player.
User avatar
Alexandra Ryan
 
Posts: 3438
Joined: Mon Jul 31, 2006 9:01 am


Return to III - Morrowind