WSE - Lua edition [Beta], a new way of scripting

Users who are viewing this thread

So, Ladies and Gentlemen, I added Lua to WSE.

This is meant as a replacement/supplement to the module system.
If you don't already know, Lua is the de facto standard for scripting in the gaming industry - countless games utilize it. It's a powerful tool, especially compared to the module system.
While the MS gets the job done, using it is cumbersome and leaves a lot to be desired.
Now you don't have to rely on the module system anymore for most purposes. My goal was that you never have to touch a single line of MS code again. It's not quite there yet, but it's going in the right direction.
Lua is superior in many ways. Proper functions (with return values!), native arrays/tables, easy string manipulation, easy math, (re)loading code on the fly, incredible flexibility, ...

It's based on a modified version of LuaJIT 2.0.4, a JIT compiler for Lua 5.1. A JIT compiler translates script code to machine code at runtime, which results in a massive performance boost compared to traditional script interpreters. So, if you've ever dreamed about high performance computing inside M&B, your dreams have come true. I added a sandbox that restricts file system access to a root folder, disables execution of anything except Lua files and disables bytecode (could contain exploits). This is important to prevent harm from end users and could be a requirement for hosting providers.

Features include:
  • Easy way of calling game engine operations
  • Game register access
  • Adding/removing module triggers on the fly
  • Game loops (try_for_agents, ...)
  • Native position/rotation "class"
  • Module operations to call lua from the module system

A detailed guide is included in the download (WSESDK\luaGuide.html).

This is the first version I deemed worthy a release, but I'm sure there are bugs left. If you find one, please make a post here which includes:
  • Exact error message
  • Steps/Code to reproduce
  • latest entry in wse_crash_log.txt, if existent
Once it's stable, it will be included into main WSE. Now included in main WSE.
If you give it a try, please leave some feedback here.

Download: https://bitbucket.org/Kumpuu/warband-script-enhancer/downloads/WSE_LUA_0.3.zip  Merged into main WSE
Source Code: https://bitbucket.org/Kumpuu/warband-script-enhancer/src


Thanks to:
-EmielRegis , for testing and finding a crapton of bugs
-Real Human Bean, for technical support
 
Now I only have to learn Lua x)


Seriously though, seems like awesome work at first sight & I will try it out in detail tomorrow^^
Always wanted to learn at least some Lua anyways!


E: Having no idea of Lua and reading the documentation you provided, I just noticed that I'd like some more examples of already written(and working) code. Could you provide some examples?:p
 
Namakan said:
E: Having no idea of Lua and reading the documentation you provided, I just noticed that I'd like some more examples of already written(and working) code. Could you provide some examples?:p

I actually don't have a lot of code to show you, sorry. Only wrote stuff for testing and I didn't keep that. I'll ask
EmielRegis tho, he did a lot of stuff already and I'm sure he is willing to share some of it when he comes online tomorrow.
 
Ok. Here is simple example that will spawn nice and tidy bot rectangle formation around player when someone is hit.

main.lua
Code:
function getmypos()
	for agent in game.agentsI() do
		if not game.agent_is_non_player(agent) then
			game.agent_get_position(1, agent)
			game.display_message(tostring(game.preg[1]))
			break
		end
	end

end

----------------------------------------------------------------------------
spawnSpreadDistance = 1
----------------------------------------------------------------------------
function spawnSquad(troop, amount, position)
	local column = math.floor(math.sqrt(amount))
	local leftovers = amount - column*column
	position.o.x = position.o.x - math.floor(column/2)*spawnSpreadDistance
	position.o.y = position.o.y - math.floor(column/2)*spawnSpreadDistance

	for i=1, column do
		for i=1, column do
			game.preg[1] = position
			game.set_spawn_position(1)
			game.spawn_agent(troop)
			position.o.x = 	(position.o.x + spawnSpreadDistance)

			game.display_message(tostring(game.preg[1].o.x))

			--output:write(position.o.x.."\n")
			--output:flush();
		end
		position.o.x = 	position.o.x - (spawnSpreadDistance*column)
		position.o.y = 	(position.o.y + spawnSpreadDistance)
	end

end


-----------------------------------------------------------


function test()
	getmypos()
	spawnSquad(10, 10, game.preg[1])
end

Some mission template:
Code:
(ti_on_agent_hit, 0, 0, [],
 [
    (lua_call, "@test", 0),
 ]),


If you have any more questions about practical use of wse lua Im happy to help.
 
AgentSmith said:
Alright, thanks. Just a little confused by the lack of response...
This whole forum is pretty sluggish these days, and most of the people here are just trying to figure out how to import an item from one mod to another. :razz:
 
Ruthven said:
This whole forum is pretty sluggish these days, and most of the people here are just trying to figure out how to import an item from one mod to another. :razz:

Guess I should have done this a few years earlier  :grin:
But even if only a handful of people use this, it wasn't wasted. Also learned new tricks while doing it :idea:
 
AgentSmith said:
Makes modding much quicker and more powerful. Or doesn't it?
Depending on coding skills.
I am not a professional coder, so I'm not used to stuff like EmielRegis posted as an example. It looks like {insert_any_difficult_foreign_language_here} to me and the very view of it gives me a headache, while module system looks very simple and almost intuitively clear.
Professionals may find it useful, but noobs like me - probably not.
 
A good training for bannerlord modding. Probably on bannerlord we'll have a tool developed by taleworlds to do basic modding (changing string, adding maps, adding items ecc.). But if you want to do something complex, you've to use C# (by what i know). Yes, module system is easy to understand but is raw and verbose.
 
Leonion said:
AgentSmith said:
Makes modding much quicker and more powerful. Or doesn't it?
Depending on coding skills.
I am not a professional coder, so I'm not used to stuff like EmielRegis posted as an example. It looks like {insert_any_difficult_foreign_language_here} to me and the very view of it gives me a headache, while module system looks very simple and almost intuitively clear.
Professionals may find it useful, but noobs like me - probably not.

Yep, but dont forget that same can be said about python, which is module system foundation. Not to mention that it has some capabilities very usefull for ppl of type "I just wanna add that  hello kitty armors to game" but about it later. Just wait till some nerds make it more acessible for  [quote author=noob]noobs like me[/quote]  :iamamoron:
 
I'm open to trying Lua coding, as the experience would contribute to other projects down the road. My question is will a player require WSE to play the mod? If so, that could be a major deal breaker
 
Bad Idea said:
I'm open to trying Lua coding, as the experience would contribute to other projects down the road. My question is will a player require WSE to play the mod? If so, that could be a major deal breaker

Depends of what mod we are talking. If you mean native compatible server mod then no, only server needs wse. If its a single player mod, or multiplayer that needs installation he will need it.

Cant imagine how its deal breaker tho. Basic WSE works same way and no one ever complained. Also WSE lua installing not gonna make problems to anyone capable of copy paste. Becouse to be honest its everything it involves to non modder. Installing normal mod is copy paste. Why WSE makes difference? You are free to include wse in your mod files with proper instructions so players dont need look for it on their own.
 
AgentSmith said:
Ruthven said:
This whole forum is pretty sluggish these days, and most of the people here are just trying to figure out how to import an item from one mod to another. :razz:

Guess I should have done this a few years earlier  :grin:
But even if only a handful of people use this, it wasn't wasted. Also learned new tricks while doing it :idea:
If you stick around to using this for Bannerlord, this will be an extremely powerful first tool. The Golden Age of modding for this game has died down a few years ago, and now some of the more ambitious mod teams are creating indie games. Plenty of hope for Bannerlord to reinvigorate this community.
 
Leonion said:
It looks like {insert_any_difficult_foreign_language_here} to me and the very view of it gives me a headache, while module system looks very simple and almost intuitively clear.
Professionals may find it useful, but noobs like me - probably not.
As soon as you're trying to make something serious with the MS, you wish you'd have a proper language to work with. This is meant for those cases. Obviously you need some coding skills, nothing anyone can do about that.

Slytacular said:
If you stick around to using this for Bannerlord, this will be an extremely powerful first tool. The Golden Age of modding for this game has died down a few years ago, and now some of the more ambitious mod teams are creating indie games. Plenty of hope for Bannerlord to reinvigorate this community.
That will be a whole new story. Afaik, Bannerlords will have a new engine, so you'd have to create BSE (Bannerlords Script Enhancer) or something similar, before I'd be able to add lua. The lua mod relies heavily on the infrastructure and game access that WSE provides.
On the other hand, maybe Bannerlords will already feature a grown up modding system.
 
The module system's not very intuitively clear, at least not if you're coming from the other end (having coded a lot). You miss out on a lot of logical things; basic OOP of instanciating functions, proper return values (foo = bar() gets the returned value of the function bar....). 'Real' variables I miss the most. I could even get by the "if-else" system of try-begin with equal checks, if we would've had those in a normal-fashioned programming way.

I'll definitely try Lua out when making my AI. :party:
 
Back
Top Bottom