Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Script help? Teammate


chime28
 Share

Recommended Posts

Hi I would like to make a script which allows you to get teammates and not have them tun hostile towards you even when hit. Currently it works on generic NPCs like guards and bandits, but not on named NPCs when they are already hostile.

Accidentally hitting them even once causes them to flip onto me instantly, and all my other "teammates" wouldn't help as the hostile named NPCs are still part of my "teammates".

 

Below is the script modified from the existing script in Skyrim, VoiceCharmFactionScript.

Scriptname NewCharmFactionScript extends ActiveMagicEffect  

Faction Property CharmFaction Auto
Faction Property PlayerFaction Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
     akTarget.AddToFaction(CharmFaction)
     akCaster.StopCombat()
     akTarget.StopCombat()
     CharmFaction.SetAlly(PlayerFaction)
     akTarget.SetPlayerTeammate()
     akTarget.IgnoreFriendlyHits()
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
     akTarget.RemoveFromFaction(CharmFaction)
     akTarget.SetPlayerTeammate(false, false)
     CharmFaction.SetEnemy(PlayerFaction,true,true)
     akTarget.IgnoreFriendlyHits(false)
EndEvent

My current request is

-To find a way so that the named NPCs (when already in hostile BEFORE the spell is casted) do not turn hostile immediately when hit.

 

-if possible, to make my temporary teammates follow me around like in the case of my regular followers? Currently they only do their own stuff (after threat is gone, but still under effect) and will not follow me when I change maps.

 

Thank you in advance to anyone who is willing to help me.

 
Link to comment
Share on other sites

I am not a script guru but i have a remark to start with: For some of the named NPCs you might run into a setting found in the AI settings tab called 'helps nobody'. Only if they are set to help friends and/or allies your magic effect would work.

 

As of your first question my best bet is that you have to stop combat of the target NPC before moving them into the faction. As i read it they are still in combat mode and the additional faction wont stop the already active combat anymore as its the AI package controlling that.

Link to comment
Share on other sites

They made a lot of changes with Skyrim. The named NPC may also be placed in a hostile faction to you, or you may get a crime amount on a hold faction that the named NPC is in, which also may override your 'charmed' faction. All things to think about, but I have no idea, as it seemed random to me. lol

Link to comment
Share on other sites

Yeah it's quite messed up somewhere along the codes. I was thinking of using an EventOnUpdate code to enforce the stop combat effect if they turn hostile towards you, but I can't quite specify the actors involved, such as akcaster and aktarget in the Onupdate code.

 

Any advice to make the magic effect update itself while it is already casted?

 

@Dwiss, if I stopped the combat before adding to the faction, they would somehow reinitiate the combat before the faction code is run, so it made things worse as they will remain hostile towards me while being my "teammate".

Edited by chime28
Link to comment
Share on other sites

Currently I've added the following lines in between the effectstart and effectend.

Event OnEffectUpdate(Actor akTarget, Actor akCaster)
	if akTarget.IsHostiletoActor(akCaster)
		akcaster.stopcombat()
		akTarget.StopCombat()
	endif
Debug.Trace("Got the message!")
EndEvent

Also added the line "registerforupdate(1.0)"

Upon testing couldn't find the debug message popping up at all, I suspect the Effectupdate is not running as I intended.

 

Would anyone kindly tell me how would I implement the function in the context?

Link to comment
Share on other sites

It uses the same update as all others, OnUpdate

In your OnEffectStart, you can register your update frequency.

 

You MUST also have a long enough duration on the effect that allows the update to occur. Perhaps update once a second, and have a duration of 5 seconds.

 

Why bother checking if there is hostility between the caster (you) and the target? Just do the stop combats.

Link to comment
Share on other sites

hmm, I don't know what is going on but I can't seem to work out the oneffectupdate... No matter what update duration I set, it doesn't seem to work...

 

My current code is as follows:
 

Scriptname NewCharmFactionScript extends ActiveMagicEffect  

Faction Property CharmFaction Auto
Faction Property PlayerFaction Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
     akTarget.AddToFaction(CharmFaction)
     akCaster.StopCombat()
     akTarget.StopCombat()
     CharmFaction.SetAlly(PlayerFaction)
     akTarget.SetPlayerTeammate()
     akTarget.IgnoreFriendlyHits()
     registerforupdate(5.0)
EndEvent

Event OnEffectUpdate(Actor akTarget, Actor akCaster)
	if akTarget.IsHostiletoActor(akCaster)
		akcaster.stopcombat()
		akTarget.StopCombat()
	endif
Debug.Trace("Working!")
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
     akTarget.RemoveFromFaction(CharmFaction)
     akTarget.SetPlayerTeammate(false, false)
     CharmFaction.SetEnemy(PlayerFaction,true,true)
     akTarget.IgnoreFriendlyHits(false)
EndEvent

Just to make sure the script is working, I've tested it using EventOnupdate and the trace worked but EventOneffectupdate doesn't seem to be working as it should. It doesn't register at all. Back to the question, any ideas on how to specify the target and caster using EventOnupdate? Otherwise, how should I rewrite the code to activate the oneffectupdate?

Can't really work it out, I was thinking if it's possible to change the AI of the afflicted NPCs so that they act somewhat akin to thralls... But after reading some forums posts around the net, might be impossible to change the AI, unless someone has input on this?
 

Link to comment
Share on other sites

Hmm, one more idea would be to tweak with the relationship rank or removing all other factions. Forgive me for this really newb question, but is it possible for the script to "record" down the original value ie for relationship or factions, then set a new value and restore to the original value at the end of the spell?

Link to comment
Share on other sites

I don't know how to define the actors using Onupdate. I can use Actor Property with caster and target, but I don't know how to set up the target as I've mentioned in my previous post, since the target is supposed to be a variable. 

 

Using akcaster and aktarget returns me the compiling error variable akcaster and aktarget is not defined.

I've looked around online but still am really lost here and I'm not sure how to go on with this, so I'd appreciate if you could show me the sample of code I could refer directly?

Link to comment
Share on other sites

So I found this in the creation kit wiki:

 

Actor caster = ActiveFireEffect.GetCasterActor()

 

Problem is I don't know what to replace the ActiveFireEffect with. I've tried spell IDs and Form IDs of various spells but it just doesn't compile.

 

They would return an error stating

-no viable alternative at input 'ActiveFireEffect'

-required (...)+ loop did not match anything at input '.' (the '.' before GetCastorActor())

-Unknown user flag ActiveFireEffect
 
How should I use GetCastorActor() to define the casting actor?
Edited by chime28
Link to comment
Share on other sites

I still wonder why you didnt follow the advice from Willie and just stop the combat regardless if hostile to you or not. As he said: Reason for combat might not be the actor himself but belonging to a certain hostile faction.

 

And OnUpdate says clearly: Event called periodically if the active magic effect/alias/form is registered for update events. Thats exactly what you want, right?

Link to comment
Share on other sites

Nevermind, I got it to work already. Turns out that the 'getcasteractor' function has to be placed under a function or event to work.

 

Thanks Willie, your input was helpful. :)

 

@Dwiss, as I told Willie, if I removed that line, the NPCs under my control will be inert, which is just as good as having their AI disabled. They will not initiate combat against anything hostile towards them. Right now the code only plays if the target turns hostile against me, so that the ones unaffected will continue fighting the hostiles.

 

And yes, I am aware of the purpose of Onupdate and my intention of using it for my script. I was asking if anyone could help me with defining the actors in the script using Onupdate, of which I managed to figure out after discovering the "getcastoractor" function. 

 

Thanks for your invaluable input anyways.

Link to comment
Share on other sites

Another solution to getting the target of the spell might be:

 

1. You define an actor variable that will be used to store the target actor.

Actor Property TargetActor Auto

 

2. In your OnEffectStart, you set it to the akTarget variable:

TargetActor = akTarget

 

3. You can now use TargetActor in the onUpdate event.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...