[Free][Libs]A simple scaleform menu

Github: nbk_scaleform_simplemenu
Preview Youtube
20220312011446

This is a simple menu script for some of my custom works.
Sometimes we just need a simple menu script without any much, a easy way to create menu, adding buttons and button-callbacks with a clean ui.
This is also an example script for show how to use [Free][Utility] nbk_scaleform_draw2d | Draw Rect,Sprite,Text,Circle with scaleform

Dependencies

[Free][Utility] nbk_scaleform_draw2d | Draw Rect,Sprite,Text,Circle with scaleform

Import or exports

load(LoadResourceFile("nbk_scaleform_simplemenu", 'import'))()
--[[
if not CreateSimpleMenuS then 
   CreateSimpleMenuS = function(...)
      return exports['nbk_scaleform_simplemenu']:CreateSimpleMenuS(...)
   end 
end 
--]]
CreateSimpleMenuS = function(...)
      return exports['nbk_scaleform_simplemenu']:CreateSimpleMenuS(...)
   end 

Example:

CreateThread(function() 
        load(LoadResourceFile("nbk_scaleform_simplemenu", 'import'))()
	local menu = CreateSimpleMenuS("namespace","test",{
         glare = true,
         title = "negbookglare",
         subtitle = "hello",
         maxslot = 6,
         buttons  = {
            {name="Spawn A Vehicle",description="hello",actions={"osiris","adder","turismor"}},
            {name="Suicide",description="Suicide",crossed = true},
            {name="Cat",description="hell312o",options={"$3000"},icon = 5},
            {name="Race",description="hell312o",disable = true,icon = 13},
            {name="Some Disabled",description="Disabled",disable = true},
            {name="Fruits",description="hell312o",options={"apple","banana","hamburger"}},
            {name="Close Menu",description="Close your menu"},
         }
      })
      
      menu:On('open',function(...)
         print("open!?",...)
      end)
      menu:On('select',function(currentdata,menu_)
         print("submit?",json.encode(currentdata))
         
      end)
      menu:On('back',function(currentdata,menu)
         print("cancel",json.encode(currentdata))
         menu.close()
      end)
      menu:On('change',function(currentdata,menu)
         
         --print("example,change",currentdata.slot,currentdata.data)
      end)
      menu:OpenWith("F1","Open the menu1")
      menu:OpenWithHolding("M",500,"Open the menu1")
      menu:OpenWithHolding("SELECT_INDEX",500,"Open the menu1 delay","PAD_DIGITALBUTTON")
      menu:Button(1,function(options,selected)
         local vehname = options[selected]
         local x,y,z = table.unpack(GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 8.0, 0.5))
         if vehname == nil then vehname = "adder" end
         vehiclehash = GetHashKey(vehname)
         RequestModel(vehiclehash)
         while not HasModelLoaded(vehiclehash)  do Wait(100) end 
         local veh = GetVehiclePedIsIn(PlayerPedId())
         local speed = GetEntitySpeed(PlayerPedId())
         if DoesEntityExist(veh) then 
            DeleteEntity(veh)
         end 
         local vehicle = CreateVehicle(vehiclehash, x, y, z, GetEntityHeading(PlayerPedId()), 1, 0)
         SetVehicleEngineOn(vehicle, true, true, false)
         SetVehicleForwardSpeed(vehicle, speed)
         SetPedIntoVehicle(PlayerPedId(), vehicle, -1);
      end)
      menu:Button(2,function() -- no options and no actions cb nothing 
         SetEntityHealth(PlayerPedId(),0)
      end)
      menu:Button(7,function(options,selected,menu)
         menu.close()
      end)
end)

7 Likes

it actually works! wow been looking hard to find something that could handle menu’s or even handle scaleforms.

great job!

now i just gotta find a way to adjust the position of the menu, it’s quite a lot off-screen :stuck_out_tongue:

( it only happens to be off screen in low screen resolutions, i didnt try a lot but it seems to like full-hd resolutions or anything near it when windowed 1920x1080 )

1 Like
client/draw.lua

line 122~130

Jup thats what i sought, thank you very much for the directions.

local basicx = 0.580
local basicy = 0.120

This puts it on the right for 800x600 windowed, for 1920x1080 it puts it right but more mid, it really depends on the res. i’ll try something with the resolutions on player join. but assuming the majority of the players will run 1920x1080 or higher wouldn’t this be much of a problem.

1 Like