• LUA Kick. how to use it?
    42 replies, posted
Hello. I'm learning the LUA language, and I'm working on a small script. All perfectly works except the kick code. This is an example: local ply = LocalPlayer() timer.Simple(20, function() print("You Was kicked") ply:Kick("You was kicked") end ) When I join in the my server, after 20 seconds, in the console I can read "You was kicked". But the server don't kick me, and don't give me any script errors!
Use [lua] tags, also it's lua, not LUA.
[URL="http://wiki.garrysmod.com/page/Player/Kick"]Player:Kick[/URL] is serverside only. You are running it clientside.
[QUOTE=Netheous;49107659]Use [lua] tags, also it's lua, not LUA.[/QUOTE]It doesn't matter if its lua or LUA. Posting shit like that is the pure definition of shitposting. And as CB said you have to run it serverside
[QUOTE=CoreWaffle;49107732]It doesn't matter if its lua or LUA. Posting shit like that is the pure definition of shitposting. And as CB said you have to run it serverside[/QUOTE] Yeah, because my post was ALL ABOUT semantics and not about him using lua tags so it's more readable. Good job being an asshat.
[QUOTE=Netheous;49107738]Yeah, because my post was ALL ABOUT semantics and not about him using lua tags so it's more readable. Good job being an asshat.[/QUOTE]I've seen you and alot of other people complaining about the none important spelling of lua so I felt like commenting on that.
LUA lua Lua LuA lUa LUA lua Lua LuA lUa LUA lua Lua LuA lUa
[QUOTE=CoreWaffle;49107746]I've seen you and alot of other people complaining about the none important spelling of lua so I felt like commenting on that.[/QUOTE] And how are your posts valuable in any way? All you've done was start this pointless conversation about whether my post was valuable.
[QUOTE=Netheous;49107848]And how are your posts valuable in any way? All you've done was start this pointless conversation about whether my post was valuable.[/QUOTE]Yeah its a bit ironic when my post didn't really contribute to the thread. Mostly because CB gave him the answer and I couldn't really add anything to it. So let's focus on the question now.
If its a shared script try to put this in before the code [lua]if (SERVER) then[/lua] and end it after the code with [lua]end[/lua] If its a clientside script make it serverside. In the garrysmod wiki you can see if its a clientside or serverside code around the bottom, just above the comments on the page.
[QUOTE=CoreWaffle;49107881]Yeah its a bit ironic when my post didn't really contribute to the thread. Mostly because CB gave him the answer and I couldn't really add anything to it. So let's focus on the question now.[/QUOTE] If you don't have anything to add - then don't post lol? It's not like you HAVE to reply, especially when your reply is 'what person above said'. Now as you said, let's end this retarded convo. [QUOTE=Skere_;49107898]If its a shared script try to put this in before the code [lua]if (SERVER) then[/lua] and end it after the code with [lua]end[/lua] If its a clientside script make it serverside. In the garrysmod wiki you can see if its a clientside or serverside code around the bottom, just above the comments on the page.[/QUOTE] I really suggest using separate files for serverside, clientside and shared for organization purposes
If I'm Working in a clientside file, and I want kick the player, how can I do it? For example: (ClientSide file) timer.Simple(20, function() Now I want kick this player. end )
[QUOTE=Predda;49109289]If I'm Working in a clientside file, and I want kick the player, how can I do it? For example: (ClientSide file) timer.Simple(20, function() Now I want kick this player. end )[/QUOTE] You can't you have to kick the player with a server side file. I am not sure why you would want to kick someone inside a client side file. Can you explain more of what you are trying to do?
[QUOTE=Predda;49109289]If I'm Working in a clientside file, and I want kick the player, how can I do it? For example: (ClientSide file) timer.Simple(20, function() Now I want kick this player. end )[/QUOTE] You could use LocalPlayer():ConCommand("disconnect")
[URL="https://facepunch.com/showthread.php?t=911309"]https://facepunch.com/showthread.php?t=911309[/URL] I want do a remake of this script, only for learn the lua.
So why can't you do this in a server file? The original code is a server file it dosn't take place on the client. I don't really see a real reason for why you need it to be a client side file.
[QUOTE=SexyBeast70;49109412]You could use LocalPlayer():ConCommand("disconnect")[/QUOTE] Oh, thank you. [editline]13th November 2015[/editline] [QUOTE=boxvader;49109456]So why can't you do this in a server file? The original code is a server file it dosn't take place on the client. I don't really see a real reason for why you need it to be a client side file.[/QUOTE] Because I'm used to making any scripts in client side file. Isn't it professional?
[QUOTE=Predda;49109458]Oh, thank you. [editline]13th November 2015[/editline] Because I'm used to making any scripts in client side file. Isn't it professional?[/QUOTE] That's a really poor reason. It's not that hard to make a server side file and you need to learn when it is appropriate to use the two. They are not interchangeable there are cases where you should be using one over the other.
If I paste the script in the server file, it doesn't works. I should to re-make this script for use the server side file. And I haven't understand how to use the server or client side file. This script work on the player, so on the client, for that I've written the script in the client side file, when I have to write the script on the server side and when on the client side? Sorry for my English!
[QUOTE=Predda;49109289]If I'm Working in a clientside file, and I want kick the player, how can I do it? For example: (ClientSide file) timer.Simple(20, function() Now I want kick this player. end )[/QUOTE] You can't kick via clientside file. If you want some button, menu or anything then you'll have to do networking.
Here fam, I'll show you what your script should like like. This needs to go in a shared file, but as Netheous said when you're a bit more experienced you should separate them into server and client. [lua] if CLIENT then local ply = LocalPlayer() -- you got this right, on clientside. timer.Simple(20, function() -- and this. print("You Was kicked") net.Start("KickMe") -- preparing the 'envelope' to go to the server. net.WriteEntity(ply) -- Putting yourself in the envelope. net.SendToServer() -- Sending the envelope over to serverside with the ply inside. end) end if SERVER then util.AddNetworkString("KickMe") -- This tells the server that if this string is sent via net library then it's a valid string. net.Receive("KickMe", function(len, pl) -- ignore len, but 'pl' is a variable telling us who sent this local ply = net.ReadEntity() -- Opening the envelope that the server received and looking at the ply inside. if ply == pl then -- without this, any player with hacks could kick whoever they wanted to! This checks that the person they want to kick is themself. ply:Kick("Kicked") end end) end [/lua] The netlibrary is like a post system, that lets you send envelopes of data between client and server. In this example after 20 seconds it sends a message to the server telling it that you want yourself kicked.
[QUOTE=Splerge;49120387]Here fam, I'll show you what your script should like like. This needs to go in a shared file, but as Netheous said when you're a bit more experienced you should separate them into server and client. [lua] if CLIENT then local ply = LocalPlayer() -- you got this right, on clientside. timer.Simple(20, function() -- and this. print("You Was kicked") net.Start("KickMe") -- preparing the 'envelope' to go to the server. net.WriteEntity(ply) -- Putting yourself in the envelope. net.SendToServer() -- Sending the envelope over to serverside with the ply inside. end) end if SERVER then util.AddNetworkString("KickMe") -- This tells the server that if this string is sent via net library then it's a valid string. net.Receive("KickMe", function(len, pl) -- ignore len, but 'pl' is a variable telling us who sent this local ply = net.ReadEntity() -- Opening the envelope that the server received and looking at the ply inside. if ply == pl then -- without this, any player with hacks could kick whoever they wanted to! This checks that the person they want to kick is themself. ply:Kick("Kicked") end end) end [/lua] The netlibrary is like a post system, that lets you send envelopes of data between client and server. In this example after 20 seconds it sends a message to the server telling it that you want yourself kicked.[/QUOTE] Why are you writing an entity that isn't needed. You can litterally just use the second argument of net.Recieve, there's no reason to WriteEntity yourself as well.
[QUOTE=meharryp;49120444]Why are you writing an entity that isn't needed. You can litterally just use the second argument of net.Recieve, there's no reason to WriteEntity yourself as well.[/QUOTE] to teach him how to use net library, that's why. Otherwise he might get a skewed perspective of what it's used for.
[QUOTE=Splerge;49120571]to teach him how to use net library, that's why. Otherwise he might get a skewed perspective of what it's used for.[/QUOTE] You're just going to confuse people by doing that.
But if you want to kick other players then you'll have to use net.WriteEntity(), but remember to always check client sent stuff serverside. So the players won't be able to abuse it.
[QUOTE=CoreWaffle;49120954]But if you want to kick other players then you'll have to use net.WriteEntity(), but remember to always check client sent stuff serverside. So the players won't be able to abuse it.[/QUOTE] that's what I was getting at, as he'll probably eventually want to make the script more versatile.
[QUOTE=Splerge;49120387][lua] if CLIENT then local ply = LocalPlayer() -- you got this right, on clientside. timer.Simple(20, function() -- and this. print("You Was kicked") net.Start("KickMe") -- preparing the 'envelope' to go to the server. net.WriteEntity(ply) -- Putting yourself in the envelope. net.SendToServer() -- Sending the envelope over to serverside with the ply inside. end) end if SERVER then util.AddNetworkString("KickMe") -- This tells the server that if this string is sent via net library then it's a valid string. net.Receive("KickMe", function(len, pl) -- ignore len, but 'pl' is a variable telling us who sent this local ply = net.ReadEntity() -- Opening the envelope that the server received and looking at the ply inside. if ply == pl then -- without this, any player with hacks could kick whoever they wanted to! This checks that the person they want to kick is themself. ply:Kick("Kicked") end end) end [/lua] [/QUOTE] [lua] if SERVER then util.AddNetworkString("kickmyass") net.Receive("kickmyass", function(_, ply) ply:Kick("ass was kicked") end) else timer.Simple(5, function() net.Start("kickmyass") net.SendToServer() end) end [/lua] fixed
[QUOTE=Netheous;49107659]Use [lua] tags, also it's lua, not LUA.[/QUOTE] actually it should be Lua :v comes from the creator's name
[QUOTE=NewDude;49122672]actually it should be Lua :v comes from the creator's name[/QUOTE] or maybe gLua :v:
[QUOTE=Phoenixf129;49122791]or maybe gLua :v:[/QUOTE] dude youre pushing it too far edit: i wasnt being serious, guys
Sorry, you need to Log In to post a reply to this thread.