Jump to content

[TUT] exporting a function


ernst

Recommended Posts

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.

  • Like 2
Link to comment
  • 2 years later...

This tutorial could be a lot better. A lot of the stuff I don't understand because you're not putting the script names/type of scripts next side by side to the code. So it's not exactly clear to me.

Also, I don't know if I'm supposed to put the in the meta.xml of the source resource or in the meta.xml of the remote resource.

Link to comment
  • 2 months later...
Can someone explain me what that "false" means here:

W8ne80t.png

I really don't get it.

I know what does false or true here...:

function warningWindow(message) 
    guiSetVisible(warning, true) -- to make Gui visible 
    showCursor(true) -- to make cursor visible 
end 

For guiSetVisible, the false is to show that the GUI is not showing. if you set that to true, it will show

For guiCreateButton, the false is show relative co-ordinates. So if it was true, then the numbers will look like 0.84, 0.11, 0.23, 0.12 (examples). If it was false, like it is, then the co-ordinates look like what they look like at the moment.

You can find all these details on the wiki. Just look at all the arguments.

Here is a list of the functions you are asking about:

https://wiki.multitheftauto.com/wiki/GuiCreateButton

https://wiki.multitheftauto.com/wiki/GuiSetVisible

https://wiki.multitheftauto.com/wiki/GuiCreateLabel

https://wiki.multitheftauto.com/wiki/Gu ... taticImage

https://wiki.multitheftauto.com/wiki/GuiCreateWindow

https://wiki.multitheftauto.com/wiki/Gu ... ontalAlign

Link to comment
  • 2 years later...
On 03.08.2012 at 02:07, ernst said:

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.

Thanks for post.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...