Okay, so in this tutorial you will learn how to export a function, in this side to show a GUI and set the label text using "exports"
let's start of with making the actual GUI part.
requirements: a brain and an image called "warning.png" placed in a folder called "files"
warning = guiCreateWindow(756,395,409,290,"Warning!",false)
guiSetAlpha(warning,1)
warningimage = guiCreateStaticImage(122,28,159,92,"files/warning.png",false,warning)
warninglabel = guiCreateLabel(17,145,377,89,"Warning msg",false,warning)
guiSetFont(warninglabel,"clear-normal")
warningButton = guiCreateButton(18,245,376,29,"Close",false,warning)
guiLabelSetHorizontalAlign(warninglabel,"center",false)
Now we got our GUI, we'll need to make the function which we will later export.
function warningWindow()
end
Okay, when we trigger the export, we will send a message right? So, we will need to retrieve the message by doing:
function warningWindow(message)
end
Sweet! Now let's make sure that the GUI is actually visible and show them a cursor when we trigger the function using the export.
function warningWindow(message)
guiSetVisible(warning, true)
showCursor(true)
end
And, of-course setting the label text to the message we will retrieve.
function warningWindow(message)
guiSetVisible(warning, true)
showCursor(true)
guiSetText(warninglabel, message)
end
Okay, now I think we're done with the function so let's add the event (because we will need to trigger it server sided if we make an export for server sided which we will!) and let's don't forget to disable the window when the players presses on the close button!
warning = guiCreateWindow(756,395,409,290,"Warning!",false)
guiSetAlpha(warning,1)
warningimage = guiCreateStaticImage(122,28,159,92,"files/warning.png",false,warning)
warninglabel = guiCreateLabel(17,145,377,89,"Warning msg",false,warning)
guiSetFont(warninglabel,"clear-normal")
warningButton = guiCreateButton(18,245,376,29,"Close",false,warning)
guiLabelSetHorizontalAlign(warninglabel,"center",false)
guiSetVisible(warning, false)
function warningWindow(message)
guiSetVisible(warning, true)
showCursor(true)
guiSetText(warninglabel, message)
end
addEvent("warningBox", true)
addEventHandler("warningBox", root, warningWindow)
function disableWarning()
guiSetVisible(warning, false)
showCursor(false)
end
addEventHandler("onClientGUIClick", warningButton, disableWarning)
And, voila! You now have the full client code above!
Now let's make the server-sided part!
Since it's server-sided we need to retrevie the player and what message, so we just do as we did earlier
function warningBoxServer(player, message)
end
And now we trigger the client event which we added with what player and what message.
function warningBoxServer(player, message)
triggerClientEvent(player, "warningBox", player, message)
end
Okay, now we're done with the lua part! Let's add those two functions to the meta!
<export function="warningBoxServer" type="server"/>
<export function="warningWindow" type="client"/>
And now we can use this!
--client:
exports.RESOURCENAME:warningBox("Your message!")
-- server:
exports.RESOURCENAME:warningBoxServer(player, "Your message!")
Enjoy, I tried to be so clear as I possibly could and hope you learnt something.