SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
88 stars 18 forks source link

Effects with serverside custom data #96

Closed Trojaner closed 6 years ago

Trojaner commented 6 years ago

Currently effects can not display any data sent by the server.

My idea is to trigger effects like this:

[SteamCall]
public void triggerEffect(CSteamID sender, ushort effectId, ..., string[] bindings)

(bindings is optional)

bindings would replace {0} in texts with bindings[0], {1} with bindings[1] etc... (e.g. Hello {0} would become Hello Trojaner if bindings is set to {"Trojaner"})

This could use string.Format to implement it.

The reason why I ask for this is to have more dynamic effects possible (e.g. an effect displaying "You killed xxxxx!" on the screen)

Of course these effects with data binding should not be able to get triggered by triggerEffect without bindings or wrong bindings.

Actually I would prefer object[] bindings but that seems not possible with the current serialization.

vlasooff commented 6 years ago

Yes, many people dream about this, we had such a problem, either the animation of the effect, or many effects (same type), or chat.

N1GHTPATROL commented 6 years ago

This would allow for so much haha

SDGNelson commented 6 years ago

How do you propose the game find strings to format with your bindings? Or just looking through every string field on the object?

Trojaner commented 6 years ago

loop string fields as soon as assets load and cache them maybe?

RoyIL commented 6 years ago

@SDGNelson Hm?

Trojaner commented 6 years ago

effects are unity prefabs so its a bit hard to have data on them

but it should not be impossible

SDGNelson commented 6 years ago

Sorry - this is still on my radar, but not super high priority between balancing 4 and 3 development. I'm thinking the next update will be Christmas related, and then I'll be back to Calgary for the holiday. I promise I'll get at least formatting custom effect strings into Text.text sometime January!

SDGNelson commented 6 years ago

This Friday's update has two new features available in EffectManager.sendUIEffect which should allow some neat stuff:

  1. You can optionally provide a 16-bit "key" (or -1 to disable) which will remove an effect with the same key before spawning the new one. My thinking is that this will allow you to update effects rather than repeatedly sending them.

  2. You can format up to 4 strings into your effect similar to the original post e.g. {2} will be replaced with arg2.

Closing the issue, but interested to see what you can make with it and further requests.

Trojaner commented 6 years ago

Thanks for adding it 👍 , But arent 4 strings a bit limited? What about having dynamic size array instead? (E.g. sending size of string array, then for each string first sending size of string then the characters themselves)

I dont know if the SteamCall serialization supports string arrays as arguments but worst case is sending it as packet stream, like this:

(pseudo code)

//sending
string[] array = ...
send(array.Length)
foreach(string s in array)
{  
    send(s.Length);
    foreach(var c in s) 
       send(c);
}

//receiving
int length = read<int>();
string[] array = new string[length];
for(int i = 0; i < length; i++) 
{
   int strLength = read<int>();
   StringBuilder sb = new StringBuilder();
   for(int j = 0; j < strLength; j++) {
       sb.Append(read<char>());
    }
   array[i] = sb.ToString();
}
aviadmini commented 6 years ago

Just use chunk buffer packet type with dynamic array of args :)

Tell me if code needed 💃

SDGNelson commented 6 years ago

It would be fairly straightforward to add read/write string array to the Block class, but in what cases would you need that many strings?

Trankvil commented 6 years ago

EffectManager.sendUIEffect(3, 11234455, player.CSteamID, true, String.Format("Hello"), String.Format("Man"), String.Format("Man"), String.Format("Man")); is dont work

aviadmini commented 6 years ago

@Trankvil https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/short Special for you

@SDGNelson ... sendUIEffect without steamID parameter methods are booed. You need to call not tellUIEffectbut overloads with arguments like tellUIEffect4Args since you're sending those

Otherwise works fine. Something like https://youtu.be/ZQbvzb13vFE is doable without pain in the ass

Trankvil commented 6 years ago

@aviadmini

EffectManager.manager.channel.send("tellUIEffect4Args", steamID, (!reliable) ? ESteamPacket.UPDATE_UNRELIABLE_BUFFER : ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { id, key, arg0, arg1, arg2, arg3 });

this code?

aviadmini commented 6 years ago

@Trankvil You don't need this

Btw @SDGNelson there's no way to remove effect from indexed on client, is there? (key = -1 simply destroys effect)

Trankvil commented 6 years ago

@aviadmini stop. i dont understand... me need upload mod in workshop?

aviadmini commented 6 years ago

If you want it to work - yes 💃

@SDGNelson Could you also add an option to update indexed effect with same ID, not just spawn a new one with new string? I can provide the code

Trankvil commented 6 years ago

@aviadmini i have code:

EffectManager.createAndFormatUIEffect(3, sdd, String.Format("Hello"), String.Format("Man"), String.Format("Man"), String.Format("Man"));

I understand, I need to have a mod with a canvas, where I want to output, right?