Login to ZARP
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: LUA Help

LUA Help 4 years 11 months ago #1117632

In this spoiler is the LUA for the main menu's background, I want it to stop randomly picking which image comes up next as I have a gif for a background and it looks nasty when it's not smoothly changing frames.

Help please?

Warning: Spoiler! [ Click to expand ]



  • Nafe
  • Nafe's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Posts: 18585
  • Thanks received: 8582
  • Karma: -377
Last Edit: 4 years 11 months ago by Nafe.
The topic has been locked.

LUA Help 4 years 11 months ago #1117633

Try commenting out:
if ( tbl.DieTime <= 0 ) then
     ChangeBackground()
end

Line 20

Doubtful it will help with the choppy-ness considering ChangeBackground just returns if "img" is a nil-y value
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
Last Edit: 4 years 11 months ago by .uzi.
The topic has been locked.
The following user(s) said Thank You: Nafe

LUA Help 4 years 11 months ago #1117635

.uzi wrote:
Try commenting out:
if ( tbl.DieTime <= 0 ) then
     ChangeBackground()
end

Line 20

That's just stopped it from changing all together, closer than I got though still.
  • Nafe
  • Nafe's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Posts: 18585
  • Thanks received: 8582
  • Karma: -377
The topic has been locked.

LUA Help 4 years 11 months ago #1117636

Nafe wrote:
.uzi wrote:
Try commenting out:
if ( tbl.DieTime <= 0 ) then
     ChangeBackground()
end

Line 20

That's just stopped it from changing all together, closer than I got though still.
OH I'M STUPID I DIDN'T READ THIS RIGHT AT ALL
local img = table.Random( Images )
Is the culprit, you'd need to have the images placed in order in your array then you can just do
for i = 1, #Images do
    -- change background here
end
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
Last Edit: 4 years 11 months ago by .uzi.
The topic has been locked.
The following user(s) said Thank You: Nafe

LUA Help 4 years 11 months ago #1117637

I think it's something to do with line 94, i'm probably very wrong tbh.
  • Nafe
  • Nafe's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Posts: 18585
  • Thanks received: 8582
  • Karma: -377
The topic has been locked.

LUA Help 4 years 11 months ago #1117639

if(Lag)
  { dontLag(); }
  • Clarky
  • Clarky's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Gold Badge
  • I love Henny
  • Posts: 16702
  • Thanks received: 9536
  • Karma: 1000
The topic has been locked.
The following user(s) said Thank You: Nafe, Jim_Jam

LUA Help 4 years 11 months ago #1117640

Warning: Spoiler! [ Click to expand ]


Please be patient I'm stupid, try:
local MenuGradient = Material( "html/img/gradient.png", "nocull smooth" )

local Images = {}

local Active = nil
local Outgoing = nil
local ImageIndex = 1

local function Think( tbl )

	tbl.Angle = tbl.Angle + ( tbl.AngleVel * FrameTime() )
	tbl.Size = tbl.Size + ( ( tbl.SizeVel / tbl.Size) * FrameTime() )

	if ( tbl.AlphaVel ) then
		tbl.Alpha = tbl.Alpha - tbl.AlphaVel * FrameTime()
	end

	if ( tbl.DieTime > 0 ) then
		tbl.DieTime = tbl.DieTime - FrameTime()

		if ( tbl.DieTime <= 0 ) then
			ChangeBackground()

			if ImageIndex + 1 > #Images then
				ImageIngex = 1
			else
				ImageIndex = ImageIndex + 1
			end
			
		end
	end

end

local function Render( tbl )

	surface.SetMaterial( tbl.mat )
	surface.SetDrawColor( 255, 255, 255, tbl.Alpha )

	local w = ScrH() * tbl.Size * tbl.Ratio
	local h = ScrH() * tbl.Size

	local x = ScrW() * 0.5
	local y = ScrH() * 0.5

	surface.DrawTexturedRectRotated( x, y, w, h, tbl.Angle )

end

local function ShouldBackgroundUpdate()

	return !IsInGame() && !IsInLoading()

end

function DrawBackground()

	if ( ShouldBackgroundUpdate() ) then

		if ( Active ) then
			Think( Active )
			Render( Active )
		end 

		if ( Outgoing ) then

			Think( Outgoing )
			Render( Outgoing )

		end

	end

	surface.SetMaterial( MenuGradient )
	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.DrawTexturedRect( 0, 0, 0, ScrH() )

end

function ClearBackgroundImages( img )

	Images = {}

end

function AddBackgroundImage( img )

	table.insert( Images, img )

end

local LastGamemode = "none"

function ChangeBackground( currentgm )

	if ( !ShouldBackgroundUpdate() ) then return end -- Don't try to load new images while in-game or loading

	if ( currentgm && currentgm == LastGamemode ) then return end
	if ( currentgm ) then LastGamemode = currentgm end

	local img = Images[ImageIndex]

	if ( !img ) then return end

	-- Remove the texture from memory
	-- There's a bit of internal magic going on here
	--[[
	local DoUnload = Outgoing != nil

	if ( Outgoing && Outgoing.Name == img ) then
		DoUnload = false
	end

	if ( Outgoing && Active && Outgoing.Name == Active.Name ) then
		DoUnload = false
	end

	if ( DoUnload ) then
		Outgoing.mat:SetUndefined( "$basetexture" )
	end
	]]

	Outgoing = Active
	if ( Outgoing ) then
		Outgoing.AlphaVel = 0
	end

	local mat = Material( img, "nocull smooth" )
	if ( !mat || mat:IsError() ) then return end

	Active = {
		Ratio = mat:GetInt( "$realwidth" ) / mat:GetInt( "$realheight" ),
		Size = 1,
		Angle = 0,
		AngleVel = -( 0 / 30 ),
		SizeVel = ( 0 / 30 ),
		Alpha = 255,
		DieTime = 0.1,
		mat = mat,
		Name = img
	}

	if ( Active.Ratio < ScrW() / ScrH() ) then

		Active.Size = Active.Size + ( ( ScrW() / ScrH() ) - Active.Ratio )

	end

end
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
Last Edit: 4 years 11 months ago by .uzi.
The topic has been locked.
The following user(s) said Thank You: Nafe

LUA Help 4 years 11 months ago #1117641

Just make it work
  • Slapy47
  • Slapy47's Avatar
  • Offline
  • Gold Boarder
  • ZARP VIP
  • EX- DarkRP Admin - TTT Moderator - Teamspeak Staff
  • Posts: 2613
  • Thanks received: 479
  • Karma: 11
The topic has been locked.

LUA Help 4 years 11 months ago #1117642

Warning: Spoiler! [ Click to expand ]


Hasn't fixed much, also the gifs stop cycling after the last frame I think it is.

  • Nafe
  • Nafe's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Posts: 18585
  • Thanks received: 8582
  • Karma: -377
The topic has been locked.

LUA Help 4 years 11 months ago #1117643

Are these background images stills of the original gif?
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
The topic has been locked.

LUA Help 4 years 11 months ago #1117644

.uzi wrote:
Are these background images stills of the original gif?

Stills

  • Nafe
  • Nafe's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Posts: 18585
  • Thanks received: 8582
  • Karma: -377
The topic has been locked.

LUA Help 4 years 11 months ago #1117645

It's probably choppy because it's trying to change the background every frame IIRC that's when Think() is invoked while the original gif isn't tied to your game's framerate

Might need to apply a timer to the ChangeBackground call
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
Last Edit: 4 years 11 months ago by .uzi.
The topic has been locked.

LUA Help 4 years 11 months ago #1117647

Here's some professional advise from Clarky:

"just comment code out until it works, thats what I always do"
  • House
  • House's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP Gold Badge
  • The best thing on Earth? Coffee.
  • Posts: 1026
  • Thanks received: 541
  • Karma: 3

⚕ former TTT Server Owner ⚕
⚕ former Surf Administrator ⚕
⚕ former SSRP Moderator ⚕
⚕ former TeamSpeak3 staff ⚕
⚕ former Forum staff ⚕


Add me on Steam!


#uzi4CM
The topic has been locked.
The following user(s) said Thank You: Nafe, Clarky, Mr. Richard

LUA Help 4 years 11 months ago #1117648

Any help? Probs won't work in a Think() function

Warning: Spoiler! [ Click to expand ]
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
Last Edit: 4 years 11 months ago by .uzi.
The topic has been locked.

LUA Help 4 years 11 months ago #1117654

god wtf are you doing just make it a gif
  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
The topic has been locked.

LUA Help 4 years 11 months ago #1117656

DEADMONSTOR wrote:
god wtf are you doing just make it a gif
we're trying to re-invent the wheel here go away
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2441
  • Karma: 123
The topic has been locked.

LUA Help 4 years 11 months ago #1117657

.uzi wrote:
DEADMONSTOR wrote:
god wtf are you doing just make it a gif
we're trying to re-invent the wheel here go away

With bad code I think Xnator has that covered sorry.
  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
The topic has been locked.
The following user(s) said Thank You: .uzi

LUA Help 4 years 11 months ago #1117666

DEADMONSTOR wrote:
god wtf are you doing just make it a gif

Honestly I was thinking the same but where is the fun and challenge in that? :clap:
  • House
  • House's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP Gold Badge
  • The best thing on Earth? Coffee.
  • Posts: 1026
  • Thanks received: 541
  • Karma: 3

⚕ former TTT Server Owner ⚕
⚕ former Surf Administrator ⚕
⚕ former SSRP Moderator ⚕
⚕ former TeamSpeak3 staff ⚕
⚕ former Forum staff ⚕


Add me on Steam!


#uzi4CM
The topic has been locked.

LUA Help 4 years 11 months ago #1117667

Looks like smeg hack to me
  • A Good Pianist
  • A Good Pianist's Avatar
  • Offline
  • Spectacular Boarder
  • ZARP VIP Golden Blue Badge
  • A Wob A Bob Bob
  • Posts: 15000
  • Thanks received: 3914
  • Karma: 22
The topic has been locked.

LUA Help 4 years 11 months ago #1117673

dl.dropboxusercontent.com/s/8pmgiabr9gw0vyo/pdLHXfIXxS.mp4

Here:
C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\lua\menu

background.lua:
pastebin.com/raw/kAvmLz0w

mainmenu.lua:
pastebin.com/raw/iaMpYWH2

Cool command this will change all files within that folder with the file extension .gif to .jpg

ren *.gif *.jpg
  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
Last Edit: 4 years 11 months ago by DEADMONSTOR.
The topic has been locked.
  • Page:
  • 1
  • 2
Time to create page: 0.144 seconds

149 PLAYERS ONLINE

Connect to server View Gametracker DarkRP 1
8/127
online
Connect to server View Gametracker Deathrun
0/40
online
Connect to server View Gametracker TTT
0/47
online
Connect to server View Gametracker Bhop
0/32
online
Connect to server View Gametracker Surf
3/32
online
Connect to server View Gametracker Prop Hunt
0/42
online
Connect to server View Gametracker Sandbox
0/42
online
Connect to server Discord
138/790
online
Top