• How do you ignite a player
    18 replies, posted
Hello, I got a quick question. How would you go about igniting a player from a list. I'm trying to make a simple admin mod with commands like Ignite Slay kick ban. This is what I have so far. [LUA] -- DComboBox local list = vgui.Create( "DComboBox" ) list:SetParent(menu ) list:SetSize( 100, 200) list:SetPos( 15, 100 ) list:SetMultiple( false ) for k, v in pairs(player.GetAll() ) do list:AddItem( v:Nick() ) -- Ignite Command local ignite = vgui.Create("DButton") ignite:SetSize( 150, 25 ) ignite:SetPos( 10, 100 ) ignite:SetText("Ignite") ignite:SetParent( commandspanel ) ignite:DoClick = function( ) -- Line 153 for k, v in pairs(palyer.GetAll() ) do if v:list:GetSelectedItems()[1]:GetValue() then -- If the player is selected from the DComboBox then Ignite them v:Ignite( 1, 50 ) end end end -- This is the Error Im getting [RunString:153] function arguments expected near '=' [/LUA] I got GetSelectedItems()[1]:GetValue() from the wiki so I think thats how you get the player. Any help would be appreciated.
Here's what's wrong with your code: 1. For loop on line 7: you never gave it an "end". 2. You're getting the syntax wrong. In Lua, you either define the function like [lua]-- this function ignite:DoClick() end -- or this ignite.DoClick = function() end[/lua] 3. Line 17, it's "player" not "palyer". 4. Line 18, it's not "v:list", it's just "list". 5. Also on Line 18, you'll want to compare the value you got to v:Nick(). As it is, you're just checking to see if it exists or not (which it will). 6. You can't ignite people from the client (line 19). Instead, you'll need to use a concommand of some sorts (i.e. "ignite_player [name]").
[QUOTE=Entoros;27623497]Here's what's wrong with your code: 1. For loop on line 7: you never gave it an "end". 2. You're getting the syntax wrong. In Lua, you either define the function like [lua]-- this function ignite:DoClick() end -- or this ignite.DoClick = function() end[/lua] 3. Line 17, it's "player" not "palyer". 4. Line 18, it's not "v:list", it's just "list". 5. Also on Line 18, you'll want to compare the value you got to v:Nick(). As it is, you're just checking to see if it exists or not (which it will). 6. You can't ignite people from the client (line 19). Instead, you'll need to use a concommand of some sorts (i.e. "ignite_player [name]").[/QUOTE] Okay thanks for the help. But I've got a new problem. I've made a Igniting command but whenever I type Ignite Bot01 in console it ingites me instead. [LUA] function IgniteThem( ply, cmd, args ) if ( args[1] ) then ply:Ignite( 10, 1 ) end end concommand.Add("Ignite", IgniteThem) [/LUA]
ply is who called the command, you called the command so you get ignited, change it to something like [lua]args[1]:Ignite (10,1)[/lua] Though if you mistype their name it'll throw up an error so you may want to write some code to catch an error, maybe something like(not tested) [lua] function IgniteThem( ply, cmd, args ) if ( args[1] ) then if (args[1]:IsPlayer()) then args[1]:Ignite( 10, 1 ) else print ("Player not found!") end end end concommand.Add("Ignite", IgniteThem) [/lua]
You could use a FindPlayer function, like this, which would allow you type partial names: [lua] function FindPlayer(info) local pls = player.GetAll() for k, v in pairs(pls) do if string.find(string.lower(v:Name()), string.lower(tostring(info)), 1, true) ~= nil then return v end end return nil end function IgniteThem( ply, cmd, args ) if ( args[1] ) then local target = FindPlayer(args[1]) if target != nil then target:Ignite( 10, 1 ) else print ("Player not found!") end else print("Invalid arguments") end end concommand.Add("Ignite", IgniteThem) [/lua]
I see, Thanks for the help both of you!
If I may ask something here: How can you make ConCommands admin only, because otherwise if I used soemthing like this and then other players in the server found the command, they would randomly ignite each other, whereas I want only admins to be able to see and use it
[QUOTE=xomaxhox;27629673]If I may ask something here: How can you make ConCommands admin only, because otherwise if I used soemthing like this and then other players in the server found the command, they would randomly ignite each other, whereas I want only admins to be able to see and use it[/QUOTE] [lua] concommand.Add("admin_only",function(ply,cmd,args) if !ply:IsAdmin() then return end --do stuff end) [/lua]
Could I do: [lua]function Bob() --Blah blah end function Jim() --Blah blah end function ConCommands(ply,cmd,args) if !plyIsAdmin() then return end concommand.Add("bob", Bob) concommand.Add("jim", Jim) end end[/lua]
[QUOTE=xomaxhox;27630736]Could I do: [lua]function Bob() --Blah blah end function Jim() --Blah blah end function ConCommands(ply,cmd,args) if !plyIsAdmin() then return end concommand.Add("bob", Bob) concommand.Add("jim", Jim) end end[/lua][/QUOTE] Think about what that code would do. Let's take a look at your ConCommands function. [lua]function ConCommands(ply,cmd,args) if !plyIsAdmin() then return end concommand.Add("bob", Bob) concommand.Add("jim", Jim) end end[/lua] You have one 'end' too much, because your if closure is already ended with an end at line 2. Let's see what this function does... when a player who is an admin calls this function, two new console commands are added. So, as soon as an admin has made the server add those console commands, all people will be able to run 'jim' and 'bob' in their console. Is that what you want?
[QUOTE=Overv;27632333]Is that what you want?[/QUOTE] 1. Sorry about that extra end, I wasn't really paying attention at the time and I just quickly made a code that seemed as if it would work at the time, but after looking into it and you explaining what I did it obviously won't 2. I was just trying to make another version of Ralle's code in which I could first specify the function, and then link it to a console command that could only be seen and ran by admins and make all of those Console Commands admin only at once
[QUOTE=xomaxhox;27632692]I was just trying to make another version of Ralle's code in which I could first specify the function, and then link it to a console command that could only be seen and ran by admins and make all of those Console Commands admin only at once[/QUOTE] You could do something like this: [lua]local commands = {} commands.bob = function( ply, args ) ... end commands.jim = function( ply, args ) ... end local function adminCommandHandler( ply, com, args ) if ( ply:IsAdmin() ) then commands[com]( ply, args ) end end for com, func in pairs( commands ) do concommand.Add( com, adminCommandHandler ) end[/lua] Tell me if I need to explain anything.
Hey, back with a question. Thought I'd just add onto this thread rather than make a new one. I'm trying to make a Noclip command based off what Jimbodude said. The problem is, is that it doesn't work. I don't get any errors it just doesn't work. [LUA] function NahClip( ply, cmd, args ) if ( args[1] ) then local target = FindPlayer( args[1] ) if target != nill then target:SetMoveType(MOVETYPE_NOCLIP) end end end concommand.Add("noclipem", Nahclip) [/LUA]
[QUOTE=Pappasmurf;27635656]Hey, back with a question. Thought I'd just add onto this thread rather than make a new one. I'm trying to make a Noclip command based off what Jimbodude said. The problem is, is that it doesn't work. I don't get any errors it just doesn't work.[/QUOTE] I would guess it has something to do with: 1. Make sure you are not in noclip at the time of running this command if its on yourself Use [url=http://wiki.garrysmod.com/?title=Entity.GetMoveType]THIS[/url] to make sure that you switch the movetype depending on what your current state is 2. You spelt "nil" wrong in line 4
Still can't get it to work, I made sure I wasn't nocliped allready and I changed nill to nil. Any help would be appreciated.
I've got the same issue, despite following a previous thread dedicated to this problem (their solution tried to use the spectate and unspectate command) and neither work, did Garry shift around the functions or something?
[QUOTE=Pappasmurf;27638033]Still can't get it to work, I made sure I wasn't nocliped allready and I changed nill to nil. Any help would be appreciated.[/QUOTE] Are you sure the function is being called? Did you add a message above the noclip line and did it print?
Actually, It won't print. Any help would be appreciated. [LUA] function NoclipPlayer(ply, cmd, args) if ( args[1] ) then local target = FindPlayer( args[1] ) if target != nil then print("test") target:SetMoveType(MOVETYPE_NOCLIP ) end end end concommand.Add("NoclipThePlayer", NoclipPlayer) [/LUA] That's weird. I just ran the command in console manually And it printed Test and I was nocliped This is the button command on my Derma panel that runs it. Any help would be apreciated. [LUA] local noclip = vgui.Create("DButton") noclip:SetSize( 150, 25 ) noclip:SetPos( 170, 70 ) noclip:SetText("NoClip" ) noclip:SetParent( commandspanel ) noclip.Doclick = function() for k, v in pairs(player.GetAll() ) do if list:GetSelectedItems()[1]:GetValue() == v:Nick() then RunConsoleCommand("NoclipThePlayer", v:GetName() ) end end end [/LUA]
Try printing what is passed as an argument and what FindPlayer compares it to.
Sorry, you need to Log In to post a reply to this thread.