codeluaeveryday Posted January 18, 2012 Share Posted January 18, 2012 (edited) 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 January 28, 2012 by Guest Link to comment
Kenix Posted January 27, 2012 Share Posted January 27, 2012 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
BriGhtx3 Posted January 28, 2012 Share Posted January 28, 2012 Lol that code is totally messed. onResourceStart has nothing to do with the player. Link to comment
codeluaeveryday Posted January 28, 2012 Author Share Posted January 28, 2012 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 . 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
BriGhtx3 Posted January 28, 2012 Share Posted January 28, 2012 I just said that it is wrong. You cant get the player name from onResourceStart. And this is totally right, so I cant be blind or what you want to call me. Link to comment
codeluaeveryday Posted January 28, 2012 Author Share Posted January 28, 2012 what you want to call me. Learn english lol! Link to comment
BriGhtx3 Posted January 28, 2012 Share Posted January 28, 2012 This is not a flame war And Im not American, Australian,... so dont expect that everyone speaks english without mistakes. But you are australian, so you should know what i meant Link to comment
AGENT_STEELMEAT Posted January 29, 2012 Share Posted January 29, 2012 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. Link to comment
codeluaeveryday Posted January 29, 2012 Author Share Posted January 29, 2012 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
FatalTerror Posted January 29, 2012 Share Posted January 29, 2012 Please, explain me why you use that: local isMessageEnabled,st = get( getResourceName( getThisResource( ) ).. '.enabledjoinmessage' ) I don't understand why you must the name of the resource Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 https://wiki.multitheftauto.com/wiki/Set ... ting_names We get setting current resource. 1 Link to comment
Recommended Posts