• Ban players who disconnect with a certain weapon in their hands
    25 replies, posted
I already tried: [CODE] function GAMEMODE:PlayerDisconnected( ply ) ActiveWeapon = ply:GetActiveWeapon() if ( ActiveWeapon == guigui_handcuffed ) then RunConsoleCommand(ulx ban ply:Name 5 You get banned.) PrintMessage( HUD_PRINTTALK, ply:Name.. " get banned." ) end PrintMessage( HUD_PRINTTALK, ply:Name.. " left the game." ) end [/CODE] guigui_handcuffed is set in the hands of the player when hancuffed. But this code does nothing, even the PrintMessage does not print message. The code is in lua/autorun/server
You should be getting a syntax error in your console about not using strings. "guigui_handcuffed" should be a string, and "ulx ban ply:Name 5 You get banned." should be a set of args for each space.
[CODE]if IsValid(ActiveWeapon) then if ActiveWeapon:GetClass()=="guigui_handcuffed" then ... end end[/CODE]
Also, use local variables.
Unless you're developing your own gamemode, do not override the gamemode functions, use hooks. (Or at least til you know what you're doing) fixed code: [code] local function plydisco(ply) local ActiveWeapon = ply:GetActiveWeapon() if ( ActiveWeapon == "guigui_handcuffed" ) then RunConsoleCommand("ulx ban",ply:Name(),"You got punished for leaving while being cuffed","1d") PrintMessage( HUD_PRINTTALK, ply:Name().. " got fucking rekt." ) end PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." ) end hook.Add("PlayerDisconnected","PunishLeavers",plydisco) [/code] You don't need to use globals, don't forget () after metafunctions, get a lua tutorial on strings and var types. Good attempt, but lots of beginners mistakes.
[QUOTE=RaKo;52640102]Unless you're developing your own gamemode, do not override the gamemode functions, use hooks. (Or at least til you know what you're doing) fixed code: [code] local function plydisco(ply) local ActiveWeapon = ply:GetActiveWeapon() if ( ActiveWeapon == "guigui_handcuffed" ) then RunConsoleCommand("ulx ban",ply:Name(),"You got punished for leaving while being cuffed","1d") PrintMessage( HUD_PRINTTALK, ply:Name().. " got fucking rekt." ) end PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." ) end hook.Add("PlayerDisconnected","PunishLeavers",plydisco) [/code] You don't need to use globals, don't forget () after metafunctions, get a lua tutorial on strings and var types. Good attempt, but lots of beginners mistakes.[/QUOTE] getactiveweaapon returns nil sometimes. you have to check if it is valid or not.
Didn't know that, actually makes sense when player doesn't have any weapon equipped (aka stripped, could be problem with NRL systems?) For OP: [code] if ( IsValid(ActiveWeapon) and ActiveWeapon == "guigui_handcuffed" ) then [/code]
[QUOTE=gmoddertr;52640115]getactiveweaapon returns nil sometimes. you have to check if it is valid or not.[/QUOTE] It returns NULL, not nil. That means you can do just ActiveWeapon:IsValid() [editline]2nd September 2017[/editline] [QUOTE=RaKo;52640118]Didn't know that, actually makes sense when player doesn't have any weapon equipped (aka stripped, could be problem with NRL systems?) For OP: [code] if ( IsValid(ActiveWeapon) and ActiveWeapon == "guigui_handcuffed" ) then [/code][/QUOTE] You still have to use GetClass.
[QUOTE=code_gs;52640126]It returns NULL, not nil. That means you can do just ActiveWeapon:IsValid() [/QUOTE] I didnt really know the difference between NULL and nil. I guess if it is entity it will be NULL. Thanks anyway
[QUOTE=RaKo;52640102]Unless you're developing your own gamemode, do not override the gamemode functions, use hooks. (Or at least til you know what you're doing) fixed code: [code] local function plydisco(ply) local ActiveWeapon = ply:GetActiveWeapon() if ( ActiveWeapon == "guigui_handcuffed" ) then RunConsoleCommand("ulx ban",ply:Name(),"You got punished for leaving while being cuffed","1d") PrintMessage( HUD_PRINTTALK, ply:Name().. " got fucking rekt." ) end PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." ) end hook.Add("PlayerDisconnected","PunishLeavers",plydisco) [/code] You don't need to use globals, don't forget () after metafunctions, get a lua tutorial on strings and var types. Good attempt, but lots of beginners mistakes.[/QUOTE] It does not work, the message "left the game" appears, but even if I change guigui_handcuffed to weapon_physgun and hold my physgun, I do not get banned. :s:
[QUOTE=Quozul;52640147]It does not work, the message "left the game" appears, but even if I change guigui_handcuffed to weapon_physgun and hold my physgun, I do not get banned. :s:[/QUOTE] maybe check our fixes?
[QUOTE=gmoddertr;52640150]maybe check our fixes?[/QUOTE] I do not need to check if the player have a valid weapon (is there other fixes that I don't see?) [editline]2nd September 2017[/editline] I think the problem is that I have a RP name because I try this in DarkRP gamemode
As code_gs mentioned, you need to call :GetClass() on the active weapon as well. Do it by either: [code] local ActiveWeapon = ply:GetActiveWeapon():GetClass() -- OR local ActiveWeapon = ply:GetActiveWeapon() ActiveWeapon = ActiveWeapon:GetClass() [/code] And yes, you do need to check if the player has a valid weapon. Imagine if player has no weapon in hand - which can happen and is very possible. (Disconnect on death? NRL system?) If he has no weapon, then your code will error. Also, I am 100% sure that RPName doesn't affect anything here. [editline]2nd September 2017[/editline] Wait actually don't use my fix, call the :GetClass() in the statement, otherwise the Valid check will fail.
[QUOTE=RaKo;52640169] [editline]2nd September 2017[/editline] Wait actually don't use my fix, call the :GetClass() in the statement, otherwise the Valid check will fail.[/QUOTE] So what do I need to do ? Because after adding :GetClass() nothing prints anymore. [editline]2nd September 2017[/editline] There is this error: [CODE] [ERROR] addons/darkrp_quozul/lua/autorun/server/sv_autoban.lua:6: Tried to use a NULL entity! 1. GetClass - [C]:-1 2. fn - addons/darkrp_quozul/lua/autorun/server/sv_autoban.lua:6 3. unknown - addons/ulib-master/lua/ulib/shared/hook.lua:109 [/CODE]
Can you post the code you have?
[QUOTE=code_gs;52640185]Can you post the code you have?[/QUOTE] [CODE] local function plydisco(ply) local ActiveWeapon = ply:GetActiveWeapon():GetClass() if ( ActiveWeapon == "weapon_physgun" ) then PrintMessage( HUD_PRINTTALK, ply:Name().. " got banned." ) end PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." ) end hook.Add("PlayerDeath","PunishLeavers",plydisco) [/CODE] I changed the code to simplify the tests
you cut something out, because 6th line erroring doesn't have any sense. And this error happens because you haven't listened to us, the ActiveWeapon was a NULL, which means you didn't have any IsValid check. We can't help you, if you simply don't listen to us. You may think you don't need something, and cut it out, but again, you're the one asking for help - and we are just helping you. [editline]2nd September 2017[/editline] I'm going to post full code here, hopefully it works. I am also going to add comments, so hopefully you learn something [code] local function plydisco(ply) --Here, we define, create a local function - Local functions exist only in the same file as it is created in local ActiveWeapon = ply:GetActiveWeapon() -- We are defining a new variable which contains player held weapon, note: the ActiveWeapon can be empty if the player doesn't have any weapon - again, we're making it local - no need to make it globally available. if ( IsValid(ActiveWeapon) and ActiveWeapon:GetClass() == "guigui_handcuffed" ) then --We are checking here, if the variable (with the weapon) is valid, and if the class of the weapon equals something RunConsoleCommand("ulx ban",ply:Name(),"You got punished for leaving while being cuffed","1d") --self explanatory, the wiki states that we need to pass each argument as new string PrintMessage( HUD_PRINTTALK, ply:Name().. " got fucking rekt." ) --You seem to get that, good for you end PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." ) end hook.Add("PlayerDisconnected","PunishLeavers",plydisco) --We are "sticking" that function we just made using existing in game hook system - this makes it that whenever there's an event happening in the game, the original function will call those "hooks", allowing us to add on our own behavior to those events. First argument is the event name. You can see all of them on gmod wiki. Second argument is our unique name, in case we ever need to remove that hook. Third argument is our function callback, so whenever this event gets run, that function that we supplied will be run as well. Since we are referencing to the function (it is different than calling it or creating it) we don't add the ()'s around them. Hook arguments like Player get automatically passed over to our function. [/code]
[QUOTE=RaKo;52640195]you cut something out, because 6th line erroring doesn't have any sense. And this error happens because you haven't listened to us, the ActiveWeapon was a NULL, which means you didn't have any IsValid check. We can't help you, if you simply don't listen to us. You may think you don't need something, and cut it out, but again, you're the one asking for help - and we are just helping you. [editline]2nd September 2017[/editline] I'm going to post full code here, hopefully it works. I am also going to add comments, so hopefully you learn something [code] local function plydisco(ply) --Here, we define, create a local function - Local functions exist only in the same file as it is created in local ActiveWeapon = ply:GetActiveWeapon() -- We are defining a new variable which contains player held weapon, note: the ActiveWeapon can be empty if the player doesn't have any weapon - again, we're making it local - no need to make it globally available. if ( IsValid(ActiveWeapon) and ActiveWeapon:GetClass() == "guigui_handcuffed" ) then --We are checking here, if the variable (with the weapon) is valid, and if the class of the weapon equals something RunConsoleCommand("ulx ban",ply:Name(),"You got punished for leaving while being cuffed","1d") --self explanatory, the wiki states that we need to pass each argument as new string PrintMessage( HUD_PRINTTALK, ply:Name().. " got fucking rekt." ) --You seem to get that, good for you end PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." ) end hook.Add("PlayerDisconnected","PunishLeavers",plydisco) [/code][/QUOTE] I believe you need to separate every spaced command as an arg in RunConsoleCommand. "ulx" and "ban" should be separate, and so should every word.
[QUOTE=code_gs;52640215]I believe you need to separate every spaced command as an arg in RunConsoleCommand. "ulx" and "ban" should be separate, and so should every word.[/QUOTE] honestly, phuck that, code will only become more and more gimmicky for already new user like OP use (better imo, if \" aren't confusing for him) [code] game.ConsoleCommand( "ulx ban "..ply:Name().." \"You got punished for leaving the server while being cuffed\" 1d" ) [/code]
And now, how I unban myself :D Thanks guys [QUOTE=RaKo;52640102]Unless you're developing your own gamemode, do not override the gamemode functions, use hooks.[/QUOTE] I have a GAMEMODE:PlayerDeath in the script, I turn it into hook [QUOTE=RaKo;52640195]you cut something out, because 6th line erroring doesn't have any sense. And this error happens because you haven't listened to us, the ActiveWeapon was a NULL, which means you didn't have any IsValid check. We can't help you, if you simply don't listen to us. You may think you don't need something, and cut it out, but again, you're the one asking for help - and we are just helping you.[/QUOTE] Sorry if I don't understand English as easely as you
[QUOTE=Quozul;52640249]snip Sorry if I don't understand English as easely as you[/QUOTE] Had no idea that English isn't your native language, I thought that you're just really young. Well anyways, sorry, but try to listen to our suggestions a little bit more in the future :)
[QUOTE=RaKo;52640254]Had no idea that English isn't your native language, I thought that you're just really young. Well anyways, sorry, but try to listen to our suggestions a little bit more in the future :)[/QUOTE] There is a flag, (and my os and web browser) under my name, no problem
[QUOTE=Quozul;52640256]There is a flag, (and my os and web browser) under my name, no problem[/QUOTE] Doesn't really matter you see, I am from Poland but I am living in Ireland, the flag doesn't tell us much about the user ;) Are you still having problems with you being banned or is it fixed?
[QUOTE=RaKo;52640271]Are you still having problems with you being banned or is it fixed?[/QUOTE] [CODE]Error, bad server command ulx ban abc "You got punished for leaving the server while being cuffed" 1d[/CODE] But I will find how to fix it
[QUOTE=Quozul;52640277][CODE]Error, bad server command ulx ban abc "You got punished for leaving the server while being cuffed" 1d[/CODE] But I will find how to fix it [/QUOTE] you may want to use the ulib ban function directly. [CODE]ULib.addBan(steamid, time, reason)[/CODE]
[QUOTE=gmoddertr;52640294]you may want to use the ban function directly. [CODE]ULib.addBan(steamid, time, reason)[/CODE][/QUOTE] Works, thanks
Sorry, you need to Log In to post a reply to this thread.