edited October 2014 in ORK Scripting
I didn't want to create a prefab for every weapon type my skeleton could equip. So, I threw together this script which grabs a weapon from his STARTING INVENTORY list and equips it. If you have an equipment viewer setup and a prefab for the weapon, it will display as well. I thought I would share it with the ORK community.
EDIT: Forgot to mention, just attach the script to the prefab of the monster/NPC.


sing UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ORKFramework;
using ORKFramework.Behaviours;

public class EquipWeapon : MonoBehaviour
{
#region fields
Combatant combatant;
#endregion

#region init
// Use this for initialization
void Start ()
{
combatant = ComponentHelper.GetCombatant(gameObject);

if(combatant != null)
{
if (combatant.Inventory.HasWeapons())
{
List<IShortcut> wpns = combatant.Inventory.GetContent(combatant,false,false,true,false);
if(wpns.Count > 0)
{
IShortcut wpn = null;
//now choose a random weapon from the list to equip
int roll = DiceBag.Custom(0,wpns.Count-1);

if (wpns.Count == 1)
{
wpn = wpns[0]; //wpns.RandomObject();
}
else
{
wpn = wpns[roll]; //wpns.RandomObject();
}

if(wpn != null)
{
//create the shortcut and equip the item
EquipShortcut es = new EquipShortcut(EquipSet.Weapon,wpn.ID,1,1);
combatant.Equipment.Equip (2,es,null,false); //2 is my primary weapon slot which has an equipmentviewer attached. This is where the weapon will be displayed.
combatant.MarkResetStatus();
}
}
}

//we could add shields and helms here
}
}
#endregion
}

Post edited by keyboardcowboy on
Sign In or Register to comment.