During the last weeks alot of players asked me to explain how starfall screens work. To help those people who want to learn Starfall i wrote a little turorial.
The button functions are made by LocInt. You have to download the button lib in my shared folder. Also the tutorial code is availible in my shared folder.
--@name Example
--@author SuperPlayer
--@requirecl lib/button.txt
--@sharedscreen
--@updater STEAM_0:0:74694146
--Button functions by LocInt. Thank you so much for this
if SERVER then
local String = "What ever you want"
function sendToClient()--Send stuff to client/Yes i know strings are slow but for learning its the easiest.
net.start()
net.writeString(String)
net.broadcast()
end
timer.create("Timer1",2,1,sendToClient)--Send our String to the CLIENT after 1 second and do this just 1 time
else--The CLIENT enviorment
local Value = ""
resetButtons()--Reset our buttons at the beginning
function receiveServerMessage()--Receive our Message
Value = net.readString()--Set the Value to the string
end
trebuchet18 = render.createFont("Trebuchet", 18)--This our Text font, Size = 18
trebuchet25 = render.createFont("Trebuchet", 25)--This our Text font, Size = 25
function drawCRect(x,y,w,h)--Makes that you can draw like in e2/EGP
render.drawRect(x-w/2,y-h/2,w,h)
end
function Use(Ply)--if we press use call this function defined in the hook
if Ply == nil then return end--Is the player not there stop
local X, Y = render.cursorPos(Ply)--The coordinates where you press use
for i, v in pairs(buttons) do--check all buttons
if v:pressed(X,Y) then
if i == "Button" then--is the button called "Button" ?
print("You pressed the button")
end--if you want to add more button add them with elseif i == "NAME" then
end
end
end
function renderScreen()--A normal screen has a resolution of 512x512 so the position values are from 0-512
render.setColor(90,90,90,255)--Color
drawCRect(256,256,512,512)--Draw a rect in the middle as a background
render.setColor(0,150,150,255)--Color
render.drawFilledCircle( 256,100, 50, 50 )--This is a circle
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet18,256,100,"This is Text!",1)--Our Text (0 = left bound, 1 = center, 2 = right bound) here we want it to center at 256,200
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet18,256,200,"Value = "..Value,1)--You can alse draw Values. Here we set the Text the value we send from server to client
ButtonDraw()--You can also draw functions in functions. Usefull if you want to have multiple tabs. Here we just draw a button!
end
function ButtonDraw()
render.setColor(255,0,0,255)--Color
drawCRect(256,350,150,50)--Our visual button
addButton("Button",256,350,150,50)--Made by LocInt, Basicly adds a button with a name at x,y with size w,h in our case it the position and size from the line before
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet25,256,340,"BUTTON",1)--Our Text
end
hook("render","Render",renderScreen)--This is needed to draw
hook( "starfall_used", "Screen Used", Use )--Call the function Use if we press use
hook( "net", "netSCREEN", receiveServerMessage)--Recieve Net messages from the server side
end
If you have any questions just ask.
I hope this little example helps you.
If you want more tutorials on screens or explanaitions for fuctions just ask me. BUT I will NOT do the work for you. That would be pointless
SuperPlayer
--@name Example
--@author SuperPlayer
--@requirecl lib/button.txt
--@sharedscreen
--@updater STEAM_0:0:74694146
--Button functions by LocInt. Thank you so much for this
if SERVER then
local String = "What ever you want"
function sendToClient()--Send stuff to client/Yes i know strings are slow but for learning its the easiest, You can also send tables
net.start()
net.writeString(String)
net.broadcast()
end
timer.create("Timer1",2,1,sendToClient)--Send our String to the CLIENT after 1 second and do this just 1 time
else--The CLIENT enviorment
local Value = ""
resetButtons()--Reset our buttons at the beginning
function receiveServerMessage()--Receive our Message
Value = net.readString()--Set the Value to the string
end
trebuchet18 = render.createFont("Trebuchet", 18)--This our Text font, Size = 18
trebuchet25 = render.createFont("Trebuchet", 25)--This our Text font, Size = 25
function drawCRect(x,y,w,h)--Makes that you can draw like in e2/EGP
render.drawRect(x-w/2,y-h/2,w,h)
end
function drawCTexRect(x,y,w,h)--Makes that you can draw like in e2/EGP
render.drawTexturedRect(x-w/2,y-h/2,w,h)
end
function Use(Ply)--if we press use call this function defined in the hook
if Ply == nil then return end--Is the player not there stop
local X, Y = render.cursorPos(Ply)--The coordinates where you press use
for i, v in pairs(buttons) do--check all buttons
if v:pressed(X,Y) then
if i == "Button" then--is the button called "Button" ?
print("You pressed the button")
A = 1
end--if you want to add more button add them with elseif i == "NAME" then
end
end
end
function renderScreen()--A normal screen has a resolution of 512x512 so the position values are from 0-512
render.setColor(90,90,90,255)--Color
drawCRect(256,256,512,512)--Draw a rect in the middle as a background
render.setColor(0,150,150,255)--Color
render.drawFilledCircle( 256,100, 50, 50 )--This is a circle
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet18,256,100,"This is Text!",1)--Our Text (0 = left bound, 1 = center, 2 = right bound) here we want it to center at 256,200
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet18,256,200,"Value = "..Value,1)--You can alse draw Values. Here we set the Text the value we send from server to client
ButtonDraw()--You can also draw functions in functions. Usefull if you want to have multiple tabs. Here we just draw a button!
end
function ButtonDraw()
local tex1 = render.getTextureID("james/teltac/gold")
render.setTexture(tex1)
render.setColor(255,0,0,255)--Color
drawCTexRect(256,350,150,50)--Our visual button
addButton("Button",256,350,150,50)--Made by LocInt, Basicly adds a button with a name at x,y with size w,h in our case it the position and size from the line before
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet25,256,340,"BUTTON",1)--Our Text
end
if A == 1 then
render.clear()
render.drawCircle(256,256,50,50)
end
hook("render","Render",renderScreen)--This is needed to draw
hook( "starfall_used", "Screen Used", Use )--Call the function Use if we press use
hook( "net", "netSCREEN", receiveServerMessage)--Recieve Net messages from the server side
end
--@name Example
--@author SuperPlayer
--@requirecl lib/button.txt
--@sharedscreen
--@updater STEAM_0:0:74694146
--Button functions by LocInt. Thank you so much for this
if SERVER then
local String = "What ever you want"
function sendToClient()--Send stuff to client/Yes i know strings are slow but for learning its the easiest, You can also send tables
net.start()
net.writeString(String)
net.broadcast()
end
timer.create("Timer1",2,1,sendToClient)--Send our String to the CLIENT after 1 second and do this just 1 time
else--The CLIENT enviorment
local Value = ""
resetButtons()--Reset our buttons at the beginning
function receiveServerMessage()--Receive our Message
Value = net.readString()--Set the Value to the string
end
trebuchet18 = render.createFont("Trebuchet", 18)--This our Text font, Size = 18
trebuchet25 = render.createFont("Trebuchet", 25)--This our Text font, Size = 25
function drawCRect(x,y,w,h)--Makes that you can draw like in e2/EGP
render.drawRect(x-w/2,y-h/2,w,h)
end
function drawCTexRect(x,y,w,h)--Makes that you can draw like in e2/EGP
render.drawTexturedRect(x-w/2,y-h/2,w,h)
end
function Use(Ply)--if we press use call this function defined in the hook
if Ply == nil then return end--Is the player not there stop
local X, Y = render.cursorPos(Ply)--The coordinates where you press use
for i, v in pairs(buttons) do--check all buttons
if v:pressed(X,Y) then
if i == "Button" then--is the button called "Button" ?
print("You pressed the button")
A = 1
end--if you want to add more button add them with elseif i == "NAME" then
end
end
end
function renderScreen()--A normal screen has a resolution of 512x512 so the position values are from 0-512
render.setColor(90,90,90,255)--Color
drawCRect(256,256,512,512)--Draw a rect in the middle as a background
render.setColor(0,150,150,255)--Color
render.drawFilledCircle( 256,100, 50, 50 )--This is a circle
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet18,256,100,"This is Text!",1)--Our Text (0 = left bound, 1 = center, 2 = right bound) here we want it to center at 256,200
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet18,256,200,"Value = "..Value,1)--You can alse draw Values. Here we set the Text the value we send from server to client
ButtonDraw()--You can also draw functions in functions. Usefull if you want to have multiple tabs. Here we just draw a button!
end
function ButtonDraw()
local tex1 = render.getTextureID("james/teltac/gold")
render.setTexture(tex1)
render.setColor(255,0,0,255)--Color
drawCTexRect(256,350,150,50)--Our visual button
addButton("Button",256,350,150,50)--Made by LocInt, Basicly adds a button with a name at x,y with size w,h in our case it the position and size from the line before
render.setColor(255,255,255,255)--Color
render.drawText( trebuchet25,256,340,"BUTTON",1)--Our Text
end
if A == 1 then
render.clear()
render.drawCircle(256,256,50,50)
end
hook("render","Render",renderScreen)--This is needed to draw
hook( "starfall_used", "Screen Used", Use )--Call the function Use if we press use
hook( "net", "netSCREEN", receiveServerMessage)--Recieve Net messages from the server side
end
I am just assuming you need help with that. The problem is that you are not having the render.clear() stuff in the render function. Something you need/want to draw ALWAYS need to be in the render function defined in the hook. So move the