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

Patch Notes for v0.1.4

  • Added new methods to Ped
  • Added new methods to Player
  • Added new function to Utils
  • Fixed bug with Onesync and StateBag class not sure
  • Fixed bug with ShowNotification
  • Updated timeout functions to 20 seconds
  • Fixed Marker class, marker appears on center now
  • Fixed Coords:AddBlip
  • Removed unused prints

Commit

Release notes v0.1.5

  • Added new util, DrawText3D
  • Added new methods to Vehicle client-side
  • Fixed ShowHelpNotification
  • Fixed ShowNotification

Commit
Download

Documentation

You can check the tutorial on how to start a new resource using classes: https://pitermcflebor.github.io/tutorial/

1 Like

Release notes v0.1.6

  • Added version check
  • Added new method to Ped client-side

Commit
Download

1 Like

How can i improve this? I want to spawn a vehicle on selected position. Just one forever.

Problem: sometimes there is nothing spawned.

Server:

alGespawnedTitanic = false

RegisterServerEvent('DP_Wrakken:SpawnTitanic')
AddEventHandler('DP_Wrakken:SpawnTitanic', function()
	if alGespawnedTitanic == false then
		local model = tostring("titanic2")
		local s = tonumber(source)
		if s > 0 then
			local player = CPlayer(s)
			local titanic = Vehicle(true, model, -1872.7, -1273.22, -13.5, 50.0, true)
			titanic:WaitForExistence()
			titanic:Freeze(true)
			alGespawnedTitanic = true
		end
	else
	
	end
end)

Client:

Citizen.CreateThread(function() -- goed
	lul = true
	while true do
		Citizen.Wait(0)
		if lul == true then
			if GetDistanceBetweenCoords(-1872.7, -1273.22, -2.4, GetEntityCoords(PlayerPedId()).x, GetEntityCoords(PlayerPedId()).y, GetEntityCoords(PlayerPedId()).z, true) < 1500 then
				TriggerServerEvent('DP_Wrakken:SpawnTitanic')
				lul = false
			end
		end
	end
end)

I did client sided spawn only in my first editions. Client sided will cause to spawn the vechile multiple times. Classes resource is helping me spawning them only once more easy.

I don’t really understand this problem, probably when you spawn the vehicle there isn’t any player on the scope of the vehicle. Try to reduce the distance to spawn to 500 units not 1500.

The :Freeze() method doesn’t need a true to be passed, it only accept a number.

For example:

-- vehicle spawned
titanic:Freeze(500) -- this means will be unfrozen after 500 ms
if titanic.freezed then -- there's a variable inside to check if it's frozen or not
   titanic:Freeze() -- if .freezed was true, only calling this method again will unfreeze it
end

P.S.:
You could save the vehicle spawned server-side as a global var, so when a player tries to spawn the vehicle, you can check if the vehicle:Exists() to spawn a new one or not.

v0.2.0 BIG CHANGES?

Release notes

  • Don’t need anymore to import classes as ‘@classes/…’

Check the new method here

Commit
Download

v0.2.2

Release notes

  • Added Wait modifier for markers (less lag when far)
  • Fixed StateBag client-side at Player class
  • Updated StateBag client-side

Commit
Download

v0.2.3

Release notes

  • Fully added compatibilty with older versions (before v0.2.0)
  • Updated long strings from [[ to [=[

Commit
Download

v0.2.4

Release notes

  • Updated import method
    This doesn’t affect to older versions!

Commit
Download