[RELEASE][WIP] Lua *classes* for everyone

Lua classes/types [WIP]

I have been working on this, making some “classes” or “types” for Lua.
This will improve your code and be easier to read.

Features:

  • Easy to use
  • Advanced coding
  • Advanced error log on console

Examples:

A simple command for creating vehicles from the server-side:

made with PolaCode from VSCode

There’s an error on vehicle:EveryoneLeave() because the vehicle got deleted before.
This is how it will be printed on the server-console:

More examples: at the docs page you have an example for every class and method!

Download:

Code:

Documentation:

A WIP documentation: https://pitermcflebor.github.io/

Release notes:

here: https://pitermcflebor.github.io/#release-notes

7 Likes

great job but if u want OOP in lua u can use ImagicTheCat’s lib thats used in vRP2
u can use it w/o vRP2 too

I didn’t know about Luaoop library, but I don’t really need it. I just created own classes and other users doesn’t need to know how to create new classes.

I appreciate your reply :slight_smile:

Ok I like what you have done good job but I cant really understand some of the tings what do. So if you add some kind of a documentation of explanacion of the things you have added it will be great and maybe how to use them an example would be nice but still good job man

Awesome! Keep it up. :slight_smile:

It will optimased the script?

I will be working on a documentation and examples.

1 Like

The optimization of the script depends on your coding.

1 Like

Wait. Am i now able to spawn vehicles from server side? I realy needed this

Thank you so much!

We can now spawn static vehicles without any problem and no double spawns!

We use this for ships underwater were people can dive to. We have now 9 big ships frozen in the deep waters :slight_smile:

Isn’t Player() already used by fivem to get a player’s state bag?

Yeah, you’re right. I will change the Player class to CPlayer.

This is awesome, love it!

I don’t know if people get notifications when I edit the post, so I will be replying with the patch notes.


v0.1.3

  • Added method AddBlip to Coords class
  • Added methods GetPosition and SwapModel to class Prop
  • Added function TimeoutRequestModel to utils
  • Added common methods (string and table)
    • :split()
    • :startsWith() :endsWith()
    • :trim()
    • table.build()
    • table.fill()
    • table.dump()
  • Removed error when trying to create a Ped class with non existent entity (now is only a warning)
  • Updated state for Player class
  • Updated StateBag for players

Commit
Download

2 Likes

Wow!! Great job!!! Thank you!!

local s = tonumber(source)
local player = CPlayer(s)

SCRIPT ERROR: @classes/server/ped.lua:79: attempt to call a nil value (global ‘StateBag’)

CPlayer (@classes/server/player.lua:46)
handler (@DP_Wrakken/server/main.lua:19)

I do have source and local player = Player(s) was working on v1

There are new classes, you need to import them.
Your error is because you are missing to import StateBag @classes/server/statebag.lua

Thanks!

The vehicle is spawning now with this fxmanifiest:


server_scripts {
	'config.lua',
	'server/main.lua',
	'@classes/server/utils.lua',
	'@classes/server/coords.lua',
	'@classes/server/ped.lua',
	'@classes/server/player.lua',
	'@classes/server/vehicle.lua',
	'@classes/server/statebag.lua',
	'@classes/common/utils.lua',
	'@classes/server/prop.lua',
}

But this error in server:
local vehicle = Vehicle(true, model, -1872.7, -1273.22, -13.5, 50.0, true)

SCRIPT-WARNING [@classes/server/vehicle.lua:88:StateBag]: The entity you are trying to set StateBag doesn't exists! Maybe a onesync issue? 
InvokeNative: execution failed: Tried to access invalid entity: 135429
SCRIPT ERROR: Execution of native 000000009e35dab6 in script host failed: Tried to access invalid entity: 135429
> StateBag (@classes/server/statebag.lua:24)
> Vehicle (@classes/server/vehicle.lua:88)
> handler (@DP_Wrakken/server/main.lua:20)

Can you remake this