lukandroll Posted January 29, 2021 Share Posted January 29, 2021 Hi, I'm new to the ck and scripting and I'm trying to run a script that will add a custom ammo type to all humans npcs in the area This is the script: Scriptname LucasScript extends Quest Keyword Property ActorTypeNPC AutoMiscObject Property AMagazine_Ammo_38Caliber_Small Auto Function LucasScript() ObjectReference[] kActorArray = Game.GetPlayer().FindAllReferencesWithKeyword(ActorTypeNPC, 900.0) ObjectReference npc int i = 0 If kActorArray.Length > 0 While (i < kActorArray.Length) npc = kActorArray npc.AddItem(AMagazine_Ammo_38Caliber_Small) i = i + 1 EndWhile EndIf EndFunction I get this error on the papyrus log however:error: None or invalid form passed in to FindAllReferencesWithKeyword Seems like a problem with the ActorTypeNPC propertyBut I don't know how to declare it since I know nothing about the framework and its objectsCould anyone point me out on what I'm doing wrong? Link to comment Share on other sites More sharing options...
SKKmods Posted January 29, 2021 Share Posted January 29, 2021 The keyword property looks fine, just to be safe try this: ObjectReference PlayerREF = Game.GetPlayer() as ObjectReference ObjectReference[] kActorArray = PlayerREF.FindAllReferencesWithKeyword(ActorTypeNPC, 900.0) Because Game.GetPlayer() returns Actor class by default, whilst it is a superset of ObjectReference FindAllReferencesWithKeyword may not be able to cast in the call. Link to comment Share on other sites More sharing options...
lukandroll Posted January 31, 2021 Author Share Posted January 31, 2021 Thanks, I found out what the problem was I haven't had my properties initialized as the objects they were in the Properties window of the script Now it looks like this: Also I had the ammot declared as a MiscObject, that was wrong also, I declared as a Ammo now The now working script looks like this: Scriptname LucasScript extends Quest Keyword Property ActorTypeNPC Auto Ammo Property AMagazine_Ammo_38Caliber_Small Auto Function GiveAmmoMag38() ObjectReference PlayerREF = Game.GetPlayer() as ObjectReference ObjectReference[] kActorArray = PlayerREF.FindAllReferencesWithKeyword(ActorTypeNPC as Form, 900000.0) ObjectReference npc int i = 0 If kActorArray.Length > 0 While (i < kActorArray.Length) npc = kActorArray[i] npc.AddItem(AMagazine_Ammo_38Caliber_Small) i = i + 1 EndWhile EndIf EndFunction However, there is a problem, the AddItem is reseting the NPC equiped items, so all my provisioners and guards now are wearing their default clothes and weapons Is there anything I can do to prevent this? Link to comment Share on other sites More sharing options...
SKKmods Posted January 31, 2021 Share Posted January 31, 2021 "(1) The automatic [ Return all weapons/ammo ... ] functions can occasionally trigger actors to reset to their default ActorBase outfit if you have equipped non standard clothes/armor. This outfit reset is a base game defect triggered by script functions RemoveItem(Weapon), AddItem(Weapon) and comically EquipItem(Armor) when trying to fix the issue by automatically re-equipping armor. Even the official high quality supported lol :D Creation Club content has this problem." My workaround is to have a persistent container in a holding cell, or create a temporary container at the actor, put the items into that container and then TempContainer.RemoveAllItems(ThisActor, abKeepOwnership = false) which avoids triggering the outfit switch. Link to comment Share on other sites More sharing options...
lukandroll Posted January 31, 2021 Author Share Posted January 31, 2021 (edited) "(1) The automatic [ Return all weapons/ammo ... ] functions can occasionally trigger actors to reset to their default ActorBase outfit if you have equipped non standard clothes/armor. This outfit reset is a base game defect triggered by script functions RemoveItem(Weapon), AddItem(Weapon) and comically EquipItem(Armor) when trying to fix the issue by automatically re-equipping armor. Even the official high quality supported lol :D Creation Club content has this problem." My workaround is to have a persistent container in a holding cell, or create a temporary container at the actor, put the items into that container and then TempContainer.RemoveAllItems(ThisActor, abKeepOwnership = false) which avoids triggering the outfit switch. Lol, silly function So you have to loop through the actor items and copy them to a temp container, add the new item to the temp container, but then how do you replace the actor items with the temp container without triggering the reset? Edited January 31, 2021 by lukandroll Link to comment Share on other sites More sharing options...
SKKmods Posted January 31, 2021 Share Posted January 31, 2021 I dont have any other language to offer than what I originally shared: " and then TempContainer.RemoveAllItems(ThisActor, abKeepOwnership = false) which avoids triggering the outfit switch. " Link to comment Share on other sites More sharing options...
lukandroll Posted January 31, 2021 Author Share Posted January 31, 2021 I found a workaround, using EquipItem instead of AddItem would not cause the reset, the problem I had was that I couldn't just applied it to every NPC, because it would make Provisioners and Guards to equip another ammo and use it, and that messes with their equipped weaponsSo I found a Function BrendonLeCount made in this topic: https://forums.nexusmods.com/index.php?/topic/5892563-check-settlers-role-via-script/That identifies each npc as Farmers, Guards, or ProvisionersAnd with that I restricted the script to work only on settlers that aren't Provisioners or GuardsI know, its super specific Here's how the function ended up, in case anyone need it: Scriptname LucasScript extends Quest Keyword Property ActorTypeNPC Auto Ammo Property AMagazine_Ammo_38Caliber_Small Auto Function GiveAmmoMag38() ObjectReference PlayerREF = Game.GetPlayer() as ObjectReference ObjectReference[] kActorArray = PlayerREF.FindAllReferencesWithKeyword(ActorTypeNPC, 900000.0) ObjectReference npc int i = 0 If kActorArray.Length > 0 While (i < kActorArray.Length) npc = kActorArray[i] as Actor Actor npc2 npc2 = npc as Actor If (npc2 Is WorkshopNPCScript) If (GetJobIndex(npc2 as WorkshopNPCScript) != 3 && GetJobIndex(npc2 as WorkshopNPCScript) != 1) npc2.EquipItem(AMagazine_Ammo_38Caliber_Small, False, True) EndIf EndIf i = i + 1 EndWhile EndIf EndFunction WorkshopParentScript Property WorkshopParent Auto RefCollectionAlias Property CaravanActors Auto int Function GetJobIndex(WorkshopNPCScript akNPC) ; 0 - unassigned ; 1 - guard ; 2 - scavenger ; 3 - provisioner ; 4 - farmer ; 5 - merchant (and phoropter tech? soda jerk? power cyclist?) If akNPC.bIsWorker If akNPC.bIsGuard return 1 ; 1 - Guard ElseIf akNPC.bIsScavenger return 2 ; 2 - Scavenger Else If akNPC.assignedMultiResource == WorkshopParent.WorkshopRatings[WorkshopParent.WorkshopRatingFood].resourceValue return 4 ; 4 - farmer Else return 5 ; 5 - merchant or other EndIf EndIf Else If CaravanActors.Find(akNPC) >= 0 return 3 ; 3 - provisioner Else return 0 ; 0 - unassigned EndIf EndIf EndFunction Link to comment Share on other sites More sharing options...
PJMail Posted February 6, 2021 Share Posted February 6, 2021 (edited) SKK - do you have a trick for replacing "RemoveItem(weapon)" that won't trigger the Outfit reset bug?And will TempContainer.Removeitem(Weapon,1,true,Thisactor) bypass the AddItem bug for Thisactor too? Edited February 6, 2021 by PJMail Link to comment Share on other sites More sharing options...
Recommended Posts