HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Simple Extension to the Dynamically Replicated Objects tutorial.  (Read 1492 times)

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO

http://hewiki.heroengine.com/wiki/Replication_Tutorial

Maybe this isnt needed and I am missing something in regards to information that "instance" holds but:

When creating DRO objects I want to reference back to the DRO item on the server when the user interacts with the instance created from the DRO.

Create a new Client Side Field "DynamicReplicatedObject" as noderef
Create a new Client Side Class Called "IsDynamicReplicatedObject"
Add Field "DynamicReplicatedObject" to it.


From the tutorial change:

Code: [Select]
// Asynchronous callback resulting from calling the external function AddAssetSpecToPropBucketCB()
method AssetSpecReady(spec as NodeRef of Class HBSpec, loadFailed as Boolean)
  println( "AssetSpecReady: " + spec.LW_FIELD_sFQN + " IsReady: " + IsAssetSpecReady( "DYNAMICREPLICATEDOBJECT", me.DRO_AssetID ) + " IsBroken: " + IsAssetSpecBroken( "DYNAMICREPLICATEDOBJECT", me.DRO_AssetID ))
  if not loadFailed
    // Remove existing instance, because we are about to create a new one using this asset spec
    instance as NodeRef of Class HBNode = me.DRO_InstanceID
    if instance <> None
      me.DRO_InstanceID = 0
      RemoveInstanceFromPropBucket( "DYNAMICREPLICATEDOBJECT", instance )
    .
 
    instance = CreateInstanceFromPropBucket( "DYNAMICREPLICATEDOBJECT", me.DRO_AssetID )
    me.DRO_InstanceID = instance
    SetNodePosition( instance, me.DRO_Position)
    SetNodeRotation( instance, me.DRO_Rotation)
    instance["LODFactor"] = 10
    instance["DiffuseColor"] = "#.267,.0,1.0,1.0"
    instance["AmbientColor"] = "#.267,.0,1.0,1.0"
    ActivateInstance( instance, "")
  .
.

to

Code: [Select]
// Asynchronous callback resulting from calling the external function AddAssetSpecToPropBucketCB()
method AssetSpecReady(spec as NodeRef of Class HBSpec, loadFailed as Boolean)
  println( "AssetSpecReady: " + spec.LW_FIELD_sFQN + " IsReady: " + IsAssetSpecReady( "DYNAMICREPLICATEDOBJECT", me.DRO_AssetID ) + " IsBroken: " + IsAssetSpecBroken( "DYNAMICREPLICATEDOBJECT", me.DRO_AssetID ))
  if not loadFailed
    // Remove existing instance, because we are about to create a new one using this asset spec
    instance as NodeRef of Class HBNode = me.DRO_InstanceID
    if instance <> None
      me.DRO_InstanceID = 0
      RemoveInstanceFromPropBucket( "DYNAMICREPLICATEDOBJECT", instance )
    .
 
    instance = CreateInstanceFromPropBucket( "DYNAMICREPLICATEDOBJECT", me.DRO_AssetID )
    me.DRO_InstanceID = instance
    SetNodePosition( instance, me.DRO_Position)
    SetNodeRotation( instance, me.DRO_Rotation)
    instance["LODFactor"] = 10
    instance["DiffuseColor"] = "#.267,.0,1.0,1.0"
    instance["AmbientColor"] = "#.267,.0,1.0,1.0"
    ActivateInstance( instance, "")
////////////NOCAKE - THE CHANGE
   GlomClass("IsDynamicReplicatedObject",instance)
    where instance is kindof IsDynamicReplicatedObject
      instance.nodereference = me
    .
//////////NOCAKE - END CHANGE
  .
.

We glom the new class onto the instance object and then check for it on our "on use" call

When raycasting objects check it with:

Code: [Select]
   
      where hit_node is kindof IsDynamicReplicatedObject
         $INPUT.InputDoMouseClick(hit_node.nodereference, lmb, rmb, mmb, mb4, mb5)
         return true
      .


Now when you raycast on a dynamically replicated object you can reference back to the DRO on the server side easily. This allows for you to glom classes onto the DRO server side to hold custom information about a DRO in your world.
« Last Edit: May 26, 15, 04:33:07 AM by nocake »
Logged