Jump to content

[TUT] Meta.xml settings tutorial


Recommended Posts

Difficulty: Just above beginner.

Hello all, I thought about sharing a small tutorial. This tutorial will help you in adding settings in the meta.xml. All the values entered in the meta.xml are editable in the admin panel.

Settings are defined in the meta.xml, then the script can get the string from the meta.xml. To be able to get the data entered in the meta.xml, you must use get(), and optionally set().

Lets use one of my scripts as an example, this is my meta.xml file:

    "Chris" version="1.15" type="script" name="Basemode ID Tag" description="This adds the basemode ID tag before a players name." /> 
    

I have just shown you the base of settings. Now its all about reading the settings. Lets create a script which enables a certain feature of the script.

get() Syntax:

get(settingName) -- settingName is a string. 

local isMessageEnabled = get('enabledjoinmessage') -- Reads the setting added in the meta, in our case its “true”. 
local player = getPlayerName(thePlayer) -- Gets the player name and adds a variable to it! 
  
-- Adding the event handler! 
_get = get 
function get( str ) 
    if type( str ) == 'string' then 
        return _get( str ),str 
    end 
    return false 
end 
  
local isMessageEnabled,st = get( getResourceName( getThisResource( ) ).. '.enabledjoinmessage' ) -- Reads the setting added in the meta, in our case its true. 
--[[ 
Example 
  
]] 
  
-- Adding the event handler! 
addEventHandler( "onPlayerJoin",root, 
    function( ) 
        if tostring( isMessageEnabled ) == 'true' then -- check if 'enabledjoinmessage' is exits 
            outputChatBox( "Welcome "..getPlayerName( source ) -- Gets the player name and adds a variable to it! 
            .." to our server, please enjoy!",root,255,153,0 ) -- output in chat box 
        else -- if not exits 
            outputChatBox( "The setting ("..st..") is neither false or true! Correct it!",root,255,153,0 ) 
        end 
    end 
) 

Set() is not very different to get(). If you need to use set(). This would be the right syntax.

set("enabledjoinmessage","false") -- this will set enabledjoinmessage to false.  

This concludes my tutorial on using get() and set(). If you have any questions or feedback, feel free to reply! I am willing to help anyone. I'll be making more tutorials. If there is anything you believe I did not explain clearly, I am willing to fix it and clear it up.

Links which can be useful:

set()

get()

Settings help on the wiki

Your community scripter,

Chris Smith.

Edited by Guest
Link to comment
  • 2 weeks later...

thePlayer is nil in your code.

_get = get 
function get( str ) 
    if type( str ) == 'string' then 
        return _get( str ),str 
    end 
    return false 
end  
  
local isMessageEnabled,st = get( getResourceName( getThisResource( ) ).. '.enabledjoinmessage' ) -- Reads the setting added in the meta, in our case its true. 
--[[ 
Example 
 <setting name="#enabledjoinmessage" value="[ true ]" /> 
]] 
  
-- Adding the event handler! 
addEventHandler( "onPlayerJoin",root, 
    function( ) 
        if tostring( isMessageEnabled ) == 'true' then -- check if 'enabledjoinmessage' is exits 
            outputChatBox( "Welcome "..getPlayerName( source ) -- Gets the player name and adds a variable to it! 
            .." to our server, please enjoy!",root,255,153,0 ) -- output in chat box 
        else -- if not exits 
            outputChatBox( "The setting ("..st..") is neither false or true! Correct it!",root,255,153,0 ) 
        end 
    end  
) 

Link to comment

just edited it.

xpromise. I was getting the player name from out of the onResourceStart. So I guess your a bit blind. I also guess I'm a bit dumb xD. Well if you don't have anything nice to say at all don't say it. Thanks Kenix for telling me about this. You made me realize that the settings where changable and can clash with other resources.

I am working on a big script. Dont expect a noob gamemode. You should be expecting something similiar to freeroam, just more improved. I have currently finished 11 % in the past 3 days. Camping so i had limited access. No internet. Plus it was flooding here in Australia.

Bb xPromise. I hope you will think before you act next time. Good boy!

Link to comment
Better idea - cache all the settings as element data under the resource root element. Then, update the cache at time a setting changes in onSettingChange. This way, you can easily implement a clientside get() function.

Cool, someone that actually read my script... I wrote this not to show my skill, but only to explain the usage.

Link to comment
  • Recently Browsing   0 members

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