• How to make a command for edit a script by the game?
    11 replies, posted
Hello. Excuse me for any grammatical errors. I would like to make a system for edit some options of my script by the game. For example: "!language eng", "The language has been changed in English". How can I make it? Thank You!
You can write/read to/from files in the garrysmod/data directory.
Use the PlayerSay hook for chat commands
[QUOTE=AJ10017;49500129]Use the PlayerSay hook for chat commands[/QUOTE] Why did you tag my reply dumb? Presumably the users don't want to type !language eng every time the map changes.
[QUOTE=RealDope;49500206]Why did you tag my reply dumb? Presumably the users don't want to type !language eng every time the map changes.[/QUOTE] then you save their choice of language after they've written !language eng the first time.
[QUOTE=Busan1;49501127]then you save their choice of language after they've written !language eng the first time.[/QUOTE] Save it where?
[QUOTE=RealDope;49501300]Save it where?[/QUOTE] "You can write/read from the [B]data[/B] folder" - Theres your answer already, and look, you even answered it yourself! :O
[QUOTE=RealDope;49500206]Why did you tag my reply dumb? Presumably the users don't want to type !language eng every time the map changes.[/QUOTE] I'd assume that you were tagged dumb not because you're wrong, but because your post misses the point, it doesn't actually really help OP with anything. And I'd assume using PData would be better for this since it's just one string. Or even a client cvar since it saves between servers, which wouldn't require a chat command at all. OP what you want to do is have a table like this: [lua]local error = { english = "You made a mistake.", pirate = "Yarrrrrr!!" }[/lua] have a chat command, I couldn't be bothered writing one out so here's the first example of a command i could find by google. Use this to switch between languages and ply:SetPData("current_language","eng") to save a language to a player. [lua] function chatCommand( ply, text, public ) if (string.sub(text, 1, 4) == "/die") then --if the first 4 letters are /die, kill him ply:Kill() return(false) --Hides the "/die" from chat end end hook.Add( "PlayerSay", "chatCommand", chatCommand ); [/lua] then you could do [lua] ply:PrintMessage(HUD_PRINTTALK,ply:error[ply:GetPData("current_language", "eng")]) -- second argument of GetPData is the default value if this pdata isn't set, currently set to english. [/lua] result: "You made a mistake."
[QUOTE=whitestar;49501333]"You can write/read from the [B]data[/B] folder" - Theres your answer already, and look, you even answered it yourself! :O[/QUOTE] Maybe it was a tad too subtle for you, but the question was rhetorical to make my point. [QUOTE=Splerge;49502467]I'd assume that you were tagged dumb not because you're wrong, but because your post misses the point, it doesn't actually really help OP with anything. And I'd assume using PData would be better for this since it's just one string. Or even a client cvar since it saves between servers, which wouldn't require a chat command at all. OP what you want to do is have a table like this: [lua]local error = { english = "You made a mistake.", pirate = "Yarrrrrr!!" }[/lua] have a chat command, I couldn't be bothered writing one out so here's the first example of a command i could find by google. Use this to switch between languages and ply:SetPData("current_language","eng") to save a language to a player. [lua] function chatCommand( ply, text, public ) if (string.sub(text, 1, 4) == "/die") then --if the first 4 letters are /die, kill him ply:Kill() return(false) --Hides the "/die" from chat end end hook.Add( "PlayerSay", "chatCommand", chatCommand ); [/lua] then you could do [lua] ply:PrintMessage(HUD_PRINTTALK,ply:error[ply:GetPData("current_language", "eng")]) -- second argument of GetPData is the default value if this pdata isn't set, currently set to english. [/lua] result: "You made a mistake."[/QUOTE] I thought the command was for admins to change the language for the whole server. Still not convinced that wasn't what he was asking for. I interpreted this as him asking for help saving config, not actually making the command. Maybe I was wrong.
[QUOTE=Splerge;49502467]-snip-[/QUOTE] PData(SQLlite) can bug out, and result in a full database reset, I still would suggest using the data folder and writing the language file there/saving the player options there, optinally the OP also could make an menu so the player can write an "local" language file to their data file in the data folder. So regarding to your post, you "cant" rate me dumb since it actually helps the OP, aka telling him where to look for, lol.
[QUOTE=RealDope;49502988] I thought the command was for admins to change the language for the whole server. Still not convinced that wasn't what he was asking for. I interpreted this as him asking for help saving config, not actually making the command. Maybe I was wrong.[/QUOTE] Yeah the language barrier is rough here, let me find that alternate language thread: [url]https://facepunch.com/showthread.php?t=1460926&highlight=language[/url]
Im Sorry, I haven't make my question correctly. I want I can edit some options by the game and automatically save it. For example: " !lang english "; " your language has been saved ". When I re enter in the server, I haven't to re write my language because it has been saved permanently. Excuse me for any grammatical errors. [editline]11th January 2016[/editline] The language is only an example, for understand how can I do this.
Sorry, you need to Log In to post a reply to this thread.