vizex1 Posted August 17, 2019 Share Posted August 17, 2019 (edited) So I'm reading this tutorial: https://www.creationkit.com/fallout4/index.php?title=Inter-mod_Communication But I'm new to scripting and I'm having trouble understanding this part: ScriptObject bfVendor = aCharacter.CastAs("BeginningFantasyVendor") Which is a part of this script: Function SetBFVendorStoreHours(Actor aVendor, float aOpenTime, float aCloseTime) ; We can't use the normal "as" operator, because that would add a dependency on the other mod. ; So instead we use the CastAs function to make sure we're pointing at the right script. ScriptObject bfVendor = aCharacter.CastAs("BeginningFantasyVendor") ; Now set the properties, again, we don't need to cast because our parameter values are ; already the right types bfVendor.SetPropertyValue("StoreOpenTime", aOpenTime) bfVendor.SetPropertyValue("StoreCloseTime", aCloseTime) endFunction My question is where did he get bfVendor and aCharacter from? How would I know what to write in place of that in my own script? Edited August 17, 2019 by vizex1 Link to comment Share on other sites More sharing options...
vizex1 Posted August 17, 2019 Author Share Posted August 17, 2019 (edited) Okay, I think I figured it out. aCharacter is what the original script is attached to. So in that case, it's the character that has the "BeginningFantasyVendor" script on him. Right? So then bfvendor would be the object or character in my mod that has the script, I think, right? Edited August 17, 2019 by vizex1 Link to comment Share on other sites More sharing options...
Reneer Posted August 17, 2019 Share Posted August 17, 2019 Okay, I think I figured it out. aCharacter is what the original script is attached to. So in that case, it's the character that has the "BeginningFantasyVendor" script on him. Right? So then bfvendor would be the object or character in my mod that has the script, I think, right?What that code is doing is getting a reference to the BeginningFantasyVendor script that exists on the aCharacter reference, but specifically without making your script dependent upon the BeginningFantasyVendor script itself. So your bfvendor reference should now point to aCharacter's BeginningFantasyVendor script and you can, for example, call functions contained within the BeginningFantasyVendor script using bfvendor.CallFunction(). Link to comment Share on other sites More sharing options...
vizex1 Posted August 17, 2019 Author Share Posted August 17, 2019 What that code is doing is getting a reference to the BeginningFantasyVendor script that exists on the aCharacter reference, but specifically without making your script dependent upon the BeginningFantasyVendor script itself. So your bfvendor reference should now point to aCharacter's BeginningFantasyVendor script and you can, for example, call functions contained within the BeginningFantasyVendor script using bfvendor.CallFunction(). Sorry I'm still new to scripting, so do I have to set up aCharacter as a property? Or is that the part where I use GetFormFromFile function and that is what references aCharacter? Link to comment Share on other sites More sharing options...
Reneer Posted August 17, 2019 Share Posted August 17, 2019 What are you trying to do overall with your mod? Why do you need inter-mod communication in the first place? Link to comment Share on other sites More sharing options...
vizex1 Posted August 17, 2019 Author Share Posted August 17, 2019 (edited) What are you trying to do overall with your mod? Why do you need inter-mod communication in the first place?I'm trying to get my script to reference a reference in another mods script.The mod is Visible Weapons by registrar2000. Here's some snippets of code in his script. int idx = listOfWeapons.find(currentWeapon, 0) Game.GetPlayer().UnequipItem(listOfItems[idx], False, True) I want to attach an omod to the specific armor that script is referring to. I think that script is referring to the armor at least. So I'm guessing my script might look something like this. Game.GetPlayer().AttachModToInventoryItem(listOfItems[idx], Mod1) I'm just testing at this point. But I can't really try it to see if it'll work if I don't know how to do inter-mod communication. Edited August 17, 2019 by vizex1 Link to comment Share on other sites More sharing options...
SKKmods Posted August 17, 2019 Share Posted August 17, 2019 You will not be able to reference idx remotely as it is a local script variable an not exposed as a property. If ListOfItems is a form list then you can easily get at that remotely and run the find yourself (I am totally guessing at the actual script logic here); If (Game.IsPluginInstalled("MODNAME.esp") == TRUE) FormList ThisList = Game.GetFormFromFile(0x00001234, "MODNAME.esp") as FormList; Weapon ThisWeapon = ThisList.Find(Game.GetPlayer().GetEquippedWeapon()) If (ThisWeapon != None) Game.GetPlayer().UnequipItem(ThisWeapon, abPreventEquip = false, abSilent = true) Game.GetPlayer().AttachModToInventoryItem(ThisWeapon, Mod1) Game.GetPlayer().EquipItem(ThisShooter, abPreventRemoval = true, abSilent = true) EndIf EndifIf ListOfItems is an array that is exposed as a script property then it depends on what the script is attached to on how you would access it, an example if the parent object is a quest; If (Game.IsPluginInstalled("MODNAME.esp") == TRUE) Quest FormFromOtherMod = (Game.GetFormFromFile(0x00001234, "MODNAME.esp") as Quest) ScriptObject RemoteScript = FormFromOtherMod.CastAs("ScriptName") Var ListOfItems = RemoteScript.GetPropertyValue("ListOfItems") ThisList = (ListOfItems as Weapons[]) ; now paste in the .Find block above EndIf If ListOfItems is not exposed then you will need to hack the original mod script and distribute that, probably as a cancerous loose script, if you can get permission from the author. Link to comment Share on other sites More sharing options...
jags78 Posted August 17, 2019 Share Posted August 17, 2019 I agree with SKK50. Been reverse engineering regi's script myself back and forth, looking for a way to inject weapons and armor into those arrays without success. Inheritance doesn't work when trying to change private variables and CastAs neighter, appart that the latter has an additional private variable that locks the procedure of adding data to his arrays when conditions aren't met. I wrote to regi asking if he would add a kind of API function to his mod allowing us to inject weapon<->armor information without the need of manually doing so, but he didn't anwser until now. I was thinking of writing a similar mod as 'Visible Weapons'... What's your overall goal? Maybe we could help eachother. Link to comment Share on other sites More sharing options...
vizex1 Posted August 17, 2019 Author Share Posted August 17, 2019 If ListOfItems is an array that is exposed as a script property then it depends on what the script is attached to on how you would access it, an example if the parent object is a quest; If (Game.IsPluginInstalled("MODNAME.esp") == TRUE) Quest FormFromOtherMod = (Game.GetFormFromFile(0x00001234, "MODNAME.esp") as Quest) ScriptObject RemoteScript = FormFromOtherMod.CastAs("ScriptName") Var ListOfItems = RemoteScript.GetPropertyValue("ListOfItems") ThisList = (ListOfItems as Weapons[]) ; now paste in the .Find block above EndIf If ListOfItems is not exposed then you will need to hack the original mod script and distribute that, probably as a cancerous loose script, if you can get permission from the author.I think this is in the right direction because it's not a formlist, it has no formID. In the original script There's this at the top: ; Variables int currentRegistrationMode = -1 ; ALWAYS -1 when not registering. 0 for registering weapon. 1 for registering gun-on-back. 2 for registering empty holsters. bool firstRun = True ; First run will give player the config. Weapon[] listOfWeapons ; List of weapons that are registered. Form[] listOfItems ; Holds the "gun-on-back" when the weapon is unequipped. Form[] listOfEmptyHolsters ; Holds the "empty" holsters when a weapon is equipped. int[] equipModes ; Holds the equip modes for each weapon. The source is available in his mod download page, so I don't think hacking is necessary.https://www.nexusmods.com/fallout4/mods/10317/?tab=files Here's what I've done so far: bool modInstalled = Game.IsPluginInstalled("VisibleWeapons.esp") if modInstalled Quest Holster = Game.GetFormFromFile(0x01000800, "VisibleWeapons.esp") as Quest ScriptObject RemoteScript = Holster.CastAs("WeaponHolster") Var listofWeapons = RemoteScript.GetPropertyValue("listofWeapons") Var listofItems = RemoteScript.GetPropertyValue("listofItems") Debug.Notification("Inter-Mod Communication.") Debug.Trace("Inter-Mod Communication.") Weapon currentWeapon = Game.GetPlayer().GetEquippedWeapon(0) int idx = listOfWeapons.find(currentWeapon, 0) Game.GetPlayer().AttachModToInventoryItem(listOfItems[idx], Mod1) The last 2 lines don't compile:(lastline1, 24) var is not a known user-defined script type(lastline1, 4) type mismatch while assigning to a int (cast missing or types unrelated)(lastline2, 42) only arrays can be indexed Link to comment Share on other sites More sharing options...
vizex1 Posted August 17, 2019 Author Share Posted August 17, 2019 I was thinking of writing a similar mod as 'Visible Weapons'... What's your overall goal? Maybe we could help eachother.Well, I want to make a mod that has all the vanilla weapons as holsters. I've got that part down and it should be easy. This script stuff is just me trying to figure out a way to get blood to appear on the holstered version of the melee weapons. So I thought I could use script to attach an omod with a material swap whenever the weapon linked to the holstered accessory was used. Link to comment Share on other sites More sharing options...
Recommended Posts