edited March 2015 in ORK Scripting
Hi, I am pretty new to scripting with unity in general, but have been using ORK for some time now. However I am trying to learn scripting as well as do things with the ORK API and such.

Currently I am trying to make a simple script that changes the weapon displayed on my combatant based on what is equipped in his inventory. I know their may be several non-scripting ways to accomplish this, but I am trying to use this a learning experience.

Currently I have the weapon object childed to my combatants prefab.

I would like it to be so when I equip my weapon in the inventory the script will then enable the object making it visible on my combatant and if I change any weapon it will disable and enable those components based on what I have equipped.

Again I am very new to the javascript syntax with unity so I am even more so clueless on how to script with ORK exactly. I was mostly just hoping for some structure help and how I should go about setting it up.

Anything is appreciated, thanks in advance! :)

  • There's actually the Equipment Viewer component included in ORK doing exactly that :)
    The code is included in the full version if you want to check it out.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Hi, thanks for taking the time to respond, much appreciated.

    Yes im pretty aware of the equipment viewer, but I actually wasn't to crazy about the process I had to go through to set my equip to the right position.

    Also(and maybe you can help with this too). I am making the weapon be displayed in and outside of combat(outside on his back, inside in his hands). So I am not sure how to get it to display and move to different positions with the viewer. im certain with this I am just not doing something that I dont know though so any comments on that is appreciated too.

    But anyway, I was really hoping to try and script this to learn how to use some thing with the API mostly, I know there is other ways, but I just thought this could be easy and fun. Not trying to negate the advice you gave me though I really do appreciate it!
  • For that you would use two separate viewers each displaying the same weapon part, positioned one the hand and back separately. Change the settings in the inspector so that the back item is displayed when not in battle, and the hand one for when battling = true.

    My little chunk of the internet: http://artemic.com
  • Hey thanks man,

    Ok, I guess you guys are basically telling me, im trying to do things the hard way haha. Guess I will just do this after all then. Thanks for the help. Can anyone leave any scripting advice with ork though? I checked the tutorials and all, but still left feeling a bit confused when i was going through the API.
  • There are some scripting how-tos available at the bottom of this page.

    E.g. the where is what how-to can be useful for starters :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Last question regarding the Equipment viewer. How do you have multiple position viewers for one object? If I change it for lets say a weapon, it seem to effect how it is positioned in both hands and on his back.
  • The offset settings in the equipment will be added to all viewers that display it. We'll probably need new settings for that :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Sorry I now have a few more questions. as I have decided to create a script after all.

    I was wondering what would need to do to make the script Check if the player has a certain weapon equipped and then if it does will enable the mesh render of an object(i have the later down, just need to know how to do the first part with the ORK functions.)
  • First, access the combatant of the game object. After that you can access the equipment like this:

    combatant.Equipment[int index]

    index is the ID of the equipment part (i.e. it's index in the list in the editor).
    This gives access to the equipment part with additional functionality to access the weapon that's equipped there.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • ok I think im almost on the right track, just still need a little coaching. I really do appreciate your help.

    Here is my code so far. You can ignore the bottom bit for now. Im sorta doing it backwards to test to make sure changes are made when the combatant does have the weapon equipped.(but if you can understand whats going on then please dont hesitate to help on that too)

    #pragma strict

    using ORKFramework ;
    using ORKFramework.Behaviours ;

    CombatantComponent combatantComponent = dpt_sword_boy_PF;
    GetComponent<CombatantComponent>() ;
    if(combatantComponent != null)
    {
    Combatant combatant = combatantComponent.combatant;
    }

    function Update ()
    { if (combatant.Equipment[int 4])
    {
    GetComponent(MeshRenderer).enabled = false;
    ]

    }
  • First, please wrap this up in a proper component class (extending MonoBehaviour), looks horrible like this :D

    Put finding the combatant in the Start function of the component (void Start()) and make the combatant a field of the class to have it accessible in the update function.

    Checking if something is equipped on the part is done like this:

    if(combatant.Equipment[4].Equipped && combatant.Equipment[4].Equipment != null)

    To check what's actually equipped on there, you'll access the Equipment property of the equipment part (what's used as a 2nd check in the if statement).
    This is the EquipmentShortcut class that holds the data of the equipped weapon/armor - you can check the ID and type (weapon/armor) of it.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Ok again scripting noob here, but I did some research and not sure i understand the void start bit or even really the class extending mono behavior stuff...but I set things up like this(still got a whole bunch of errors still ofcourse):

    Is any of this what you met? (thanks for having a lot of patience with me)

    #pragma strict

    using ORKFramework ;
    using ORKFramework.Behaviours ;



    public class weapon viewer : MonoBehaviour

    function Start()
    {
    (void Start(

    CombatantComponent combatantComponent = dpt_sword_boy_PF;
    GetComponent<CombatantComponent>() ;

    if(combatantComponent != null)
    {
    Combatant combatant = combatantComponent.combatant;
    }
    )
    )

    function Update ()
    {
    if (combatant.Equipment[int 4].Equipped && combatant.Equipment[4].equipment != null)
    {
    GetComponent(MeshRenderer).enabled = false;
    }

    }
  • edited March 2015
    You probably should first start learning scripting with Unity before trying to do stuff with ORK :)

    If this is C# (what it looks like to be), you wont be using stuff like function Start() or function Update(), but void Start() and void Update() instead.
    The MonoBehaviour class you're extending from will make this script a component that can be attached to game objects - the Start function will be called when the object is added to the scene, the Update function every frame.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Yes Actually I did more research and now a few more things make some sense. Ok I really thing I am getting the hang of this now. I only have 2 errors of the "name combatant" doesn not exist.

    How is this looking? And your right I was doing javascript, but now I switched to C#:

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

    public class weaponviewer : MonoBehaviour {
    public GameObject Obj;

    // Use this for initialization
    void Start () {


    CombatantComponent combatantComponent = gameObject.
    GetComponent<CombatantComponent> ();

    if (combatantComponent != null) {
    Combatant combatant = combatantComponent.combatant;
    }

    }

    // Update is called once per frame
    void Update () {

    MeshRenderer w = Obj.GetComponent<MeshRenderer>();

    if (combatant.Equipment[4].Equipped && combatant.Equipment[4].equipment != null)



    {
    w.enabled = false;
    }

    }

    }


  • Well, you try to access combatant in the Update function - like I told you before, you need to make the combatant a field (like you did with the game object) and assign it in the start function.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.