Vice City: Multiplayer

Server Development => Community Plugins => Topic started by: DizzasTeR on Nov 05, 2020, 12:53 PM

Title: Lua Plugin
Post by: DizzasTeR on Nov 05, 2020, 12:53 PM
Here's a Lua plugin for VCMP. It lets you script in Lua (No sh!t Sherlock :o) Also because python sucks kekw @Shad

https://github.com/DizzasTeR/VCMP-Lua

Downloads are available in the release (https://github.com/DizzasTeR/VCMP-Lua/releases) section over at GitHub

Features:

Blank Script (Lua Version): https://github.com/DizzasTeR/VCMP-Lua/wiki/Blank-Script

Important: You need OpenSSL (F**K MySQL and everything related to it): https://slproweb.com/products/Win32OpenSSL.html OR Just place the two DLLs available with plugin download and place them in server directory

If you are going to try this out, I've written a README on GitHub which you should totally check out. I've also written as much wiki (https://github.com/DizzasTeR/VCMP-Lua/wiki) on github as I could and its written enough to let anyone be able to do stuff.

Note: Please know that I may have missed some functions of VCMP, if someone is actually going to use this and you come across a functionality that doesn't exist, let me know I can try looking into it.

:edit: You CAN set up LuaRocks or LuaDist to use third-party pre-made lua libraries but I didn't really test them, so if you are really into Lua, you may try that.
Title: Re: Lua Plugin
Post by: Inferno on Nov 06, 2020, 04:32 AM
Great work.
Title: Re: Lua Plugin
Post by: NicusorN5 on Nov 06, 2020, 05:24 PM
Speed performance between LUA and Squirreil when?
Title: Re: Lua Plugin
Post by: DizzasTeR on Nov 07, 2020, 04:48 AM
While there's more evidence towards Squirrel being more "efficient" than Lua because it provides functionality based on your needs (Take static and dynamic arrays in squirrel for example, you use one which fits more) however in Lua you just straight up throw Tables for anything and it just works. Both languages are close, one has advantages over the other.

However LuaJIT is faster than Squirrel I believe.

:edit: Also Lua is actively maintained right now and more popularly supported
Title: Re: Lua Plugin
Post by: DizzasTeR on Nov 11, 2020, 11:39 AM
Update
— Added SQLite3 Module (https://github.com/DizzasTeR/VCMP-Lua/wiki/SQLite3-Module)
— Small new features & logical fixes

Quote from: Athanatos on Nov 06, 2020, 05:24 PMSpeed performance between LUA and Squirreil when?
After testing, faster than squirrel. How much and in what scenarios is subjective.
Title: Re: Lua Plugin
Post by: DizzasTeR on Nov 12, 2020, 03:46 PM
Update
JSON Script Module (https://github.com/DizzasTeR/VCMP-Lua/wiki/JSON-Module). Provides following two functions: JSON.stringify and JSON.parse
— Server.shutdown() was missed, added now.
Title: Re: Lua Plugin
Post by: DMWarrior on Nov 16, 2020, 09:00 PM
Good work! Lua support can be very interesting, not only due to it's popularity, but because it has more libraries avaliable than Squirrel, too.

I still don't know what I could do with it, though. But for anyone interested in giving a try, I managed to rewrite most of the VC:MP Blank Server (https://forum.vc-mp.org/?topic=33.0) to Lua, as well looking through each function and finding which ones are missing. The only problem is that SendDataToClient() doesn't work, but everything else seems to be fine.

This, alongside the Wiki (https://github.com/DizzasTeR/VCMP-Lua/wiki), should be enough for getting started:
VC:MP Blank Server (Lua Script) (https://hastebin.com/pidulibeli.lua)
Title: Re: Lua Plugin
Post by: DizzasTeR on Nov 17, 2020, 03:53 AM
Such an amazing contribution @DMWarrior

I've looked through the code and everything seems great, I don't know regarding the SendDataToClient failing to work but I'm sure I did test all the stream stuff however I'll double check it again. However I would rather just recommend using the JSON module to just send a nice JSON string as a single string and then using the squirrel json script on client side to decode it back, its one of the easiest and best ways to just send info back and forth.

It seems you made a mistake writing the SendDataToClient function, when you're taking the stramType from argument[1], you no longer need to include the first parameter in your further data extraction, you should be going through arguments[2] to #arguments or basically #arguments - 1 (Updated version of your script is now on github with a fixed SendDataToClient)

I will also add that script to the github wiki as a source of code example and getting started.
:edit: Available now: https://github.com/DizzasTeR/VCMP-Lua/wiki
Title: Re: Lua Plugin
Post by: DMWarrior on Nov 22, 2020, 10:58 AM
I made some minor changes on Blank Server:
Updated Blank Server (Lua script) (https://hastebin.com/iwagedumad.lua)

After setting up "package.path", we can easily load modules with require(). For anyone who's not familiar with Lua, here's an example:

MyModule.lua
----
-- @module MyModule
--
local M = {}

----
-- A function.
--
function M.hello()
  print("Hello, world!")
end

return M

Server script
local MyModule = require("MyModule")
MyModule.hello()

And since Lua has no classes, libraries like middleclass (https://github.com/kikito/middleclass) can be extremely useful, specially when combined with modules. It's easier to work with in comparison to Squirrel, at least in my opinion.

After noticing that VEH_ constants are missing, I decided to make a very simple list, too:
Vehicles List (Lua Script) (https://hastebin.com/uwetubutic.m)

Nothing amazing or interesting yet, though, but it may gain some more interest once there's more scripts available to work with. One idea would be rewrite some scripts from Squirrel to Lua so they could be used as example or base for other scripts. I don't know if anyone would do it, but I could try doing this with some of my scripts to see how it looks.
Title: Re: Lua Plugin
Post by: DizzasTeR on Nov 24, 2020, 11:56 AM
Lua Plugin 2.0 Beta released

After knowing some interesting people who started using this plugin, the development and updates have been going strong to add the remaining bits and features.

The latest 2.0 release provides a CPR module which gives you access to Remote.fetch and Remote.post. More on them on wiki (https://github.com/DizzasTeR/VCMP-Lua/wiki/CPR-Module).
Title: Re: Lua Plugin
Post by: habi on Nov 06, 2022, 02:35 PM
Nice work.