1. I've made a few items lately for the workshop that is themed on running a command when the player is close to the item.

    [​IMG]

    With some help from people with more skills in code than myself we got a prototype working pretty good by running a raycasting on player input, if the player was on an item with a specific name we'd run an instanciate() or whatever.
    This however, I believe will be quite hard on the server with 60 people online.

    In pure cow-trix style he gave away a little nugget of information a week or so ago when we were lucky enough to have him communicate with us for half an hour. But the guys I was hoping to collaborate with, doesn't seem to be able or keen to do this after all. And with a few concepts and models already made and an vacation creeping up in just over a weeks time.. I am really hoping someone here might pick it up, so we can get some cool items out on the workshop before christmas. I believe that a collider-sniffer-event-trigger like this is the single most important piece of code that needs to be written for HurtworldOxide - if we're going to see any interesting objects in the workshop.

    Below is the transcript where it was given some hints at a better solution than raycasting on input. But I'm not even sure cowtrix is right or understood the concept.. As these items will need to be placed dynamically, getting things like trapPosition might be a real challenge.



    Who's up for the challenge?!
     
  2. Here's the full proof-of-concept script that works rather well, except for that it probably will be causing quite a bit of server stress on a full server:
    Code:
    // Reference: UnityEngine.UIusing System;
    using System.Reflection;
    using Assets.Scripts.Core;
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using uLink;namespace Oxide.Plugins
    {
      [Info("Trap", "WolfPack", 0.1)]
      [Description("Raycasts for TrapFoundations and spawns TrapItems on Hit")]  class Trap : HurtworldPlugin
      {
      private Hash<GameObject,bool> traps = new Hash<GameObject,bool>();
      private void Loaded()
      {
      Puts("Plugin loaded");
      }
      void OnPlayerInput(PlayerSession session, InputControls input)
      {
      if (input.Forward
      || input.Backward
      || input.StrafeLeft
      || input.StrafeRight
      || input.Sprint
      || input.Crouch)
      {
      // Puts("Player imput works");
      StartTrap(session);
      }
      }  void StartTrap(PlayerSession session)
      {
      // Puts("Calling Void works");
      // var all = Resources.FindObjectsOfTypeAll<TrapFoundation>();
      string steamId = session.SteamId.ToString();
      Vector3 randposition = session.WorldPlayerEntity.transform.position;  if (!string.IsNullOrEmpty(steamId))
      {
      // Puts("Finding steamid works");  RaycastHit hitInfo;
      var rayLength = 1;  if (Physics.Raycast(randposition, Vector3.down, out hitInfo, rayLength))
      {
      if(!traps.ContainsKey(hitInfo.collider.gameObject)){
      traps.Add(hitInfo.collider.gameObject,false);
      }// SPEARTRAP
      //Check Raycast
      if (hitInfo.collider.gameObject.name.Contains("ConcreteSpear1TrapFoundation"))
      {
      // timer.Once(0f, () =>
      Puts("Spiketrap");
      hurt.SendChatMessage(session, "SPIKETRAP!!");
      //  if(traps[hitInfo.collider.gameObject]){
      //  traps[hitInfo.collider.gameObject] = true;
      //Spawn Items Below SpikesIronDynamicServer
      var obj= Singleton<HNetworkManager>.Instance.NetInstantiate(uLink.NetworkPlayer.server,
      "spear1DynamicServer", session.WorldPlayerEntity.transform.position,
      Quaternion.Euler(0.0f, (float) UnityEngine.Random.Range(0f, 360f), 0),
      GameManager.GetSceneTime());  //  audio.PlayOneShot(landcrabArmedSound, 0.7F),
      timer.Once(5f, ()=>{HNetworkManager.Instance.NetDestroy(obj.uLinkNetworkView());traps[hitInfo.collider.gameObject] = false;Puts("Destroyed!");});
      }
    // }// FIRETRAP
      //Check Raycast
      if (hitInfo.collider.gameObject.name.Contains("ConcreteFireTrapFoundation"))
      {
      //console and notifier
      Puts("Firetrap");
      hurt.SendChatMessage(session, "FIRETRAP!!");  //Spawn Items Below
      var obj= Singleton<HNetworkManager>.Instance.NetInstantiate(uLink.NetworkPlayer.server,
      "FireDynamicServer", session.WorldPlayerEntity.transform.position,
      Quaternion.Euler(270, 0, 0),
      GameManager.GetSceneTime());
      //destroy items
      timer.Once(10f, ()=>{HNetworkManager.Instance.NetDestroy(obj.uLinkNetworkView());Puts("Destroyed!");});  }//ACID
      //Check Raycast
      if (hitInfo.collider.gameObject.name.Contains("ConcretePoisonTrapFoundation"))
      {
      //console and notifier
      Puts("Poisontrap");
      hurt.SendChatMessage(session, "BAD ACID!!");  //Spawn Items Below
      var obj= Singleton<HNetworkManager>.Instance.NetInstantiate(uLink.NetworkPlayer.server,
      "TrapPoison", session.WorldPlayerEntity.transform.position,
      Quaternion.Euler(0.0f, (float) UnityEngine.Random.Range(0f, 360f), 0),
      GameManager.GetSceneTime());  //destroy items
      timer.Once(15f, ()=>{HNetworkManager.Instance.NetDestroy(obj.uLinkNetworkView());Puts("Destroyed!");});  }//SPEAR 2  //Check Raycast
      if (hitInfo.collider.gameObject.name.Contains("ConcreteSpear2TrapFoundation"))
      {
      //console and notifier
      Puts("SpikeTrap2");
      hurt.SendChatMessage(session, "SpikeTrap 2");  //Spawn Items Below
      var obj= Singleton<HNetworkManager>.Instance.NetInstantiate(uLink.NetworkPlayer.server,
      "spear2DynamicServer", session.WorldPlayerEntity.transform.position,
      Quaternion.Euler(0.0f, (float) UnityEngine.Random.Range(0f, 360f), 0),
      GameManager.GetSceneTime());  //destroy items
      timer.Once(5f, ()=>{HNetworkManager.Instance.NetDestroy(obj.uLinkNetworkView());Puts("Destroyed!");});  }//SPEAR 3  //Check Raycast
      if (hitInfo.collider.gameObject.name.Contains("ConcreteSpear3TrapFoundation"))
      {
      //console and notifier
      Puts("SpikeTrap3");
      hurt.SendChatMessage(session, "SpikeTrap 3");  //Spawn Items Below (alternative SpikesIronDynamicServer)
      var obj= Singleton<HNetworkManager>.Instance.NetInstantiate(uLink.NetworkPlayer.server,
      "spear3DynamicServer", session.WorldPlayerEntity.transform.position,
      Quaternion.Euler(0.0f, (float) UnityEngine.Random.Range(0f, 360f), 0),
      GameManager.GetSceneTime());  //destroy items
      timer.Once(5f, ()=>{HNetworkManager.Instance.NetDestroy(obj.uLinkNetworkView());Puts("Destroyed!");});}
    //DEBUG
    /*
      if (!hitInfo.collider.gameObject.name.Contains("batman"))  {
      Puts("Whatever!");  hurt.SendChatMessage(session, "name:");
      hurt.SendChatMessage(session, hitInfo.collider.gameObject.name);
      // hurt.SendChatMessage(session, "tag:");
      // hurt.SendChatMessage(session, hitInfo.collider.gameObject.tag);
      }
      */  }
      }
      }
      }
    }
    /*Goodies from CowTrix:StructureManager.GetAttachment(HitInfo raycastHit)
    //var enumerator = OwnershipStakeServer.GetEnumerator();
    while(enumerator.MoveNext())
    {
    var currentStake = enumerator.Current;
    // Do whatever
    }// play sound
    if (EmissionSounds != null && EmissionSounds.Length != 0)
    {
      i_love_codeoSource audio = meteor.GetComponent<i_love_codeoSource>();
      if (audio != null)
      {
      int index = UnityEngine.Random.Range(0, EmissionSounds.Length);
      i_love_codeoClip clip = EmissionSounds[index];
      audio.PlayOneShot(clip, scale);
      }
    }
    */
     
  3. Looks nice!
     
  4. Thanks, but as a decorative item this is still kind of boring and pointless. Either using rubies/amber/etc or an oxide base ingame-currency to buy bullets or weapon attachments for the deathmatch update that is around the corner is a lot more interesting in my opinion.

    The logic would be (I think) to attach a larger trigger collider set to a certain layer (cowtrix suggested layer 17) to the prefab - and some way of checking if/when a player collides with this trigger - Then run some function for shopping.
    At some point with itemsv2 a more "machine" like approach might be possible, basically turning it into a workbench with custom recipes. But for now, and for a lot of other interactive usable objects a collider-sniffer-event-trigger is what we'll need!..

    // EDIT
    This bit from a Rust thread seems to be in the right neighborhood
     
    Last edited by a moderator: Dec 15, 2016
  5. Code:
    static function OverlapSphere (position : Vector3, radius : float, layerMask : int = kAllLayers) : Collider[]
    Returns an array with all colliders touching or inside the sphere.


    NOTE: Currently this only checks against the bounding volumes of the colliders not against the actual colliders.
     
    Last edited by a moderator: Dec 29, 2016
  6. I want to customize build a monster to mod.
    but about of the monster how check Get Hit?
    Do you have any good ideas? about this.