Garry's Mod

Garry's Mod

View Stats:
glua questions.
i was wondering how to do these things, it would expand my possibilitys for glua a lot.

1: How do i store a number in a string and then be able to change and extract that value?

2: What is the proper glua folder structure (what should go in autorun, what should not, etc.)

3: How do i make something like chat or console commands, what im wondering is how do i make something like !kill (username) and it kills the target, i cant figure out how to tell the script that whatever they enter is htis script, and then kill whatever is in the string.

tanks!
Last edited by Grandpa Gropes-A-Lot; Aug 15, 2016 @ 6:42pm
< >
Showing 1-15 of 51 comments
Tanks
Originally posted by Eisotopius❤可愛い:
Tanks
oooooold scooby doo refrence
Oh boy, don't ask questions like this here. Especially when you can research them and that's what your supposed to do first. If you must, hire a teacher since learning that will take a lot longer than a simple post. Or ask the facepunch website, and or other GMod deving communties. I doubt anyone can help you here with GLua unless a mod has time to answer this or maybe another coder.
Zak Aug 16, 2016 @ 4:47am 
1. Local number = 666 print(number)
2. To begin with just myaddon/lua/autorun and throw your Lua files in there
3. Console commands - https://wiki.garrysmod.com/page/concommand/Add
Chat commands - https://wiki.garrysmod.com/page/GM/PlayerSay

Checkout Code Blue on YouTube as he covers the basics well
https://www.youtube.com/channel/UCFpuE-Qjn4EWqX-VJ_l7pbw
Originally posted by Hackcraft:
1. Local number = 666 print(number)
2. To begin with just myaddon/lua/autorun and throw your Lua files in there
3. Console commands - https://wiki.garrysmod.com/page/concommand/Add
Chat commands - https://wiki.garrysmod.com/page/GM/PlayerSay

Checkout Code Blue on YouTube as he covers the basics well
https://www.youtube.com/channel/UCFpuE-Qjn4EWqX-VJ_l7pbw

1: aliright good, but how do i change that number, like SetValue or something
2: I tried putting them in there, but nothing has worked from it. i tried putting one funtion script in there that prints your ip in the server console when you respawn, but i cant get it to work. tried /lua, tried /lua/autorun and tried /lua/autorun/server
3:Ive seen the chat command in code blues tutorials and on the wiki, but how can i make a command that targets a player. i tried extracting ulx to look for chat commands code, but i couldnt find it
4: i actuly learned glua in one night while working on a map from that guy, he does make amazing tutorials.

i tried to make one in console too, but what im wondering is how do i tell the game that !kill (string) means kill whatever they typed in the string

i do appreciate the help though!
Last edited by Grandpa Gropes-A-Lot; Aug 16, 2016 @ 11:25am
now that i go balls deep into thinking, can i do this?
hook.Add( "PlayerSay", "Killurself", function( ply, text, public ) text = string.lower( text ) -- Make the chat message entirely lowercase if ( text == "!kill" ( ply ) ) then ply:Kill() return "" end end )

i dont think this would work. sounded better in my head, but maybe
Last edited by Grandpa Gropes-A-Lot; Aug 16, 2016 @ 11:30am
Zak Aug 16, 2016 @ 4:19pm 
hook.Add( "PlayerSay", "Killurself", function( ply, text, public ) text = string.lower( text ) -- Make the chat message entirely lowercase if ( text == "!kill" ) then ply:Kill() return "" end end )

-- It's really not hard to scroll down in the wiki to see examples like the one below.
concommand.Add( "killyourself", function( ply, cmd, args ) ply:Kill() print( "You killed yourself!" ) end )
concommand.Add( "retrieveplayers", function() for _, ply in ipairs( player.GetAll() ) do print( ply:Nick() .. ", " .. ply:SteamID() .. "\n" ) end end )
Last edited by Zak; Aug 16, 2016 @ 4:19pm
what im looking to do is to be able to target a player, like i said this would open up a lot for me, i already asked this and the guy said to use the ulx base. i couldnt find the commands, nor is it meant to be a base, from what i can see
Zak Aug 16, 2016 @ 4:32pm 
Target which player?
The calling player? If so I already showed you how to do that in my above post.
Originally posted by Hackcraft:
Target which player?
The calling player? If so I already showed you how to do that in my above post.
not the player who ran the command, the one the command specifies, like !kill (username). i want it to kill the person you put after !kill
Zak Aug 17, 2016 @ 11:49am 
Untested but something like this should work.
hook.Add( "PlayerSay", "Killurself", function( ply, text, public ) text = string.lower( text ) -- Lowercase if string.Left(text,5) == "!kill" then -- if !kill local name = string.lower(string.Right( text, #text-5 )) -- Lowercase if name == nil then return "" ply:ChatPrint("Please enter a name: !kill (name)") end -- Check they entered a name for k, v in ipairs(player.GetAll()) do -- Loop through each player if string.find(string.lower(v:Nick()), name, 1, true) then -- if what you typed is in their name v:Kill() -- Kill them ply:ChatPrint("Killed " .. v:Nick()) end end return "" -- don't return the command to chat. end end )
Last edited by Zak; Aug 17, 2016 @ 11:54am
Originally posted by Hackcraft:
Untested but something like this should work.
hook.Add( "PlayerSay", "Killurself", function( ply, text, public ) text = string.lower( text ) -- Lowercase if string.Left(text,5) == "!kill" then -- if !kill local name = string.lower(string.Right( text, #text-5 )) -- Lowercase if name == nil then return "" ply:ChatPrint("Please enter a name: !kill (name)") end -- Check they entered a name for k, v in ipairs(player.GetAll()) do -- Loop through each player if string.find(string.lower(v:Nick()), name, 1, true) then -- if what you typed is in their name v:Kill() -- Kill them ply:ChatPrint("Killed " .. v:Nick()) end end return "" -- don't return the command to chat. end end )
ill go test it now, thank you! ill add you as a creator if i can get this to work

EDIT:


[ERROR] lua/uwot.lua:5: 'end' expected near 'ply'

ill fix that

another edit

few more errors, ez fix

this one is odd, [ERROR] lua/uwot.lua:14: ')' expected (to close '(' at line 1) near 'end'

but line one has no end. maybe its refrencing the end to close line 1?
Last edited by Grandpa Gropes-A-Lot; Aug 17, 2016 @ 12:30pm
Zak Aug 17, 2016 @ 12:30pm 
Oh sorry, I put the return in the wrong place on line 5!
hook.Add( "PlayerSay", "Killurself", function( ply, text, public ) text = string.lower( text ) -- Lowercase if string.Left(text,5) == "!kill" then -- if !kill local name = string.lower(string.Right( text, #text-5 )) -- Lowercase if name == nil then ply:ChatPrint("Please enter a name: !kill (name)") return "" end -- Check they entered a name for k, v in ipairs(player.GetAll()) do -- Loop through each player if string.find(string.lower(v:Nick()), name, 1, true) then -- if what you typed is in their name v:Kill() -- Kill them ply:ChatPrint("Killed " .. v:Nick()) end end return "" -- don't return the command to chat. end end )
Originally posted by Hackcraft:
Oh sorry, I put the return in the wrong place on line 5!
hook.Add( "PlayerSay", "Killurself", function( ply, text, public ) text = string.lower( text ) -- Lowercase if string.Left(text,5) == "!kill" then -- if !kill local name = string.lower(string.Right( text, #text-5 )) -- Lowercase if name == nil then ply:ChatPrint("Please enter a name: !kill (name)") return "" end -- Check they entered a name for k, v in ipairs(player.GetAll()) do -- Loop through each player if string.find(string.lower(v:Nick()), name, 1, true) then -- if what you typed is in their name v:Kill() -- Kill them ply:ChatPrint("Killed " .. v:Nick()) end end return "" -- don't return the command to chat. end end )
its not killing me (singleplayer) it does hide it from chat, but nothing is said if i dont enter a name.
< >
Showing 1-15 of 51 comments
Per page: 1530 50

Date Posted: Aug 15, 2016 @ 5:56pm
Posts: 51