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/
85 stars 18 forks source link

System events for modding. #435

Closed vlasooff closed 5 years ago

vlasooff commented 5 years ago

You probably know that you can add scripts to a file with a mod (.unity3d). Of course, if these scripts are in the game. I have an idea. Simple example: image

Edsparr commented 5 years ago

Don't wanna be that guy but there is a reason to why scripts are banned after all. If there was a way around that I would love to see that though.

vlasooff commented 5 years ago

I have already added component Landscape this way to the game, and not any problems.

Edsparr commented 5 years ago

Oh, wait I think it's limited on workshop only? Maybe it's changed, not sure.

aviadmini commented 5 years ago

OnEnterVehicle -> Add KillVolume -> OnVehicleExploded -> OnPlayerDied -> Profit

vlasooff commented 5 years ago

there may be many. OnDay OnNight etc.

Trojaner commented 5 years ago

1) You can not export scripts with asset bundles. 2) This would be very dangerous

vlasooff commented 5 years ago

You can use a copy of the script from the game by adding it asset bundles!

Trojaner commented 5 years ago

No, you can not export scripts.

vlasooff commented 5 years ago

I personally attached the script component Landscape and added it from the objects to the game, your inexperience.

khakers commented 5 years ago

You cannot have any custom script in assetbundles but you can reference scripts in game through a bug

aviadmini commented 5 years ago

You can attach scripts that already exist in game. But there's not many useful ones

It's not a bug just the way that Unity works

vlasooff commented 5 years ago

Thus, if a developer adds a script and throws us an example, we will be able to use it.

vlasooff commented 5 years ago

And I'm talking about events that will be useful for modding.

SDGNelson commented 5 years ago

The other comments are correct that you unfortunately cannot export scripts inside asset bundles. If you open the asset bundle file you can see that they're serialized as numeric IDs of components included with vanilla Unity so that you can bundle components like meshes, landscapes, lights, etc.

I believe I saw a blog post (maybe from Facepunch?) recently about how they extended this list of IDs to include their own code, however that would still be limited to components from the game's dlls.

For the most part these sorts of events are currently possible by hooking events in the base game using Rocket or the modules feature.

SDGNelson commented 5 years ago

As an example here's the header for 4's headlights component (picked random recent bit of code), much better documentation coverage and designed for modded components to hook events or inherit from.

https://gist.github.com/SDGNelson/0e6057ec280b0eb302879d459b5814ff

vlasooff commented 5 years ago

https://steamcommunity.com/sharedfiles/filedetails/?id=1086881979&searchtext=script Read, here is what I mean, UnityEvent with game events. Add separate scenarios with events and call these events, and we attach scripts to objects and listen to events. And send the scripts to us so that we add them to the gameobject. Sorry for my english please.

vlasooff commented 5 years ago

You are talking about modules, but if I'm not mistaken, players will not be able to load them (for example, as mods). I use some tricks to fundamentally change the logic of the game on the server (and these are not modules or plugins), but this is not enough for me. For example, not so long ago I made endless ammunition for turrets

SDGNelson commented 5 years ago

Interesting, I wonder if Unity hashes the attached script and then the game recognizes the hash is the same as one in the assembly. (I imagine that's why the script has to be identical.)

From your original example it looks like you want delegates for existing scripts, in which case do they even need to be attached? Rocket plugins already hook delegates from the vanilla scripts for many things.

aviadmini commented 5 years ago

It doesn't have to be identical. It just needs to have same entry points. Moreover, only those you need

vlasooff commented 5 years ago

@SDGNelson We are waiting for the event system for mods.)))

aviadmini commented 5 years ago

Lolz, "we are waiting" sounds so wrong. At least provide some use cases

vlasooff commented 5 years ago

@aviadmini This is just a contraction, and developer support, and I once again apologize for my English.

aviadmini commented 5 years ago

And yet you forgot to provide some use cases

vlasooff commented 5 years ago

In general, I can make events myself, send scripts to the developer, and the developer simply adds them to the game and initiates the events?

vlasooff commented 5 years ago

Hi, I created an example.

  1. I created the VehicleEvent script in Assembly-CSharp.dll image
  2. I changed the method in VehicleManager.enterVehicle image Got the component "VehicleEvent" with the gameobject "Vehicle" and raised the OnEnter event... In the same way, I changed the VehicleManager.exitVehicle method and added an OnExit event call. 3.I added a copy of the “VehicleEvent” component to the “Vehicle” gameobject and added lighting to the train when the player returns to the train the light turns on, and when he leaves the train the light turns off. image Here's what happened: 20181104161023_1 20181104161043_1 20181104161058_1 20181104161130_1 There is an idea with keystrokes, there is an idea with triggers ...
vlasooff commented 5 years ago

I can implement various event systems and provide samples to the developer, can I do it or not? =\

SDGNelson commented 5 years ago

Interesting, thank you for the example. I wasn't aware unity events let you control properties like that. (they're not used in the game anywhere) Not sure when the next update will be, but as an experiment I'll add a bunch of events for vehicles similarly to what you requested + more, and we'll see how it goes.

vlasooff commented 5 years ago

Always happy to help ... =)

SDGNelson commented 5 years ago

"+ more" was an overstatement, for the next update here's the hook: https://gist.github.com/SDGNelson/61b5f598cbe3553ba53c04b074577d7f These scripts will be kept in the Bundles/Sources/ModHooks/ folder.

Once the update is out let me know if it works correctly for you, and from there you can let me know other events needed!