Companion's inventory script help.

Post » Fri Feb 18, 2011 6:08 pm

I need the help of any expert scriptwriter out there.
I'm trying to make a mod for Nehrim that would add a companion to the game.
It works just fine, however, I am now trying to write a script that would allow me to access the inventory of the companion.
I first tried making it all one block, but I wasn't sure if it would continue even in the container menu or if it would pause after the "activate" step and wait until I exited the menu.
THE PROBLEM: The game crashes when I try to remove something from the companion's inventory container. :banghead:
I made it so you could choose the gender of the companion.
I have already had the script set the gender variable, so if you're wondering what that means:
CompanionGender 1 = male
CompanionGender 2 = female
Also, what could I add to make the container appear right behind the player?
You're the best. =)


Begin GameMode
If companioninventoryopen == 1 ;dialog sets this variable
If CompanionGender == 1
CompanionInventory.MoveTo Player 0 0 0
CompanionInventory.RemoveAllItems
CompanionMREF.DuplicateAllItems CompanionInventory ;companioninventory is the reference id for the container
CompanionInventory.Activate Player
set companioninventorymenu to 1
endif
If CompanionGender == 2
CompanionInventory.MoveTo Player 0 0 0
CompanionInventory.RemoveAllItems
CompanionFREF.DuplicateAllItems CompanionInventory
CompanionInventory.Activate Player
set companioninventorymenu to 1
endif
endif
end

begin gamemode
if companioninventorymenu == 1
If CompanionGender == 1
CompanionMREF.Removeallitems
CompanionInventory.DuplicateAllItems CompanionMREF
CompanionMREF.AddScriptPackage CompanionAIEquip ;I saw this used in someone else's script. Was hoping it'd cause the companion to equip any new clothes or armor. I selected Skip fallout, no idle anim, weap.armor unequip
CompanionInventory.moveto COMPINVTO
Set CompanionInventoryOpen to 0
Set CompanionInventoryMenu to 0
endif
If CompanionGender == 2
CompanionFREF.Removeallitems
CompanionInventory.DuplicateAllItems CompanionFREF
CompanionFREF.AddScriptPackage CompanionAIEquip
CompanionInventory.moveto COMPINVTO ;COMPINVTO is a marker I have created in a dummy cell
Set CompanionInventoryOpen to 0
Set CompanionInventoryMenu to 0
endif
endif
end
User avatar
Damned_Queen
 
Posts: 3425
Joined: Fri Apr 20, 2007 5:18 pm

Post » Fri Feb 18, 2011 8:01 pm

Okay, so I've been playing with it a bit and I got it to stop crashing.
The problem now is after I close out of the companioninventory container I don't know how to get him to equip what I have given him.
I tried playing around with that AI thing I saw on another mod which worked for that one, but still, after I close out he is standing there in his undies with his fists up.

Begin GameMode
If companioninventoryopen == 1 && CompanionGender == 1
Set CompanionInventoryOpen to 0
CompanionInventory.MoveTo Player 0 0 0
companionmref.removeallitems companioninventory
CompanionInventory.Activate Player
CompanionInventory.removeallitems companionmref
CompanionInventory.positioncell 0, 0, 0, 0, zzzzCompanionDummyCell
set unequip to 1
companionmref.setalert 1
set unequip to 0
companionmref.setalert 0
endif
If companioninventoryopen == 1 && CompanionGender == 2
Set CompanionInventoryOpen to 0
CompanionInventory.MoveTo Player 0 0 0
companionfref.removeallitems companioninventory
CompanionInventory.Activate Player
CompanionInventory.removeallitems companionfref
CompanionInventory.positioncell 0, 0, 0, 0, zzzzCompanionDummyCell
set unequip to 1
companionfref.setalert 1
set unequip to 0
companionmref.setalert 0
endif
end
User avatar
mimi_lys
 
Posts: 3514
Joined: Mon Apr 09, 2007 11:17 am

Post » Fri Feb 18, 2011 11:09 pm

:wacko:
User avatar
jennie xhx
 
Posts: 3429
Joined: Wed Jun 21, 2006 10:28 am

Post » Fri Feb 18, 2011 10:52 pm

It is easier for others to read your scripts if you use proper indentation, and folks are more inclined to help you if your scripts are easy to read!

Begin GameMode	If companioninventoryopen == 1 && CompanionGender == 1		Set CompanionInventoryOpen to 0		CompanionInventory.MoveTo Player 0 0 0		companionmref.removeallitems companioninventory		CompanionInventory.Activate Player		CompanionInventory.removeallitems companionmref		CompanionInventory.positioncell 0, 0, 0, 0, zzzzCompanionDummyCell		set unequip to 1		companionmref.setalert 1		set unequip to 0		companionmref.setalert 0	endif	If companioninventoryopen == 1 && CompanionGender == 2		Set CompanionInventoryOpen to 0		CompanionInventory.MoveTo Player 0 0 0		companionfref.removeallitems companioninventory		CompanionInventory.Activate Player		CompanionInventory.removeallitems companionfref		CompanionInventory.positioncell 0, 0, 0, 0, zzzzCompanionDummyCell		set unequip to 1		companionfref.setalert 1		set unequip to 0		companionmref.setalert 0	endifend 


That said, an NPC won't generally equip new things unless he is specifically told to equip a specific item, or if you use OBSE functions to tell him to equip anything in his inventory based on various conditions, or if the NPC has cause to evaluate his current AI package. In your case, adding the line "companionref.EVP" will force him to evaluate his AI package, and thus choose items to equip. He will, by default, choose the most expensive items and/or the items with the highest armor rating; unless his current AI package has the "Armor Unequipped" flag, in which case items with armor rating will be ignored.
User avatar
Kerri Lee
 
Posts: 3404
Joined: Sun Feb 25, 2007 9:37 pm


Return to IV - Oblivion