Garry's Mod

Garry's Mod

Gmod Blueprints (Visual Scripting)
Origin of this addon
i just wanted to know how did you make this addon? for example, how did you coded it and how was the design for the whole blueprint template made. Because i installed Python 2 days ago and i got a little bit inspired. can you give me a tip how to do it? it would be really nice ty.
Showing 1-1 of 1 comments
Kaz  [developer] May 30, 2020 @ 10:12am 
Hi, apologies for this late response, I don't check this workshop page very often.

So this whole thing started back in September;
I drew some ASCII diagrams of how the nodes would be connected, and how you'd make a simple Garrysmod thing in Blueprints.
I also poked around at Unreal's nativization tech to get a feel for how they 'compiled' a blueprint.

I decided to start with an extremely simple 'script':
OnThink -> If player is crouching -> Set player velocity to 0,0,1200

I wrote a Lua script to represent nodes and their connections: https://pastebin.com/kvM6zHi6
The blueprint did not function in anyway, I was mainly trying to feel out the structure of a graph:
- There are nodeTypes, each with a list of input and output pins
- There are nodes, each pointing to a nodeType and having an X, and Y coordinate
- There are connections, each containing 4 values (nodeA, pinA, nodeB, pinB)

With those fundamentals, I could hard-code a graph and represent it on the screen visually.
If you look at line 106 in the code listing above you can see the hard-coded simple test blueprint.

After I had a graph structure laid out, I started working on the compiler.
The goal was to convert these nodes into Lua code.

The approach I came up with is as follows:
1. Make a 'variable' for every output pin on all the nodes and emit them at the top of the script.
2. Compile each node into a Lua statement, this pass pulls variables from the previous pass.
3. Compile function nodes, and at each function node, walk backwards through all its connected pure-nodes, prepending their code.
4. Emit each compiled function node with a jump label and a goto statement to jump to the next function.

If you want to see what this looks like, this is the earliest version of the compiler I could find (6 days after starting the project):
https://pastebin.com/nR5UUVQw

If you look at the function on line 536, you can kind of see the broad strokes of how the compiler builds a script from the graph.

Now of course compilation isn't the only way to run a visual graph.
You could give each node a function to run, and have it pull from an input pin, and store the result on an output pin.
Then have your program tell all the nodes to do their thing.

My advice to you is to start as simple as possible, and build things out as you go.
Start with a simple representation of a graph of nodes, and build the simplest logic to test it.
Make a graph as simple as: "5 -> square number -> print" and see if you can get it to print 25.

If you have more questions, or just want to chat, feel free to drop by the Discord server, I'm most active there.

Cheers,
-Zak
Showing 1-1 of 1 comments
Per page: 1530 50