JellyFishInLoop Posted March 16 Share Posted March 16 (edited) SOLVED Now I need to figure out how to allow me to change weapons to anything other than a bow... (or remove arrows with a keyword when equipping something other than a bow) Because the current script will instantly equip my invisible bow again SOLVED I'm making a mod with throwing knives. I'm using an empty bow mesh. arrows with knives model and a new throwing (shooting) animations. I was somehow able to find a script that allows me to add and equip an invisible bow to my inventory when equipping my arrows (throwing knives) and remove it when removing the arrow-knives. Actually, my question is, is it possible to somehow unify the script for all throwing knives from the mod, so as not to make separate scripts for each type of throwing knife? Maybe using keywords or something.... my shameful script Spoiler Scriptname tttEquip extends ReferenceAlias Weapon Property tttWeapon Auto Ammo Property tttIronKnive Auto Actor Property PlayerRef Auto Int Property arrowNum Auto Int count Int add Event OnInit() RegisterForSingleUpdate(0.25) EndEvent Event OnUpdate() If (PlayerRef.IsEquipped(tttIronKnive)) If !(PlayerRef.IsEquipped(tttWeapon)) PlayerRef.AddItem(tttWeapon,1,true) PlayerRef.EquipItem(tttWeapon,true,true) Else add = PlayerRef.GetItemCount(tttWeapon) While (add < 1) PlayerRef.AddItem(tttWeapon,1,true) add += 1 EndWhile EndIf Else If (PlayerRef.IsEquipped(tttWeapon)) PlayerRef.UnequipItem(tttWeapon,true,true) count = PlayerRef.GetItemCount(tttWeapon) PlayerRef.RemoveItem(tttWeapon,count,true,None) EndIf EndIf RegisterForSingleUpdate(0.25) EndEvent Edited March 16 by JellyFishInLoop Link to comment Share on other sites More sharing options...
xkkmEl Posted March 16 Share Posted March 16 Since you are creating your own base weapon forms, you can place part of your code on an ObjectReference script attached to the weapon. These scripts can know what kind of ammo to equip/unequip. I am however not seeing the counterpart, attaching a script to the ammo that can know what kind of weapon to equip/unequip. My guess is that you'll need to test it in an elseif cascade. Link to comment Share on other sites More sharing options...
JellyFishInLoop Posted March 16 Author Share Posted March 16 (edited) 18 minutes ago, xkkmEl said: Since you are creating your own base weapon forms, you can place part of your code on an ObjectReference script attached to the weapon. These scripts can know what kind of ammo to equip/unequip. I am however not seeing the counterpart, attaching a script to the ammo that can know what kind of weapon to equip/unequip. My guess is that you'll need to test it in an elseif cascade. Unfortunately, in my case, I need to bind the script specifically to the ammo, and this seems to be impossible to do in the creation kit. But I sort of figured it out and I needed to use WornHasKeyword Edited March 16 by JellyFishInLoop Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 16 Share Posted March 16 You might want to try this out instead: Scriptname tttEquip extends ReferenceAlias Weapon Property tttWeapon Auto Ammo Property tttIronKnive Auto Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() If (akBaseObject as Ammo) && ( (akBaseObject as Ammo) == tttIronKnive) PlayerRef.EquipItem(tttWeapon) ElseIf (akBaseObject as Weapon) && ( (akBaseObject as Weapon != tttWeapon) ) PlayerRef.UnequipItem(tttIronKnive) EndIf EndEvent Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() If (akBaseObject as Ammo) && ( (akBaseObject as Ammo) == tttIronKnive) PlayerRef.UnequipItem(tttWeapon) EndIf EndEvent This should be attached to the player alias. When the player equips the throwing knives, the invisible bow is equipped. When the player equips any other weapon, the throwing knives are unequipped. When the player unequips the throwing knives, the invisible bow is unequipped. Link to comment Share on other sites More sharing options...
JellyFishInLoop Posted March 16 Author Share Posted March 16 (edited) 34 minutes ago, IsharaMeradin said: You might want to try this out instead: Hide contents Scriptname tttEquip extends ReferenceAlias Weapon Property tttWeapon Auto Ammo Property tttIronKnive Auto Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() If (akBaseObject as Ammo) && ( (akBaseObject as Ammo) == tttIronKnive) PlayerRef.EquipItem(tttWeapon) ElseIf (akBaseObject as Weapon) && ( (akBaseObject as Weapon != tttWeapon) ) PlayerRef.UnequipItem(tttIronKnive) EndIf EndEvent Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() If (akBaseObject as Ammo) && ( (akBaseObject as Ammo) == tttIronKnive) PlayerRef.UnequipItem(tttWeapon) EndIf EndEvent This should be attached to the player alias. When the player equips the throwing knives, the invisible bow is equipped. When the player equips any other weapon, the throwing knives are unequipped. When the player unequips the throwing knives, the invisible bow is unequipped. can i somehow use a my keyword for these kniv(f)es, so as not to register each type separately (for each material)? Edited March 16 by JellyFishInLoop Link to comment Share on other sites More sharing options...
xkkmEl Posted March 16 Share Posted March 16 In Ishara's cascading elseif example, you can just replace the conditions by whatever suits your needs. She is testing the base object for equality with a specific base form "tttIronKnives" , but you can just as well test HasKeyword like so: If (akBaseObject as Ammo) && (akBaseObject as Ammo).hasKeyword( myKnifeKeyword) ... elseif (akBaseObject as Ammo) && (akBaseObject as Ammo).hasKeyword( myShurikenKeyword) ... Just create the keywords, add them to the Ammo forms, and populate your properties to access them. Use as many keywords as you need to identify your different cases. Link to comment Share on other sites More sharing options...
JellyFishInLoop Posted March 16 Author Share Posted March 16 17 minutes ago, xkkmEl said: In Ishara's cascading elseif example, you can just replace the conditions by whatever suits your needs. She is testing the base object for equality with a specific base form "tttIronKnives" , but you can just as well test HasKeyword like so: If (akBaseObject as Ammo) && (akBaseObject as Ammo).hasKeyword( myKnifeKeyword) ... elseif (akBaseObject as Ammo) && (akBaseObject as Ammo).hasKeyword( myShurikenKeyword) ... Just create the keywords, add them to the Ammo forms, and populate your properties to access them. Use as many keywords as you need to identify your different cases. Thanks! I more or less understood how it works. Link to comment Share on other sites More sharing options...
JellyFishInLoop Posted March 17 Author Share Posted March 17 (edited) 1 hour ago, xkkmEl said: In Ishara's cascading elseif example, you can just replace the conditions by whatever suits your needs. She is testing the base object for equality with a specific base form "tttIronKnives" , but you can just as well test HasKeyword like so: If (akBaseObject as Ammo) && (akBaseObject as Ammo).hasKeyword( myKnifeKeyword) ... elseif (akBaseObject as Ammo) && (akBaseObject as Ammo).hasKeyword( myShurikenKeyword) ... Just create the keywords, add them to the Ammo forms, and populate your properties to access them. Use as many keywords as you need to identify your different cases. hmm, can I ask a one more question.... Can I equip/unequip items by certain keywords Edited March 17 by JellyFishInLoop Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 17 Share Posted March 17 Alright here is an untested modification. Basically, it uses two index matching arrays as properties. The ammo array is searched when ammo is equipped and the index matching weapon is equipped while the ammo is locally stored. When any other weapon is equipped the weapon array is checked and if the weapon is not in the array the locally stored ammo is unequipped. If the ammo is unequipped, the ammo array will be searched and the index matching weapon unequipped. Spoiler Scriptname tttEquip extends ReferenceAlias Weapon[] Property tttWeapons Auto Ammo[] Property tttKnives Auto Ammo CurrentAmmo Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() Int myAL = tttWeapons.Length If (akBaseObject as Ammo) Int idx = tttKnives.Find(akBaseObject as Ammo) If idx >= 0 ; ammo found in array CurrentAmmo = tttKnives[idx] PlayerRef.EquipItem(tttWeapons[idx]) EndIf ElseIf (akBaseObject as Weapon) Int Entry = tttWeapons.Find(akBaseObject as Weapon) If Entry < 0 ; weapon not found in array If CurrentAmmo != None ; sanity check PlayerRef.UnequipItem(CurrentAmmo) EndIf EndIf EndIf EndEvent Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() Int myAL = tttWeapons.Length If (akBaseObject as Ammo) Int Entry = tttKnives.Find(akBaseObject as Ammo) If Entry >= 0 ; ammo found in array PlayerRef.UnequipItem(tttWeapons[Entry]) EndIf EndIf EndEvent Link to comment Share on other sites More sharing options...
JellyFishInLoop Posted March 17 Author Share Posted March 17 6 hours ago, IsharaMeradin said: Alright here is an untested modification. Basically, it uses two index matching arrays as properties. The ammo array is searched when ammo is equipped and the index matching weapon is equipped while the ammo is locally stored. When any other weapon is equipped the weapon array is checked and if the weapon is not in the array the locally stored ammo is unequipped. If the ammo is unequipped, the ammo array will be searched and the index matching weapon unequipped. Hide contents Scriptname tttEquip extends ReferenceAlias Weapon[] Property tttWeapons Auto Ammo[] Property tttKnives Auto Ammo CurrentAmmo Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() Int myAL = tttWeapons.Length If (akBaseObject as Ammo) Int idx = tttKnives.Find(akBaseObject as Ammo) If idx >= 0 ; ammo found in array CurrentAmmo = tttKnives[idx] PlayerRef.EquipItem(tttWeapons[idx]) EndIf ElseIf (akBaseObject as Weapon) Int Entry = tttWeapons.Find(akBaseObject as Weapon) If Entry < 0 ; weapon not found in array If CurrentAmmo != None ; sanity check PlayerRef.UnequipItem(CurrentAmmo) EndIf EndIf EndIf EndEvent Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) Actor PlayerRef = Game.GetPlayer() Int myAL = tttWeapons.Length If (akBaseObject as Ammo) Int Entry = tttKnives.Find(akBaseObject as Ammo) If Entry >= 0 ; ammo found in array PlayerRef.UnequipItem(tttWeapons[Entry]) EndIf EndIf EndEvent I don't quite understand how it works, but I'll try to learn Arrays stuff..... As i understand this is what I need for manipulating with groups of items Thank you very much for such detailed examples (for ready-made scripts lol) Link to comment Share on other sites More sharing options...
Recommended Posts