dizietemblesssma Posted April 20, 2020 Share Posted April 20, 2020 Assuming that I'm right in thinking that I can give an NPC an ability - how would a script (the effect script) refer to the NPC actor, if you don't kow in advance who the NPC will be? diziet Link to comment Share on other sites More sharing options...
maxarturo Posted April 21, 2020 Share Posted April 21, 2020 (edited) I'm assuming that the ability will be added to the npc with some sort of spell casted from the player (fire & forget). Spell Property AbilitySpell Auto Actor ActorRef Event OnEffectStart(Actor Target, Actor Caster) ActorRef = Target If ( ActorRef.isDead() == False ) ActorRef.AddSpell(AbilitySpell) EndIf EndEvent Edited April 21, 2020 by maxarturo Link to comment Share on other sites More sharing options...
dizietemblesssma Posted April 21, 2020 Author Share Posted April 21, 2020 But would this allow the effect script for ability (AbilitySpell?) to reference the target?Would I need to make the casting spell have: Scriptname AbilityCastingSpell extends ActiveMagicEffect Actor Property ActorRef Auto ;;stuff and then in the ability effect script have: AbilityCastingSpell Property abs Auto Holder_of_ability = abs.Actorref ;;more_stuff ? diziet Link to comment Share on other sites More sharing options...
maxarturo Posted April 21, 2020 Share Posted April 21, 2020 I don't really understand what you are trying to say, but... I have a "Fire and Forget" hostile spell (it's used only by some of my vamp enemies), when the spell projectile hits an enemy that is not hostile to the caster it will add to the targeted actor an "Ability" spell that is actually a scripted desease, the "ActiveMagicEffect" that fires the projectile has those lines in its script, and it will always add the "Ability" spell to any actor that hits. The "ActiveMagicEffect" has only 1 condition "IsHostileToActor". Link to comment Share on other sites More sharing options...
dizietemblesssma Posted April 22, 2020 Author Share Posted April 22, 2020 What I'd like is for the ability running on the target to have a script attached that can refer to to the target itself. So I have a spell to give an NPC the ability, here the NPC is the 'akTarget'' of the player casting the spell, but in the script attached to the ability itself there is no akTarget or akSource, I could try to pass a variable from the casting spell to the ability script with the akTarget value, but I don't know if that variable will then stay locally constant to each NPC that is given the ability or if every time a new NPC gains the ability the other instances of the ability will have the wrong value for the NPC in their script instances. Not sure if I have explained this right. diziet Link to comment Share on other sites More sharing options...
maxarturo Posted April 22, 2020 Share Posted April 22, 2020 I kind of get it, but in order for anyone to be able to help you, there are quite a few individuals that can, you need to post those scripts with an explanation of the idea > what your script is trying to do. * I do understand the fear of someone stealing your idea/script, but that's the only way. Only you are in front of your PC !. Link to comment Share on other sites More sharing options...
dylbill Posted April 22, 2020 Share Posted April 22, 2020 @Diziet, yes, you can put the script on the abilities magic effect and it will store the actor for each NPC it is given to. Each active magic effect is it's own instance. Actor ActorRef Event OnEffectStart(Actor akTarget, Actor akCaster) ActorRef = akTarget EndEvent Event SomeOtherEvent() ;do stuff with ActorRef EndEventIf, however, you need to access the actors from another script, I would recommend using a formlist. Formlist Property ModAbilityActors Auto Event OnEffectStart(Actor akTarget, Actor akCaster) ModAbilityActors.AddForm(akTarget) EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) ModAbilityActors.RemoveAddedForm(akTarget) EndEvent Link to comment Share on other sites More sharing options...
maxarturo Posted April 22, 2020 Share Posted April 22, 2020 It would be wise to post your scripts. But, if i do understand correctly this is how it should go: Script on the "ActiveMagicEffect" of the spell that will transfere the "Ability Spell". Spell Property AbilitySpell Auto Actor ActorRef Event OnEffectStart(Actor Target, Actor Caster) ActorRef = Target If ( ActorRef.isDead() == False ) ActorRef.AddSpell(AbilitySpell) EndIf EndEvent Script on the "ActiveMagicEffect" of the "Ability Spell" that has been transfered to the targeted actor: Actor SelfRef Event OnEffectStart(Actor Target, Actor Caster) SelfRef = Caster If ( SelfRef.isDead() == False ) ; Do your Stuff EndIf EndEvent * If i still haven't understand you clearly, then sorry !... * dylbill post is also correct, although i think neither he has understand you correctly. Not our fault... Link to comment Share on other sites More sharing options...
dizietemblesssma Posted April 22, 2020 Author Share Posted April 22, 2020 Hi, Certainly not your fault of course! :smile: I held off posting my scripts because I'm aware that what I'm doing has already been done, but I'm actually enjoying trying to do it anyway! Here is the ability effect script as written so far (doesn't compile as yet) Scriptname dz_location_change_ability_effect Extends ActiveMagicEffect ;;we need access to the mcm menu variables dz_outfit_change_menu Property dz_mcm Auto ;;we need acccess to the NPC's name according to the spell granting the ability dz_give_location_change_ability_spell Property abspell Auto Keyword Property LocTypeCity Auto Keyword Property LocTypeTown Auto Keyword Property LocTypePlayerHouse Auto Actor Property PlayerRef Auto String outfit_type String default String town String pleasant String rainy String snowy String playerh String swimming Actor this_npc String this_npc_name Int slot_index String env Event OnEffectStart(Actor Target, Actor Caster) this_npc = abspell.ActorRef this_npc_name = this_npc.GetBaseObject().GetName() Int i i = 0 While i < dz_mcm.Pages.Length If dz_mcm.slots[i] == this_npc_name slot_index = i EndIf EndWhile EndEvent Event OnLocationChange(Location akOldLoc, Location akNewLoc) If this_npc.IsInCombat() Return EndIf If akNewLoc.HasKeyword(LocTypeCity) || akNewLoc.HasKeyword(LocTypeTown) env = "town" debug.messagebox("Civilisation") ElseIf akNewLoc.HasKeyword(LocTypePlayerHouse) env = "Playerh" EndIf Weather currentWeather = Weather.GetCurrentWeather() If currentWeather.GetClassification() == -1 outfit_type = default ElseIf currentWeather.GetClassification() == 0 outfit_type = pleasant ElseIf currentWeather.GetClassification() == 1 outfit_type = rainy ElseIf currentWeather.GetClassification() == 2 outfit_type = rainy ElseIf currentWeather.GetClassification() == 3 outfit_type = snowy EndIf If this_npc.IsPlayerTeammate() dz_fill_teammate(this_npc) EndIf EndEvent Function dz_fill_teammate(Actor NPCRef) If env == playerh dz_fill_outfit(NPCRef,dz_mcm.playerh_outfits) ElseIf env == town If outfit_type == snowy dz_fill_outfit(NPCRef,dz_mcm.snowy_outfits) Else dz_fill_outfit(NPCRef,dz_mcm.town_outfits) EndIf ElseIf outfit_type == snowy dz_fill_outfit(NPCRef,dz_mcm.snowy_outfits) ElseIf outfit_type == rainy dz_fill_outfit(NPCRef,dz_mcm.rainy_outfits) ElseIf outfit_type == pleasant dz_fill_outfit(NPCRef,dz_mcm.pleasant_outfits) ElseIf outfit_type == default dz_fill_outfit(NPCRef,dz_mcm.default_outfits) EndIf EndFunction Function dz_fill_outfit(Actor NPCRef, Formlist[] outfit_array) Form[] Items FormList outfit_formlist outfit_formlist = outfit_array[slot_index] Items = outfit_formlist.ToArray() int i ;define this variable for use in arrays i = 0 While i < Items.Length ;loop through the stored items If Items[i] As Armor || Items[i] As Ammo || Items[i] As Light ;if stored items are armour or ammo or torch this_npc.EquipItemEx(Items[i],0,True,True) ;re-equip them EndIf i = i +1 EndWhile EndFunction ;/ Function dz_fill_town(Actor NPCRef) Form[] Items FormList town_formlist town_formlist = dz_mcm.town_outfits[slot_index] Items = town_formlist.ToArray() int i ;define this variable for use in arrays i = 0 While i < Items.Length ;loop through the stored items If Items[i] As Armor || Items[i] As Ammo || Items[i] As Light ;if stored items are armour or ammo or torch this_npc.EquipItemEx(Items[i],0,True,True) ;re-equip them EndIf i = i +1 EndWhile EndFunction /; here is my effect script for the spell to give an NPC the ability: Scriptname dz_give_location_change_ability_spell Extends ActiveMagicEffect Spell Property dz_location_change_ability Auto Actor Property ActorRef Auto Event OnEffectStart(Actor Target, Actor Caster) ActorRef = Target If ( ActorRef.isDead() == False ) ActorRef.AddSpell(dz_location_change_ability) EndIf EndEvent note that the first effect script refers back to a third script, an mcm script in which the second spell is toggled on/off: Scriptname dz_outfit_change_menu Extends SKI_ConfigBase Actor Property PlayerRef Auto Spell Property dz_give_location_change_spell Auto ------snip------------------ State toggle_on Event OnSelectST() dz_activate_changing() EndEvent Event OnDefaultST() activate_toggle[index] = False SetToggleOptionValueST(activate_toggle[index]) EndEvent Event OnHighlightST() SetInfoText("$Activate the auto changing option") EndEvent EndState ----------------snip------------------- Function dz_activate_changing() spell my_spell my_spell = dz_give_location_change_spell activate_toggle[index] = !activate_toggle[index] SetToggleOptionValueST(activate_toggle[index]) If slots[index] If activate_toggle[index] == True my_spell.cast(slots[index]) ShowMessage("Auto changing activated for "+slots[index].GetBaseObject().GetName(),False) ElseIf activate_toggle[index] == False slots[index].DispelSpell(my_spell) ShowMessage("Auto changing de-activated for "+slots[index].GetBaseObject().GetName(),False) EndIf Else ShowMessage("There is no-one assigned to this slot",False) activate_toggle[index] = False EndIf EndFunction ---------------------snip-------------------------- as you can see, the third mcm script passess a variable from an array - slots[index] - as the target of the spell that the player casts or dispells according to the mcm script toggle, the second script is the spell that is cast or dispelledthe first script on the NPC refers back to this so that the NPC can react to its own location change, rather than the location change of the player (which would have been a lot easier!) the whole mcm script is here, but I should warn you, it's very unwieldly:) Scriptname dz_outfit_change_menu Extends SKI_ConfigBase Actor Property PlayerRef Auto Spell Property dz_give_location_change_spell Auto FormList[] Property default_outfits Auto ;define the arrays to store outfits in FormList[] Property playerh_outfits Auto FormList[] Property town_outfits Auto FormList[] Property pleasant_outfits Auto FormList[] Property rainy_outfits Auto FormList[] Property snowy_outfits Auto Actor[] slots ;each slot has the NPC reference for the page ;Actor teammate Bool[] slot_toggle Bool[] activate_toggle Bool[] all_outfit_toggle ;are the page outfits being reset? Bool[] default_outfit_toggle ;array to store default outfit toggles Bool[] player_house_outfit_toggle ;array to store playerh outfit toggles Bool[] town_outfit_toggle ;array to store town/city outfit toggles Bool[] pleasant_outfit_toggle ;array to store pleasant outfit toggles Bool[] rainy_outfit_toggle ;array to store rainy outfit toggles Bool[] snowy_outfit_toggle ;array tp store snowy outfit toggles Bool being_forced ;is the page reset a forced one? String[] old_pages ;store the page names upon menu open Int index ;store the page index of current page Int Function GetVersion() ;version function Return 1 ; Default version EndFunction Event OnConfigInit() ;when the mod is first installed Pages = New String[11] ;fill the array of page names once on mod install Pages[0] = PlayerRef.GetBaseObject().GetName() Pages[1] = "slot1" Pages[2] = "slot2" Pages[3] = "slot3" Pages[4] = "slot4" Pages[5] = "slot5" Pages[6] = "slot6" Pages[7] = "slot7" Pages[8] = "slot8" Pages[9] = "slot9" Pages[10] = "slot10" slots = New Actor[11] ;fill array old_pages = New String[11] ;fill array default_outfit_toggle = New Bool[11] ;fill array player_house_outfit_toggle = New Bool[11] ;fill array town_outfit_toggle = New Bool[11] ;fill array pleasant_outfit_toggle = New Bool[11] ;fill array rainy_outfit_toggle = New Bool[11] ;fill array snowy_outfit_toggle = New Bool[11] ;fill array activate_toggle = New Bool[11] ;fill array EndEvent Event OnConfigOpen() ;when the menu is opedned Int i String temp i = 0 While i < Pages.Length ;fill the old pages array temp = Pages[i] old_pages[i] = temp i = i + 1 EndWhile Actor teammate ;get the reference for the NPC under the crosshair teammate = Game.GetCurrentCrosshairRef() as Actor String teammate_name ;get the name of the NPC under the crosshair teammate_name = teammate.GetBaseObject().GetName() If teammate ShowMessage("The currently selected character is "+teammate_name,False) ;inform as to current NPC Else ShowMessage("No character is selected under the crosshair",False) ;inform that no NPC under the crosshair EndIf EndEvent Event OnPageReset(String a_page) If a_page == "" ;exit if page is "" ;ShowMessage("a_page = \"\" Returning",False) Return EndIf ;;what is the index of this page? index = dz_find_page_index(a_page) ;get the index of the selected page debug.messagebox("on page reset debug - index = "+index) debug.messagebox("on page reset debug - slots[index] = "+slots[index]) If slots[index] SetTitletext(slots[index].GetBaseObject().GetName()) ;set the titletext of the page if the page has already got an NPC in Else SetTitletext(Pages[index]) ;otherwise use exisitng page name EndIf ;;is this a forced page reset? If being_forced == False ;skip this if-endif block if the page reset is being forced debug.messagebox("this is not a forced reset") ;;is this the character page debug.messagebox("character check - slots[index] = "+slots[index]) If dz_compare_name() == True ;is the page already for the NPC under the crosshair (true = yes) debug.messagebox("this is the characters page") ;;is this page in use or the player page? ElseIf dz_test_page_name(a_page) == True ;is this page for a different NPC than the one under the crosshair (true = yes) ShowMessage("This slot is being used, either reset it or choose another slot.",False) ElseIf dz_test_character() == True ;otherwise does the NPC under the crosshair have a different page (true = yes) ShowMessage("This character already has a slot") Else ;;set the page name, titletext and fill slots[index] dz_set_page_name() ;if none of the above, fill the page name with the NPC under the crosshair and fill the slots[] array at the appropriate index EndIf ElseIf being_forced == True ;ignore the previous block if this is a forced page reset EndIf SetCursorFillMode(TOP_TO_BOTTOM) ;fill the page with toggles etc. SetCursorPosition(0) AddHeaderOption("$Reset") ;show the toggle for reseting the outfits and page name AddtoggleOptionST("reset_page","$Reset_this_page?", all_outfit_toggle[index]) AddEmptyOption() AddEmptyOption() AddHeaderOption("$Default/Combat") ;show the toggle to setting/unsetting the default outfit AddtoggleOptionST("default","$Default_Outfit_set?", default_outfit_toggle[index]) AddEmptyOption() AddEmptyOption() AddHeaderOption("$Activate") ;show the toggle to activate/deactivate auto changing for the NPC (uses a spel) AddtoggleOptionST("toggle_on","$Activate auto changing for this character?", activate_toggle[index]) SetCursorPosition(1) AddHeaderOption("$Location") ;show the toggles to setting/unsetting the location based outfits SetCursorPosition(3) AddtoggleOptionST("playerh","$House_Outfit_set?", player_house_outfit_toggle[index]) SetCursorPosition(5) AddtoggleOptionST("town","$City_Outfit_set?", town_outfit_toggle[index]) SetCursorPosition(9) AddHeaderOption("Weather") ;show the toggles to setting/unsetting the weather based outfits SetCursorPosition(11) AddtoggleOptionST("pleasant","$Pleasant_Outfit_set?", pleasant_outfit_toggle[index]) SetCursorPosition(13) AddtoggleOptionST("rainy","$Cloudy/Rainy_outfit_set?", rainy_outfit_toggle[index]) SetCursorPosition(15) AddtoggleOptionST("snowy","$Snowy_outfit_set?", snowy_outfit_toggle[index]) ;/ SetCursorPosition(17) AddHeaderOption("$Swimming/Wading") SetCursorPosition(19) iswimming = Adpleasant_outfit_toggleOption("Swimming outfit set", _toggle_swimming) /; debug.messagebox("finished page reset") being_forced = False EndEvent State reset_page ;this is the state for deleting outfits and resetting the page name Event OnSelectST() dz_reset_toggles() EndEvent Event OnDefaultST() ;what is the default setting for this toggle all_outfit_toggle[index] = False SetToggleOptionValueST(all_outfit_toggle[index]) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Reset (delete) the outfits and clear the slot?") EndEvent EndState State toggle_on ;this is the state for activating/deactivating the auto changing Event OnSelectST() dz_activate_changing() EndEvent Event OnDefaultST() ;what is the default setting for this toggle activate_toggle[index] = False SetToggleOptionValueST(activate_toggle[index]) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Activate the auto changing option") EndEvent EndState State default ;this is the state for setting/unsetting the default outfit Event OnSelectST() dz_toggle_outfit(default_outfit_toggle,"$Set_the_Default_Outfit_for ","$Remove_the Default_Outfit_for ",default_outfits) EndEvent Event OnDefaultST() ;what is the default setting for this toggle default_outfit_toggle[index] = False SetToggleOptionValueST(default_outfit_toggle[index]) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Set the default outfit") EndEvent EndState State playerh ;this is the state for setting/unsetting the player home outfit Event OnSelectST() dz_toggle_outfit(player_house_outfit_toggle,"$Set_PlayerHouse_Outfit_for ","$Remove_the_PlayerHouse_Outfit_for ",playerh_outfits) EndEvent Event OnDefaultST() ;what is the default setting for this toggle player_house_outfit_toggle[index] = False SetToggleOptionValueST(player_house_outfit_toggle) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Set the outfit for inside the playerhouse") EndEvent EndState State town ;this is the state for setting/unsetting the towns and cities outfit Event OnSelectST() dz_toggle_outfit(town_outfit_toggle,"$Set_the_Towns and Cities_Outfit_for ","$Remove_the_Towns_and_Cities_Outfit_for ",town_outfits) EndEvent Event OnDefaultST() ;what is the default setting for this toggle town_outfit_toggle[index] = False SetToggleOptionValueST(town_outfit_toggle) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Set the outfit for towns/cities") EndEvent EndState State pleasant ;this is the state for setting/unsetting the pleasant weather outfit Event OnSelectST() dz_toggle_outfit(pleasant_outfit_toggle,"$Set_Peasant_Weather_Outfit_for ","$Remove_the_Pleasant_Weather_Outfit_for ",pleasant_outfits) EndEvent Event OnDefaultST() ;what is the default setting for this toggle pleasant_outfit_toggle[index] = False SetToggleOptionValueST(pleasant_outfit_toggle) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Set the outfit for pleasant weather") EndEvent EndState State rainy ;this is the state for setting/unsetting the rainy or cloudy weather outfit Event OnSelectST() dz_toggle_outfit(rainy_outfit_toggle,"$Set_The Rainy_Weather_Outfit_for ","$Remove_the_Rainy_Weather_Outfit_for ",rainy_outfits) EndEvent Event OnDefaultST() ;what is the default setting for this toggle rainy_outfit_toggle[index] = False SetToggleOptionValueST(rainy_outfit_toggle) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Set the outfit for cloudy or rainy weather") EndEvent EndState State snowy ;this is the state for setting/unsetting the snowy weather outfit Event OnSelectST() dz_toggle_outfit(snowy_outfit_toggle,"$Set_the_Snowy_Weather_Outfit_for ","$Remove_the_Snowy_Weather_Outfit_for ",snowy_outfits) EndEvent Event OnDefaultST() ;what is the default setting for this toggle snowy_outfit_toggle[index] = False SetToggleOptionValueST(snowy_outfit_toggle) EndEvent Event OnHighlightST() ;text shown on mouse hover over this toggle SetInfoText("$Set the outfit for snowy weather") EndEvent EndState ;;this function finds the page index of the selected page Int Function dz_find_page_index(String a_page) Int i i = 0 While i < Pages.Length If Pages[i] == a_page ;test against current page names Return i ElseIf old_pages[i] == a_page ;test against page names stored on menu open, the mcm does not update as one might think, leading to inconsistent results Return i EndIf i = i + 1 EndWhile EndFunction ;;this function tests if the selected page is being used by an NPC (true = yes) Bool Function dz_test_page_name(String a_page) debug.messagebox("test_page_debug - Slots[index] = "+slots[index]+" index = "+index) If a_page != Pages[0] If slots[index] != NONE Return True ;this page is being used EndIf EndIf Return False ;this page is not being used EndFunction ;;this function tests if the NPC under th crosshair already has a page (true = yes) Bool Function dz_test_character() Actor teammate teammate = Game.GetCurrentCrosshairRef() as Actor Int i i = 0 While i < Pages.Length If slots[i] == teammate ShowMessage("This character already has a slot",False) Return True ;the character already has a slot EndIf i = i + 1 EndWhile Return False ;the character does not have a slot EndFunction ;;this function tests if the selected page is for the NPC under the crosshair (true = yes) Bool Function dz_compare_name() Actor teammate teammate = Game.GetCurrentCrosshairRef() as Actor If slots[index] == teammate Return True ;this is the character page Else Return False ;this is not the character page EndIf EndFunction ;;this function sets the name of the page to the NPC under the crosshair, it fills the slots array at the page index and sete the page titletext Function dz_set_page_name() ;debug.messagebox("Starting to set the page name") Actor teammate teammate = Game.GetCurrentCrosshairRef() as Actor String teammate_name teammate_name = teammate.GetBaseObject().GetName() Pages[index] = teammate_name SetTitletext(teammate_name) slots[index] = teammate debug.messagebox("set_page_name_debug - slots[index] = "+slots[index]+" teammate = "+teammate) EndFunction ;;this function calls the function that removes all stored outfits at the page index Function dz_reset_toggles() all_outfit_toggle[index] = !all_outfit_toggle[index] SetToggleOptionValueST(all_outfit_toggle[index]) If index != 0 If ShowMessage("$Reset (delete) the outfits and clear the NPC name?",True) dz_delete_outfits() EndIf ElseIf index == 0 If ShowMessage("$Reset (delete) the outfits for "+Pages[0]+"?",True) dz_delete_outfits() EndIf being_forced = True ;debug.messagebox("being_forced = "+being_forced) ForcePageReset() Else all_outfit_toggle[index] = False EndIf EndFunction ;;this function removes outifts stored on the selected page, empties the slots[] index for the page and resets the page titletext Function dz_delete_outfits() Formlist a ;create empty formlist Actor[] b ;create empty array default_outfits[index] = a default_outfit_toggle[index] = False SetToggleOptionValueST(default_outfit_toggle) playerh_outfits[index] = a player_house_outfit_toggle[index] = False SetToggleOptionValueST(player_house_outfit_toggle) town_outfits[index] = a town_outfit_toggle[index] = False SetToggleOptionValueST(town_outfit_toggle) pleasant_outfits[index] = a pleasant_outfit_toggle[index] = False SetToggleOptionValueST(pleasant_outfit_toggle) rainy_outfits[index] = a rainy_outfit_toggle[index] = False SetToggleOptionValueST(rainy_outfit_toggle) snowy_outfits[index] = a snowy_outfit_toggle[index] = False SetToggleOptionValueST(snowy_outfit_toggle) If index != 0 Pages[index] = "slot"+index ;reset the page name to original slots[index] = b[index] ;empty slots[] index SetTitletext(Pages[index]) ;reset page titletext EndIf ShowMessage("Done!",False) all_outfit_toggle[index] = False ;reset toggle to empty EndFunction ;;this function casts/dispels the spell used by the player to give NPCs the abiity to auto change Function dz_activate_changing() spell my_spell my_spell = dz_give_location_change_spell ;name of the spell activate_toggle[index] = !activate_toggle[index] SetToggleOptionValueST(activate_toggle[index]) If slots[index] ;check this page has an NPC If activate_toggle[index] == True ;if no9 spell then cast it my_spell.cast(slots[index]) ShowMessage("Auto changing activated for "+slots[index].GetBaseObject().GetName(),False) ElseIf activate_toggle[index] == False slots[index].DispelSpell(my_spell) ;if has spell dispell it ShowMessage("Auto changing de-activated for "+slots[index].GetBaseObject().GetName(),False) EndIf Else ShowMessage("There is no-one assigned to this slot",False) ;else no NPC, do nothing and ensure toggle is empty activate_toggle[index] = False EndIf EndFunction ;;this function fills the passed in outfit array with a formlist of the equipped items worn by the NPC of the selected page at the appropriate index Function dz_toggle_outfit(Bool[] z_toggle,String set_message,String remove_message,FormList[] outfits_array) Actor teammate teammate = Game.GetCurrentCrosshairRef() as Actor ;need to know the NPC reference If slots[index] != teammate ;check if the page can be used ShowMessage("This slot cannot be used to assign outfits for this character\n If you have just reset the page, try reselecting the slot on the left") Return EndIf Formlist a debug.messagebox("toggle option debug - first toggle index = "+z_toggle[index]) z_toggle[index] = !z_toggle[index] ;change the toggle appearance SetToggleOptionValueST(z_toggle[index]) debug.messagebox("toggle option debug - second toggle index = "+z_toggle[index]) If z_toggle[index] == True ;if new appearance of the toggle is on If index == 0 ;this block is for the player If ShowMessage(set_message+" "+Pages[0]+"?",True) ;if accept message to set outfit, then proceed debug.messagebox("toggle option debug - getting player kit") outfits_array[index] = dz_get_kit(PlayerRef) ;fill the array using get_kit function ;dz_get_weapons(PlayerRef) ;maybe do weapons later Else ;if didn't accept the message prompt z_toggle[index] = False ;ensure the toggle stays empty being_forced = True ;indicate following page reset is forced (to avoid setting page name again etc.) ForcePageReset() ;force page reset to update toggle appearance EndIf ElseIf slots[index] == teammate ;this block is for NPCs If ShowMessage(set_message+" "+slots[index]+"?",True) ;if accept message to set outfit, then proceed debug.messagebox("toggle option debug - getting character kit") outfits_array[index] = dz_get_kit(teammate) ;fill the array using get_kit function ;dz_get_weapons(teammate) Else ;if didn't accept the message prompt z_toggle[index] = False ;ensure the toggle stays empty being_forced = True ;indicate following page reset is forced (to avoid setting page name again etc.) ForcePageReset() ;force page reset to update toggle appearance EndIf Else ;if not the player or NPC's page ShowMessage("$You cannot assign outfits on this page\n Have you tried selecting the slot to set the page title, or choosing an empty slot?",False) ;debug.messagebox("Assign = "+assign) z_toggle[index] = False ;ensure toggle is empty being_forced = True ;indicate following page reset is forced (to avoid setting page name again etc.) ForcePageReset() ;force page reset to update toggle appearance EndIf ElseIf z_toggle[index] == False ;if new appearance of the toggle is off(empty) If ShowMessage(remove_message+" "+Pages[index]+"?",True) ;ask if wish to remove outfit and if yes debug.messagebox("toggle option debug - removing kit") outfits_array[index] = a ;set outfits array index to empty Else ;if don't accept message then z_toggle[index] = True ;ensure toggle remains on(full) being_forced = True ;indicate following page reset is forced (to avoid setting page name again etc.) ForcePageReset() ;force page reset to update toggle appearance EndIf EndIf EndFunction ;;this function gets the equipped items in an array. fills a formlist from the array and adds the formliat to the outfits array Formlist Function dz_get_kit(Actor aRef) Formlist ItemList ;temporary formlaist Form[] Items ;temporary array Items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(aRef) ;fill array with equipped items ItemList.AddForms(Items) ;add temp array items to formlist Return ItemList ;return items as a formlist EndFunction ;/ Function dz_get_weapons(Actor aRef) all_weapons[2 * index] = aRef.GetEquippedWeapon(True) ;get lefthamd weapon all_weapons[2 * index + 1] = aRef.GetEquippedWeapon(False) ;get righthand weapon EndFunction Function dz_get_spells(Actor aRef) all_spells[4 * index] = aRef.GetEquippedSpell(0) ;get left hand spell all_spells[4 * index + 1] = aRef.GetEquippedSpell(1) ;get right hand spell all_spells[4 * index + 2] = aRef.GetEquippedSpell(2) ;get other spell all_spells[4 * index + 3] = aRef.GetEquippedSpell(3) ;get instant spell EndFunction /; diziet edit: since I've ended up posting the mcm script anyway, I went through it commenting it so any bored soul can follow my madness! Makes the zombie apocolypse look attractive. :smile:does nexus change tabs to spaces or something? Link to comment Share on other sites More sharing options...
dylbill Posted April 22, 2020 Share Posted April 22, 2020 Hey, in your first script, you cannot access the ActorRef from the second script, because the ActorRef property is on an active magic effect. Instead, just set the This_NPC property directly in the ability magic effect script. I'd also use GetDisplayName instead of GetBaseObject.GetName() ;;we need access to the mcm menu variables dz_outfit_change_menu Property dz_mcm Auto ;;we need acccess to the NPC's name according to the spell granting the ability dz_give_location_change_ability_spell Property abspell Auto Keyword Property LocTypeCity Auto Keyword Property LocTypeTown Auto Keyword Property LocTypePlayerHouse Auto Actor Property PlayerRef Auto String outfit_type String default String town String pleasant String rainy String snowy String playerh String swimming Actor this_npc String this_npc_name Int slot_index String env Event OnEffectStart(Actor Target, Actor Caster) this_npc = Target this_npc_name = this_npc.GetDisplayName() Int i i = 0 While i < dz_mcm.Pages.Length If dz_mcm.slots[i] == this_npc_name slot_index = i EndIf EndWhile EndEvent Event OnLocationChange(Location akOldLoc, Location akNewLoc) If this_npc.IsInCombat() Return EndIf If akNewLoc.HasKeyword(LocTypeCity) || akNewLoc.HasKeyword(LocTypeTown) env = "town" debug.messagebox("Civilisation") ElseIf akNewLoc.HasKeyword(LocTypePlayerHouse) env = "Playerh" EndIf Weather currentWeather = Weather.GetCurrentWeather() If currentWeather.GetClassification() == -1 outfit_type = default ElseIf currentWeather.GetClassification() == 0 outfit_type = pleasant ElseIf currentWeather.GetClassification() == 1 outfit_type = rainy ElseIf currentWeather.GetClassification() == 2 outfit_type = rainy ElseIf currentWeather.GetClassification() == 3 outfit_type = snowy EndIf If this_npc.IsPlayerTeammate() dz_fill_teammate(this_npc) EndIf EndEvent Function dz_fill_teammate(Actor NPCRef) If env == playerh dz_fill_outfit(NPCRef,dz_mcm.playerh_outfits) ElseIf env == town If outfit_type == snowy dz_fill_outfit(NPCRef,dz_mcm.snowy_outfits) Else dz_fill_outfit(NPCRef,dz_mcm.town_outfits) EndIf ElseIf outfit_type == snowy dz_fill_outfit(NPCRef,dz_mcm.snowy_outfits) ElseIf outfit_type == rainy dz_fill_outfit(NPCRef,dz_mcm.rainy_outfits) ElseIf outfit_type == pleasant dz_fill_outfit(NPCRef,dz_mcm.pleasant_outfits) ElseIf outfit_type == default dz_fill_outfit(NPCRef,dz_mcm.default_outfits) EndIf EndFunction Function dz_fill_outfit(Actor NPCRef, Formlist[] outfit_array) Form[] Items FormList outfit_formlist outfit_formlist = outfit_array[slot_index] Items = outfit_formlist.ToArray() int i ;define this variable for use in arrays i = 0 While i < Items.Length ;loop through the stored items If Items[i] As Armor || Items[i] As Ammo || Items[i] As Light ;if stored items are armour or ammo or torch this_npc.EquipItemEx(Items[i],0,True,True) ;re-equip them EndIf i = i +1 EndWhile EndFunction ;/ Function dz_fill_town(Actor NPCRef) Form[] Items FormList town_formlist town_formlist = dz_mcm.town_outfits[slot_index] Items = town_formlist.ToArray() int i ;define this variable for use in arrays i = 0 While i < Items.Length ;loop through the stored items If Items[i] As Armor || Items[i] As Ammo || Items[i] As Light ;if stored items are armour or ammo or torch this_npc.EquipItemEx(Items[i],0,True,True) ;re-equip them EndIf i = i +1 EndWhile EndFunction Link to comment Share on other sites More sharing options...
Recommended Posts