Jump to content

A16 - djkrose's Scripting Mod


djkrose

Recommended Posts

djkrose's

Scripting Mod

 

Adds Lua and JavaScript support and

other unique functionality to 7DTD dedicated servers.

 

Infos and Download

 

- Now open source! -

 

This mod adds support for scripting custom commands and events directly in Lua or JavaScript. It is NOT a bot for telnet. Instead, it runs directly IN the game and has full access to all .Net CLR, Unity data, 7DTD data, and full OS access. You can basically change any behavior without even restarting. Scripts can communicate with any external system like web services, REST/JSON, databases, files, email, and so on. – See the Github page for details.

 

 

Built-in Commands

 

The mod also includes some unique built-in commands (see help <command> for details):

 

[TABLE]

[TR]

[TD]dj-export[/TD]

[TD]Exports a prefab including all container content, sign texts, ownership, etc.[/TD]

[/TR]

[TR]

[TD]dj-import[/TD]

[TD]Imports a prefab, optionally including all container content, sign texts, ownership, etc.[/TD]

[/TR]

[TR]

[TD]dj-pos[/TD]

[TD]Shows the current player's position in various units and formats[/TD]

[/TR]

[TR]

[TD]dj-log-events[/TD]

[TD]Enables or disables logging of events to the server console.[/TD]

[/TR]

[TR]

[TD]dj-regen[/TD]

[TD]Regenerates a chunk or custom area based on the world seed[/TD]

[/TR]

[TR]

[TD]dj-repair[/TD]

[TD]Repairs server problems of various kinds[/TD]

[/TR]

[TR]

[TD]dj-eac-whitelist[/TD]

[TD]Allows players to be exempt from EAC checks on an EAC-enabled server[/TD]

[/TR]

[TR]

[TD]dj-patch[/TD]

[TD]Enables or disables runtime server patches[/TD]

[/TR]

[TR]

[TD]dj-version[/TD]

[TD]Shows djkrose's Scripting Mod version information.[/TD]

[/TR]

[TR]

[TD][/TD]

[TD][/TD]

[/TR]

[TR]

[TD]Included scripts:[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]dj-test-js[/TD]

[TD]Test basic JavaScript functionality and assembly import[/TD]

[/TR]

[TR]

[TD]dj-test-lua[/TD]

[TD]Test basic Lua script functionality and assembly import[/TD]

[/TR]

[TR]

[TD]dj-minibike[/TD]

[TD]Teleport your minibike back to your position (in case stuck or lost)[/TD]

[/TR]

[TR]

[TD]dj-sleepers[/TD]

[TD]Removes all sleeper volumes from the current chunk (useful after removing a POI)[/TD]

[/TR]

[TR]

[TD]_dj-variables[/TD]

[TD]Example script to show how to access certain game objects. Doesn't output anything.[/TD]

[/TR]

[TR]

[TD]_dj-pay[/TD]

[TD]Allows players to pay with in-game items (see script comments). [suggested by Trekkan][/TD]

[/TR]

[TR]

[TD]_event-...[/TD]

[TD]A couple of event scripts to show how to bind functionality to game events.[/TD]

[/TR]

[/TABLE]

 

_ = Deactivated by default; remove underscore from filename to activate.

 

Latest Release

 

Version 1.0 - compatible with A16.4 (b8)

 

 

  • Removed all obfuscation and made the mod open source.
  • Added event system that allows logging or scripting of in-game events.
  • Added command "dj-log-events" to manage event logging. See help.
  • Added 28 selected events with custom event data.
  • Added 5 example scripts for events.
  • Added possibility to disable scripts by prefixing them with underscore (_). Disabled example scripts.
  • Added telemetry and exception reporting; deactivate with <Telemetry>false</Telemetry> in settings.
  • Changed script commands js-test, js-minibike, js-sleepers, and lua-test to all use "dj-" prefix instead.
  • Changed syntax of "dj-patch XYZ on" to "dj-patch xyz /on" to match other command syntax.
  • Fixed: Parsing of script metadata can be very slow or freeze when file has many comments [#4]
  • Fixed: Incompatible line breaks in scripts on Linux [#28]
  • Removed deprecated command "dj-check-power". Use "dj-repair" instead.

 

Help and Feedback

 

Detailed documentation and API specification is just starting to grow: Documentation Wiki

 

Also have a look at the many example scripts included. Remove the underscore (_) from filename to activate and test.

 

For further help and other questions just use this thread so others can answer or benefit as well. If you wanna have a chat, find me in my Discord channel.

 

To report bugs and feature requests please use the Github issue tracker.

 

.oO( djkrose )Oo.

Link to comment
Share on other sites

I just copied over a prefab from one server to another with your tool. it worked well for the most part...i just saw a couple of issues that may need to be addressed.

 

First, i had to play with the export and import...i had to exaggerate the y number for underground portion of the base because even when i sunk down lower than i thought i needed to be to capture the bottom, it cut off part of the basement....then i had to experiment with placing is as it wanted to put the whole thing above ground by default.

 

The bigger issue is that the script missed a couple of things. it didnt copy over the engines in the generator (probably the same for battery and solar banks but i didnt have those in this build)

 

Also, it didnt recreate the wiring that was in place between the lights, switches and generator. Worse, it seems to remember something wrong about the wiring, because as i try to rewire things, the game creates wires streaching off into the distance somewhere...like it is trying to reconnect to the old location somewhere...and i cant remove those connections...so i will have to remove and rebuild/rewire everything

 

other than that, it did a great job.

Link to comment
Share on other sites

The bigger issue is that the script missed a couple of things. it didnt copy over the engines in the generator (probably the same for battery and solar banks but i didnt have those in this build)

 

These things are not included in the prefabs files... Therefore I think, it's not an issue with the script.

 

While scripting exposes all internal data in theory, you probably have a hard time finding out how it works, without looking into Unity/7DTD binaries. - But worry not! I will do that for you and expose a nice and clean script API in one of the next versions, together with a handful of example scripts and documentation.

That sounds really interesting to me. Hope your api has a foolproof design, so I can understand and use it.^^

Link to comment
Share on other sites

These things are not included in the prefabs files... Therefore I think, it's not an issue with the script.

 

my understanding was that it was gathering more than the stuff in the prefab file...since it grabs the chest contents, ownership, lock status and other things and places them in a separate file, i would assume it was going to grab the contents of the electrical items and their connections.

 

if this piece of the script is to restore an intact POI including things not normally captured with the intent to restore from griefing, i would be disappointed to find out all my engines, batteries and solar panels gone...as well as having to destroy and replace all electrical items and rewire post restore.

Link to comment
Share on other sites

Thanks for the feedback @all!

 

First, i had to play with the export and import...i had to exaggerate the y number for underground portion of the base because even when i sunk down lower than i thought i needed to be to capture the bottom, it cut off part of the basement....then i had to experiment with placing is as it wanted to put the whole thing above ground by default.

 

This needs a bit more testing and a clear reproduction scenario as I cannot reproduce it. The import/export use the exact coordinates that you specify, or if you don't specify, the exact coordinates of the player's position. Pay attention that your "eye level" is higher than your actual player's position, which is measured on the sole of your feet by the game. You can see your current Y position either in debugmode by pressing "F3" or on the map. BadCompanySM mod also has a pos command, which shows you the exact current player position.

 

BTW: The coordinates shown in F3 mode are bugged (one too high) for negative values, because it just
cuts
the decimal part of the position, instead of using Math.Floor(). For negative numbers, this results in rounding
up
(=Math.ceil), which puts the location one block further north/east. For example, when standing on (-123.246, -54.79) the F3 mode shows incorrectly position (-123, -54) when you are
actually
standing on block (-124, -55). [
] - The
pos
command from BadCompanySM shows it correctly.

 

If a Fun Pimp is reading: Constructor
Vector3i.Vector3i(Vector3 _v)
seems to be the culprit.

 

The bigger issue is that the script missed a couple of things. it didnt copy over the engines in the generator (probably the same for battery and solar banks but i didnt have those in this build)

 

You are correct. I identified this problem yesterday with Guppycur and have opened an issue for it. I've no idea yet why these contents are not included.

 

https://github.com/djkrose/7DTD-ScriptingMod/issues/2

 

Also, it didnt recreate the wiring that was in place between the lights, switches and generator. Worse, it seems to remember something wrong about the wiring, because as i try to rewire things, the game creates wires streaching off into the distance somewhere...like it is trying to reconnect to the old location somewhere...and i cant remove those connections...so i will have to remove and rebuild/rewire everything

 

Yes, we also discovered this yesterday and opened an issue for it:

https://github.com/djkrose/7DTD-ScriptingMod/issues/1

 

I think I know how to fix it. It's on my todo list for v0.6.

 

The reason for the weird wireing is quite simple: Every power block saves the absolute xyz-position to where wires go. This position is simply copied with everything else, so that wires still point to the old position, even when imported somewhere else. - I would need to adjust the wire positions relative to the new position.

 

This of course also means that wires need to be capped, if only a part of an electric setup is copied. If you copy a turret out without the connected generator, it would end up without a connection in the copy. I think that makes sense.

 

Thanks again for the feedback and testing!

 

djk

Link to comment
Share on other sites

for the wiring my suggestion would be to get the offset from prefab pos on export, then reconvert the vector to world pos on import (import pos + offset vector)

 

Also, I didnt check your dll, but are you using postion, or serverpos for y pos of player?

 

serverpos will give the real pos (serverPos.y/32 to get vector int)

Link to comment
Share on other sites

@StompyNZ: Yes, something like this would do it. I cannot easily modify the metadata object during export, because that would modify the actual metadata in the running game (= re-routing wires), but i can save the original position and adjust during import accordingly. This gives me the added benefit that I can extend the import command to offer importing at the exact old position, e.g. for restoring structures.

 

I first tried serverpos, but am now using position, because that is what's used game-wide everywhere for every action and decision, like AI pathfinding, calculating distance, chunk loading, etc. It is also updated frequently though Entity.OnUpdatePosition, while serverpos is just used intermediary during network communication. position is referenced 178 times, serverpos 6 times. -- What makes you think serverpos is better?

Link to comment
Share on other sites

because position.y won't track your underground position, it will give the surface pos (that's why the teleports to surface happen)

 

It only applies when clipping underground.

 

serverPos seemed to map correctly 100% of the time when above ground, so I don't think the update rate would matter unless doing some high speed maneuvers while exporting :p

 

you could always use serverpos just for the y pos and position for x and z

 

- - - Updated - - -

 

also, would you be able to edit the meta after you have it all in memory?

Link to comment
Share on other sites

New Release: https://github.com/djkrose/7DTD-ScriptingMod/releases

 

Version 0.5 - tested with 7DTD A16.1 (b1)

 

 

I'm also quite far with supporting import/export of electrical blocks and their content, but this fix is not yet in this release. I think/hope it will come with the next.

 

.oO( djkrose )Oo.

Link to comment
Share on other sites

Your saying it has full integration with things outside of just the game, afew things i would like to see if possible.

 

1) Ability to restart the game server from in the game. I manage the server but its being hosted by a mate. he is not always available to shutdown the exe and reload the exe when im patching in new mods etc. - If i could combine this with server tools allowing server countdown notifications i would be super happy.

 

2) We use discord to communicate, i would love to have game chat extracted from the game and able to be posted to discord or teamspeak\vent, etc. lol

 

3) This is something i think would be cool, but i dont know how useful or easy it would be, but what about email notification to owner of a trap, if triggered by people.

Link to comment
Share on other sites

Your saying it has full integration with things outside of just the game, afew things i would like to see if possible.

 

1) Ability to restart the game server from in the game. I manage the server but its being hosted by a mate. he is not always available to shutdown the exe and reload the exe when im patching in new mods etc. - If i could combine this with server tools allowing server countdown notifications i would be super happy.

 

This should easily be possible. You don't need server tools for countdown notifications either, this can be done by a script too. It's a good feature example, so I will try to add an example script for this in the next release.

 

2) We use discord to communicate, i would love to have game chat extracted from the game and able to be posted to discord or teamspeak\vent, etc. lol

 

Currently, scripts can only be triggered by console commands, but I will add events like chat message soon, and then the chat messages could be distributed to Discord, teamspeak, or so.

 

3) This is something i think would be cool, but i dont know how useful or easy it would be, but what about email notification to owner of a trap, if triggered by people.

 

Nice idea, but I don't see a way to achieve it at the moment. The game's trigger system would need to offer some event functionality where a mod can attach and listen to it. I haven't seen this functionality, but I will have a look. - If you see any other mod out there that does any action based on trap triggering, then let me know.

Link to comment
Share on other sites

Your saying it has full integration with things outside of just the game, afew things i would like to see if possible.

 

1) Ability to restart the game server from in the game. I manage the server but its being hosted by a mate. he is not always available to shutdown the exe and reload the exe when im patching in new mods etc. - If i could combine this with server tools allowing server countdown notifications i would be super happy.

 

2) We use discord to communicate, i would love to have game chat extracted from the game and able to be posted to discord or teamspeak\vent, etc. lol

 

3) This is something i think would be cool, but i dont know how useful or easy it would be, but what about email notification to owner of a trap, if triggered by people.

 

#1 there's already a way to do this. He just needs to setup on Windows so it auto restarts if not running (server companies do this but I never looked into it) then all you have to do is type shutdown in console

Link to comment
Share on other sites

New release:

https://github.com/djkrose/7DTD-ScriptingMod/releases

 

Version 0.6 - tested with 7DTD A16.2 (b7)

 

  • Updated compatibility to 7DTD A16.2 (b7)
  • Fixed a bug where permissions for script commands could not be set
  • Extended dj-check-tripwires to repair ALL power triggers: Switch, PressurePlate, TimerRelay, Motion, TripWire
  • Renamed dj-check-tripwires to dj-check-power to reflect the broader usecase
  • Added command dj-pos to show exended informaton about current player's position
  • Added error checks on all commands

Link to comment
Share on other sites

#1 there's already a way to do this. He just needs to setup on Windows so it auto restarts if not running (server companies do this but I never looked into it) then all you have to do is type shutdown in console

 

I know it can be done this way, but i want to be able to have delays on the down time. Not have it immediate.

Link to comment
Share on other sites

New release! I worked hard on the dj-export/dj-import commands to fully support electricity and wires. You can now export and import prefabs with complex electricity setups, and the copy will be fully functional immediately.

 

Also the reworked dj-check-power command can now catch more corruption problems and updates connected power blocks correctly when fixing. You should update to this version to reduce possible errors.

 

Version 0.7 - tested with 7DTD A16.2 (b7)

 

  • Improved dj-import/dj-export command to fully support electricity blocks and wires
  • Improved fixing algorithm in dj-check-power command to be more sustainable
  • Added checks in dj-check-power to find other power-related corruption problems

 

>> Download <<

 

I also made the source code for the dj-check-power command public for reference:

https://hastebin.com/ovoyonuvex.cs

Link to comment
Share on other sites

So your saying that i can build a prefab with electricity and traps etc and this is able to export prefab and import and all that will be there and working. Do we need the script if we import completed prefab in new world or

 

you'll need the mod on the server to do the import, once it's in world you would not be required to have the mod

Link to comment
Share on other sites

Since its confuserexxed and you probab have a good reason for that, i will save the time unpacking by just asking:

 

Have you utilized the chatmessage override api in any way? I want to know cause if you did, my own mod (with loads of chatcommands) will interfere as it does with all mods that do a suppress msg in the override.

 

Thanks,

 

Cheers

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...