#How to achieve Client side only changes

68 messages · Page 1 of 1 (latest)

elfin cove
#

Is it possible to change, for example, the color of a spawned primitive cube only for a single player?
Or even turning off the renderer completely for one/all but one players?

coral vale
#

you can send fake sync vars to the players that need to be affected

elfin cove
#

hmm that does look like something that would fit my case

thank you ^^

im just not sure how much longer exiled is supported qwq

coral vale
#

it's still in active development, check out their discord server
things happened that is not for discussion here

elfin cove
#

alright ^^

coral vale
#

np

inland goblet
#

DesiredPlayer.SendFakeSyncVar<Color>(primitiveObjectToy.netIdentity, typeof(PrimitiveObjectToy), nameof(PrimitiveObjectToy.NetworkMaterialColor), Color.red);

coral vale
#

oh wait

#

for primitives the uh

#

the dirty bits have to be written twice because the AdminToyBase and its inheritor classes both write the dirty bits

elfin cove
coral vale
#

you'd need to alter the CustomSyncVarGenerator method slightly to write the dirty bits twice if the type is an admin toy
basically just copy the first line and put it behind an if statement targetType.IsSubclassOf(typeof(AdminToyBase))

elfin cove
#

Thank you ^^
If i run into issues ill come back x3

lapis hill
coral vale
#

Repo was unavailable at the time of writing

lapis hill
#

Lemme find the repo

lapis hill
lapis hill
coral vale
#

I didn't think of using gitlab tbh

elfin cove
#

"TargetingSphere" is a PrimitiveObjectToy and was already checked to not be null

#

And i create it using ProjectMERs function

inland goblet
#

use NetworkPrimitiveType

#

nvm its the wrong one

#

NetworkPrimitiveFlags

#

instead of PrimitiveFlags

#

FakeSyncVar only can happen if the setter using SyncVarSetter

elfin cove
#

:o
Thank you!
So i should look out to only be using types with Network in their name?

inland goblet
#

Usually, Otherwise if not just see if the setter has a SyncVar

#

ye you see the GeneratedSyncVarSetter if it didnt has you cant fake that

elfin cove
#

Thank you ^^

#

Well it doesnt create an error anymore, but nothing seems to happen

Owner.SendFakeSyncVar<PrimitiveFlags>(
  TargetingSphere.netIdentity, 
  typeof(PrimitiveObjectToy), 
  nameof(PrimitiveObjectToy.NetworkPrimitiveFlags), 
  PrimitiveFlags.Visible
);
New lines only for readability here. In my code its one line
inland goblet
#

are you sure you spawned? first would be check if actually exists there so it can be set hidden after ensuring spawned/exists

elfin cove
#

It does exist

#

I can also move it using TargetingSphere.transform.position
-# Changing TargetingSphere.Position or .NetworkPosition didnt seem to work

#

I kept it visible but replaced the SendFakeSyncVar with the exact same one you sent in using the NetworkMaterialColor
Also doesnt do anything

elfin cove
#

Would anyone else have any idea what might be wrong?

inland goblet
#

I trying to check these stuff.
Run the log.bat and open the log you would see something like

OnDeserialize failed Exception=System.IO.EndOfStreamException (see below) object=PrimitiveObjectToy(Clone) component=AdminToys.PrimitiveObjectToy netId=593. Possible Reasons:
  * Do AdminToys.PrimitiveObjectToy's OnSerialize and OnDeserialize calls write the same amount of data? 
  * Was there an exception in AdminToys.PrimitiveObjectToy's OnSerialize/OnDeserialize code?
  * Are the server and client the exact same project?
  * Maybe this OnDeserialize call was meant for another GameObject? The sceneIds can easily get out of sync if the Hierarchy was modified only in the client OR the server. Try rebuilding both.
elfin cove
#

hm i only have access to the server via Terabit, and not sure what/where log.bat is, sorry :/

inland goblet
#

inside your client

elfin cove
#

ah, that, right

inland goblet
#
// the primitive
            PrimitiveObjectToy primitiveObjectToy = PrimitiveObjectToy.Create(player.Position);
            primitiveObjectToy.Type = PrimitiveType.Sphere;
            player.SendFakeSyncVar(primitiveObjectToy.Base.netIdentity, primitiveObjectToy.Base, 32UL, PrimitiveType.Cube, (writer, value) => 
            {
                writer.WriteLong(32); 
                writer.WriteInt((int)value);
            });
// the snycvar faker
 public static void SendFakeSyncVar<T>(this Player target, NetworkIdentity networkIdentity, NetworkBehaviour networkBehaviour, ulong dirtyBit, T syncVar, Action<NetworkWriter, T>? writer_func)
 {
     if (target.Connection == null)
         return;
     NetworkWriterPooled writer = NetworkWriterPool.Get();
     ulong value = 0;
     for (int i = 0; i < networkIdentity.NetworkBehaviours.Length; i++)
     {
         if (networkIdentity.NetworkBehaviours[i] == networkBehaviour)
         {
             value = 1UL << (i & 31);
             break;
         }
     }
     // always writing 1?
     Compression.CompressVarUInt(writer, value);

     int position = writer.Position;
     writer.WriteByte(0);
     int position2 = writer.Position;
     networkBehaviour.SerializeObjectsDelta(writer);
     if (writer_func != null)
     {
         writer.WriteULong(dirtyBit);
         writer_func(writer, syncVar);
     }

     int position3 = writer.Position;
     writer.Position = position;
     writer.WriteByte((byte)((position3 - position2) & 255));
     writer.Position = position3;

     // Copy owner to observer
     if (networkBehaviour.syncMode != SyncMode.Observers)
         CL.Warn("Well snyc mode is not observers, sucks to be you I guess.");

     target.Connection.Send(new EntityStateMessage
     {
         netId = networkIdentity.netId,
         payload = writer.ToArraySegment(),
     });

 }
#

i guess works

#

its a shpere but box for me

elfin cove
# inland goblet I trying to check these stuff. Run the log.bat and open the log you would see so...
OnDeserialize failed Exception=System.IO.EndOfStreamException (see below) object=PrimitiveObjectToy(Clone) component=AdminToys.PrimitiveObjectToy netId=571. Possible Reasons:
  * Do AdminToys.PrimitiveObjectToy's OnSerialize and OnDeserialize calls write the same amount of data? 
  * Was there an exception in AdminToys.PrimitiveObjectToy's OnSerialize/OnDeserialize code?
  * Are the server and client the exact same project?
  * Maybe this OnDeserialize call was meant for another GameObject? The sceneIds can easily get out of sync if the Hierarchy was modified only in the client OR the server. Try rebuilding both.
#

yes

inland goblet
#

ye seems like the issue was axwobo said

#

the current thing writing twice the dirtyBit

elfin cove
inland goblet
#

its inside Exiled

#

but you cant really do that

#

since exiled privated MakeCustomSyncWriter what i used

elfin cove
#

So im just at a dead end? :c

inland goblet
#

isnt really good

elfin cove
#

why does this all have to be so convoluted 😭

#

thank you though

inland goblet
#

well since games supposedly doesnt need to use faking something

#

i blame mirror

inland goblet
#
PrimitiveObjectToy primitiveObjectToy = PrimitiveObjectToy.Create(player.Position);
primitiveObjectToy.Type = PrimitiveType.Sphere;
player.SendFakeSyncVar(primitiveObjectToy.Base, 32L, PrimitiveType.Cube);

@elfin cove Copy the FaksyncExtension somehwere you can rename the namespace and include the namespace into the code above