Skip to content

Commit

Permalink
#update : supv_core v0.4 beta
Browse files Browse the repository at this point in the history
- change cache system
- new module for tool
- prepare web files
- set all config by default value
- correct some shit with marker
  • Loading branch information
SUP2Ak committed Aug 14, 2022
1 parent 0fe8d8b commit e678327
Show file tree
Hide file tree
Showing 19 changed files with 801 additions and 250 deletions.
7 changes: 5 additions & 2 deletions _g.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Config = {}
oncache = {}
-- Don't touch hit
_G.Config = {}
_G.oncache = {}

return _G.Config, _G.oncache
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use_experimental_fxv2_oal 'yes'
author 'SUP2Ak'


version '0.3b' -- b for beta
version '0.4b' -- b for beta

description 'a core standalone to manage your server and got useful function to develop it too'

Expand Down
22 changes: 14 additions & 8 deletions import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ local function call_module(self, index)
return module
end

supv = setmetatable({name = supv_core, service = service, oncache = {}, config = {client = {}, server = {}}},{ __index = call_module, __call = call_module })
supv = setmetatable({name = supv_core, service = service, config = {client = {}, server = {}}},{ __index = call_module, __call = call_module })

if service == 'client' then
local PlayerPedId <const>, PlayerId <const>, GetPlayerServerId <const> = PlayerPedId, PlayerId, GetPlayerServerId
RegisterNetEvent('supv_core:refresh:cache', function(cache)
for k,v in pairs(cache)do
supv.oncache[k] = v
end
local PlayerPedId <const>, PlayerId <const>, GetPlayerServerId <const>, GetActiveScreenResolution <const> = PlayerPedId, PlayerId, GetPlayerServerId, GetActiveScreenResolution
CreateThread(function()
supv.oncache.pedid = PlayerPedId()
supv.oncache.playerid = PlayerId()
supv.oncache.serverid = GetPlayerServerId(PlayerId())
return supv.oncache
supv.oncache.screen = {GetActiveScreenResolution()}
end)
supv.oncache = setmetatable({},
{
__index = function(self, k)
RegisterNetEvent(('supv_core:set:cache:%s'):format(k), function(v)
self[k] = v
return true
end)
end
})
TriggerEvent('supv_core:insert:config-client', function(cfg)
for k,v in pairs(cfg) do
supv.config.client[k] = v
Expand All @@ -63,4 +69,4 @@ elseif service == 'server' then
end
return supv.config.server
end)
end
end
28 changes: 14 additions & 14 deletions imports/draw/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ local function MeasureStringWidth(str, font, scale)
AddTextComponentSubstringPlayerName(str)
SetTextFont(font or 0)
SetTextScale(1.0, scale or 0)
return EndTextCommandGetWidth(true) * supv.oncache.screen.x
return EndTextCommandGetWidth(true) * supv.oncache.screen[1]
end

local function AddText(str)
Expand All @@ -65,7 +65,7 @@ local function AddText(str)
end

local function GetLineCount(Text, X, Y, Font, Scale, Color, Alignment, DropShadow, Outline, WordWrap)
local Text, X, Y = tostring(Text), (tonumber(X) or 0) / supv.oncache.screen.x, (tonumber(Y) or 0) / supv.oncache.screen.y
local Text, X, Y = tostring(Text), (tonumber(X) or 0) / supv.oncache.screen[1], (tonumber(Y) or 0) / supv.oncache.screen[2]
SetTextFont(Font or 0)
SetTextScale(1.0, Scale or 0)
SetTextColour(tonumber(Color[1]) or 255, tonumber(Color[2]) or 255, tonumber(Color[3]) or 255, tonumber(Color[4]) or 255)
Expand All @@ -84,11 +84,11 @@ local function GetLineCount(Text, X, Y, Font, Scale, Color, Alignment, DropShado
end
if tonumber(WordWrap) and tonumber(WordWrap) ~= 0 then
if Alignment == 1 or Alignment == "Center" or Alignment == "Centre" then
SetTextWrap(X - ((WordWrap / supv.oncache.screen.x) / 2), X + ((WordWrap / supv.oncache.screen.y) / 2))
SetTextWrap(X - ((WordWrap / supv.oncache.screen[1]) / 2), X + ((WordWrap / supv.oncache.screen[2]) / 2))
elseif Alignment == 2 or Alignment == "Right" then
SetTextWrap(0, X)
else
SetTextWrap(X, X + (WordWrap / supv.oncache.screen.x))
SetTextWrap(X, X + (WordWrap / supv.oncache.screen[1]))
end
else
if Alignment == 2 or Alignment == "Right" then
Expand Down Expand Up @@ -126,10 +126,10 @@ local function Text3D(coords, text, data)
DrawText(_x,_y)
local factor = (string.len(text)) / 370
if color.rect1 then
DrawRect(_x,_y+0.0125, 0.015+ factor, 0.03, color.rect1[1], color.rect1[2], color.rect1[3], color.rect1[4])
DrawRect(_x,_y+0.0125, 0.015+ factor + (scale[1]/4), 0.03, color.rect1[1], color.rect1[2], color.rect1[3], color.rect1[4])
end
if color.rect2 then
DrawRect(_x,_y+0.0300, 0.015+ factor, 0.005, color.rect2[1], color.rect2[2], color.rect2[3], color.rect2[4])
DrawRect(_x,_y+0.0300, 0.015+ factor + (scale[1]/4), 0.005, color.rect2[1], color.rect2[2], color.rect2[3], color.rect2[4])
end
end

Expand All @@ -144,7 +144,7 @@ end
---@param color table {int, int, int, int}
---@param heading float 0.0
local function Sprite(TextureDictionary, TextureName, x, y, width, heigth, color, heading)--drawSprite(TextureDictionary, TextureName, x, y, w, h, heading, color)
local screenX, screenY = supv.oncache.screen.x, supv.oncache.screen.y
local screenX, screenY = supv.oncache.screen[1], supv.oncache.screen[2]
local x, y = (tonumber(x or 0) / tonumber(screenX)), (tonumber(y or 0) / tonumber(screenY))
local w, h = (tonumber(width or 0) / tonumber(screenX)), (tonumber(heigth or 0) / tonumber(screenY))

Expand All @@ -163,7 +163,7 @@ end
---@param h number
---@param color table
local function Rect(x, y, w, h, color)
local x, y, w, h = (tonumber(x) or 0) / supv.oncache.screen.x, (tonumber(y) or 0) / supv.oncache.screen.y, (tonumber(w) or 0) / supv.oncache.screen.x, (tonumber(h) or 0) / supv.oncache.screen.y
local x, y, w, h = (tonumber(x) or 0) / supv.oncache.screen[1], (tonumber(y) or 0) / supv.oncache.screen[2], (tonumber(w) or 0) / supv.oncache.screen[1], (tonumber(h) or 0) / supv.oncache.screen[2]
DrawRect(x + w * 0.5, y + h * 0.5, w, h, color[1] or 255, color[2] or 255, color[3] or 255, color[4] or 100)
end

Expand All @@ -180,7 +180,7 @@ end
---@param Outline boolean true or false or nil
---@param WordWrap nil|number int or nil
local function Text2D(Text, X, Y, Font, Scale, Color, Alignment, DropShadow, Outline, WordWrap)
local Text, X, Y = tostring(Text), (tonumber(X) or 0) / supv.oncache.screen.x, (tonumber(Y) or 0) / supv.oncache.screen.y
local Text, X, Y = tostring(Text), (tonumber(X) or 0) / supv.oncache.screen[1], (tonumber(Y) or 0) / supv.oncache.screen[2]
SetTextFont(Font or 0)
SetTextScale(1.0, Scale or 0)
SetTextColour(tonumber(Color[1]) or 255, tonumber(Color[2]) or 255, tonumber(Color[3]) or 255, tonumber(Color[4]) or 255)
Expand All @@ -199,11 +199,11 @@ local function Text2D(Text, X, Y, Font, Scale, Color, Alignment, DropShadow, Out
end
if tonumber(WordWrap) and tonumber(WordWrap) ~= 0 then
if Alignment == 1 or Alignment == "Center" or Alignment == "Centre" then
SetTextWrap(X - ((WordWrap / supv.oncache.screen.x) / 2), X + ((WordWrap / supv.oncache.screen.y) / 2))
SetTextWrap(X - ((WordWrap / supv.oncache.screen[1]) / 2), X + ((WordWrap / supv.oncache.screen[2]) / 2))
elseif Alignment == 2 or Alignment == "Right" then
SetTextWrap(0, X)
else
SetTextWrap(X, X + (WordWrap / supv.oncache.screen.x))
SetTextWrap(X, X + (WordWrap / supv.oncache.screen[1]))
end
else
if Alignment == 2 or Alignment == "Right" then
Expand Down Expand Up @@ -240,7 +240,7 @@ local function ProgressBar(text, time, setting, data, action)
progressbar.setting.timeCancel = setting.timeCancel or 0
progressbar.setting.animation = setting.animation or defaultProgressBar.animation
progressbar.setting.prop = setting.prop or defaultProgressBar.prop
progressbar.data.x = data.x or (supv.oncache.screen.x * 0.35)
progressbar.data.x = data.x or (supv.oncache.screen[1] * 0.35)
progressbar.data.y = data.y or defaultProgressBar.y
progressbar.data.w = data.w or defaultProgressBar.w
progressbar.data.h = data.h or defaultProgressBar.h
Expand Down Expand Up @@ -280,7 +280,7 @@ local function ProgressBar(text, time, setting, data, action)

if (progressbar.data.progressAnim == 'simple') then
local _y = progressbar.data.y
local _ymax = supv.oncache.screen.y + 100
local _ymax = supv.oncache.screen[2] + 100
while _y < _ymax do
Wait(0)

Expand Down Expand Up @@ -495,7 +495,7 @@ local function ProgressBar(text, time, setting, data, action)

CreateThread(function()
if progressbar.data.progressAnim == 'simple' then
local _y = supv.oncache.screen.y + 100
local _y = supv.oncache.screen[2] + 100
while _y > progressbar.data.y do
Wait(0)
if progressbar.data.progressType == 'sprite' then
Expand Down
179 changes: 179 additions & 0 deletions imports/laser/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
local SetTextScale <const> = SetTextScale
local SetTextFont <const> = SetTextFont
local SetTextProportional <const> = SetTextProportional
local SetTextColour <const> = SetTextColour
local SetTextEntry <const> = SetTextEntry
local SetTextCentre <const> = SetTextCentre
local AddTextComponentString <const> = AddTextComponentString
local SetDrawOrigin <const> = SetDrawOrigin
local DrawText <const> = DrawText
local DrawSprite <const> = DrawSprite
local DrawLine <const> = DrawLine
local ClearDrawOrigin <const> = ClearDrawOrigin
local GetEntityModel <const> = GetEntityModel
local GetModelDimensions <const> = GetModelDimensions
local GetEntityMatrix <const> = GetEntityMatrix
local GetGroundZFor_3dCoord <const> = GetGroundZFor_3dCoord
local GetGameplayCamRot <const> = GetGameplayCamRot
local GetGameplayCamCoord <const> = GetGameplayCamCoord
local GetShapeTestResult <const> = GetShapeTestResult
local StartShapeTestRay <const> = StartShapeTestRay
local math <const> = math
local string <const> = string


local function Draw3dText(coords, text, lines)
if not lines then lines = 1 end
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(coords.x, coords.y, coords.z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawSprite("commonmenu", "gradient_bgd", 0.0, 0.0+0.0125 * lines, 0.017+ factor, 0.03 * lines, 0.1, 0, 0, 0, 75)
ClearDrawOrigin()
end

local function DrawEntityBoundingBox(entity, color)
local model = GetEntityModel(entity)
local min, max = GetModelDimensions(model)
local rightVector, forwardVector, upVector, position = GetEntityMatrix(entity)
local dim = {
x = 0.5*(max.x - min.x),
y = 0.5*(max.y - min.y),
z = 0.5*(max.z - min.z)
}

local FUR = {
x = position.x + dim.y*rightVector.x + dim.x*forwardVector.x + dim.z*upVector.x,
y = position.y + dim.y*rightVector.y + dim.x*forwardVector.y + dim.z*upVector.y,
z = 0
}

local _, FUR_z = GetGroundZFor_3dCoord(FUR.x, FUR.y, 1000.0, 0)
FUR.z = FUR_z
FUR.z = FUR.z + 2 * dim.z

local BLL = {
x = position.x - dim.y*rightVector.x - dim.x*forwardVector.x - dim.z*upVector.x,
y = position.y - dim.y*rightVector.y - dim.x*forwardVector.y - dim.z*upVector.y,
z = 0
}

local _, BLL_z = GetGroundZFor_3dCoord(FUR.x, FUR.y, 1000.0, 0)
BLL.z = BLL_z
local edge1 = BLL
local edge5 = FUR

local edge2 = {
x = edge1.x + 2 * dim.y*rightVector.x,
y = edge1.y + 2 * dim.y*rightVector.y,
z = edge1.z + 2 * dim.y*rightVector.z
}

local edge3 = {
x = edge2.x + 2 * dim.z*upVector.x,
y = edge2.y + 2 * dim.z*upVector.y,
z = edge2.z + 2 * dim.z*upVector.z
}

local edge4 = {
x = edge1.x + 2 * dim.z*upVector.x,
y = edge1.y + 2 * dim.z*upVector.y,
z = edge1.z + 2 * dim.z*upVector.z
}

local edge6 = {
x = edge5.x - 2 * dim.y*rightVector.x,
y = edge5.y - 2 * dim.y*rightVector.y,
z = edge5.z - 2 * dim.y*rightVector.z
}

local edge7 = {
x = edge6.x - 2 * dim.z*upVector.x,
y = edge6.y - 2 * dim.z*upVector.y,
z = edge6.z - 2 * dim.z*upVector.z
}

local edge8 = {
x = edge5.x - 2 * dim.z*upVector.x,
y = edge5.y - 2 * dim.z*upVector.y,
z = edge5.z - 2 * dim.z*upVector.z
}

DrawLine(edge1.x, edge1.y, edge1.z, edge2.x, edge2.y, edge2.z, color.r, color.g, color.b, color.a)
DrawLine(edge1.x, edge1.y, edge1.z, edge4.x, edge4.y, edge4.z, color.r, color.g, color.b, color.a)
DrawLine(edge2.x, edge2.y, edge2.z, edge3.x, edge3.y, edge3.z, color.r, color.g, color.b, color.a)
DrawLine(edge3.x, edge3.y, edge3.z, edge4.x, edge4.y, edge4.z, color.r, color.g, color.b, color.a)
DrawLine(edge5.x, edge5.y, edge5.z, edge6.x, edge6.y, edge6.z, color.r, color.g, color.b, color.a)
DrawLine(edge5.x, edge5.y, edge5.z, edge8.x, edge8.y, edge8.z, color.r, color.g, color.b, color.a)
DrawLine(edge6.x, edge6.y, edge6.z, edge7.x, edge7.y, edge7.z, color.r, color.g, color.b, color.a)
DrawLine(edge7.x, edge7.y, edge7.z, edge8.x, edge8.y, edge8.z, color.r, color.g, color.b, color.a)
DrawLine(edge1.x, edge1.y, edge1.z, edge7.x, edge7.y, edge7.z, color.r, color.g, color.b, color.a)
DrawLine(edge2.x, edge2.y, edge2.z, edge8.x, edge8.y, edge8.z, color.r, color.g, color.b, color.a)
DrawLine(edge3.x, edge3.y, edge3.z, edge5.x, edge5.y, edge5.z, color.r, color.g, color.b, color.a)
DrawLine(edge4.x, edge4.y, edge4.z, edge6.x, edge6.y, edge6.z, color.r, color.g, color.b, color.a)
end

local function RotationToDirection(rotation)
local adjustedRotation = {
x = (math.pi / 180) * rotation.x,
y = (math.pi / 180) * rotation.y,
z = (math.pi / 180) * rotation.z
}
local direction = {
x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
z = math.sin(adjustedRotation.x)
}
return direction
end

local function RayCastCamera(distance)
local cameraRotation = GetGameplayCamRot()
local cameraCoord = GetGameplayCamCoord()
local direction = RotationToDirection(cameraRotation)
local destination = {
x = cameraCoord.x + direction.x * distance,
y = cameraCoord.y + direction.y * distance,
z = cameraCoord.z + direction.z * distance
}
local _, b, c, _, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, supv.oncache.pedid, 0))
return b, c, e
end

local GetEntityCoords <const> = GetEntityCoords
local IsEntityAPed <const> = IsEntityAPed
local IsEntityAnObject <const> = IsEntityAnObject
local IsEntityAVehicle <const> = IsEntityAVehicle
local DrawMarker <const> = DrawMarker
local IsControlJustReleased <const> = IsControlJustReleased
local vec3 <const> = vec3
local GetEntityArchetypeName <const> = GetEntityArchetypeName
local PlayerPedId <const> = PlayerPedId

local function Show(cb)
local color = {r = 255, g = 0, b = 0, a = 200}
local position = GetEntityCoords(PlayerPedId())
local hit, coords, entity = RayCastCamera(1000.0)
if hit and (IsEntityAVehicle(entity) or IsEntityAPed(entity) or IsEntityAnObject(entity)) then
local entityCoord = GetEntityCoords(entity)
DrawEntityBoundingBox(entity, color)
DrawLine(position.x, position.y, position.z, coords.x, coords.y, coords.z, color.r, color.g, color.b, color.a)
Draw3dText(vec3(entityCoord.x, entityCoord.y, entityCoord.z), ("model : %s | name : %s\nPress [~c~E~s~] to ~g~validate~s~ ~p~entity~s~"):format(GetEntityModel(entity), GetEntityArchetypeName(entity)), 2)
if IsControlJustReleased(0, 38) then
cb(entity, GetEntityModel(entity), GetEntityArchetypeName(entity))
end
elseif coords.x ~= 0.0 and coords.y ~= 0.0 then
DrawLine(position.x, position.y, position.z, coords.x, coords.y, coords.z, color.r, color.g, color.b, color.a)
DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.1, 0.1, 0.1, color.r, color.g, color.b, color.a, false, true, 2, nil, nil, false)
end
end

return {
show = Show
}
Loading

0 comments on commit e678327

Please sign in to comment.