• Print

Author Topic: Help with a if teamkill code  (Read 13465 times)

0 Members and 1 Guest are viewing this topic.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Help with a if teamkill code
« on: July 29, 2016, 07:40:24 pm »
I wouldn't call myself a noob when it comes to programming, most of the time i can find what i need to edit and know what it does, sometimes i can't. I'm not very familiar with lua but i know very little. I'm trying to have a script that will check if an innocent has killed another innocent or a detective, and use awarn to issue a warn for "RDM" (Yes this is for TTT). I don't really know what I'm looking for but I could probably do it myself if I was given/told what i need and to do, and I will reply/edit if I am in need of more assistance.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with a if teamkill code
« Reply #1 on: July 29, 2016, 07:46:44 pm »
Be sure to check this out. It will be useful.

I know TTT has a function called "GetRole()". I know I wrote a script for this at one point but I don't have it anymore. To check for Innocent, for example, use
Code: Lua
  1. if attacker:GetRole() == ROLE_INNOCENT then
.

Let me know if you need any more help.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Help with a if teamkill code
« Reply #2 on: July 29, 2016, 08:05:19 pm »
Be sure to check this out. It will be useful.

-snip

Let me know if you need any more help.

Thank you for the help. I'm confused already. I've never even made my own code ever, usually just copy and paste whatever i need so this is all new to me (well lua at least).

Code: Lua
  1. function TTTeamKill ( ply ) do --I don't evven know
  2.         if (attacker:GetRole() == ROLE_INNOCENT) then --Pretty sure that's correct
  3.                 --Don't really know what to put here, or how to even call awarn's warn function
  4.         end
  5. end
« Last Edit: July 29, 2016, 08:07:04 pm by [?] The Last Centurion »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with a if teamkill code
« Reply #3 on: July 29, 2016, 08:25:42 pm »
Well you don't put "do" after a function. Secondly, this will warn someone any time an Innocent kills someone, which may not always be RDM. Basically it's something like this:

Code: Lua
  1. function tttTeamKill(victim, inflictor, attacker) -- These are the variables on the "PlayerDeath" hook on the Garrysmod Wiki.
  2.  
  3.     if attacker:GetRole() == ROLE_INNOCENT and victim:GetRole() == ROLE_INNOCENT then -- If both the person who killed someone and the person who was killed were innocent, then...
  4.  
  5.         -- Don't know the awarn call, but you would put it here.
  6.  
  7.     end -- Finish the if
  8.  
  9. end -- Finish the function
  10. hook.Add( "PlayerDeath", "Warn On RDM", tttTeamKill ) -- Adds the (1) hook name, (2) some random name (can be anything), and (3) the function that is called every time an action happens that satisfies the hook. In this case, "PlayerDeath" is called every time a player dies, thus calling the "tttTeamKill" function.

That's, in a nutshell, how it is. Keep in mind, that will warn ANY Innocent who kills ANY other innocent. I'm not sure how to make it check only if it was random or not, but you could always send a message to the player that was killed ( the victim ) instead of automatically warning the attacker.
« Last Edit: July 29, 2016, 08:28:02 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Help with a if teamkill code
« Reply #4 on: July 29, 2016, 08:40:30 pm »
Well you don't put "do" after a function. Secondly, this will warn someone any time an Innocent kills someone, which may not always be RDM. Basically it's something like this:

Code: Lua
  1. function tttTeamKill(victim, inflictor, attacker) -- These are the variables on the "PlayerDeath" hook on the Garrysmod Wiki.
  2.  
  3.     if attacker:GetRole() == ROLE_INNOCENT and victim:GetRole() == ROLE_INNOCENT then -- If both the person who killed someone and the person who was killed were innocent, then...
  4.  
  5.         -- Don't know the awarn call, but you would put it here.
  6.  
  7.     end -- Finish the if
  8.  
  9. end -- Finish the function
  10. hook.Add( "PlayerDeath", "Warn On RDM", tttTeamKill ) -- Adds the (1) hook name, (2) some random name (can be anything), and (3) the function that is called every time an action happens that satisfies the hook. In this case, "PlayerDeath" is called every time a player dies, thus calling the "tttTeamKill" function.

That's, in a nutshell, how it is. Keep in mind, that will warn ANY Innocent who kills ANY other innocent. I'm not sure how to make it check only if it was random or not, but you could always send a message to the player that was killed ( the victim ) instead of automatically warning the attacker.

Thanks, and I went to the Awarn2 page and found hook callbacks, so would i just put the hook needed after the if? The hook I put there was

AWarnPlayerWarned( Player target_ply, Player ply, String reason )
   target_ply - Player being warned
   ply - Warning Admin
   reason - Reason for warning

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with a if teamkill code
« Reply #5 on: July 29, 2016, 09:05:35 pm »
I'm not extremely sure. As Mr President released it and I'm not super familiar with awarn, I think he'd know the best.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Help with a if teamkill code
« Reply #6 on: July 29, 2016, 09:08:24 pm »
Code: Lua
  1. function tttTeamKill( victim, inflictor, attacker )
  2.         if not attacker:GetRole() == ROLE_INNOCENT then return end
  3.         if victim:GetRole() == ROLE_INNOCENT or victim:GetRole() == ROLE_DETECTIVE then
  4.                 awarn_warnplayer( nil, attacker, "Autowarned for RDM" )
  5.         end
  6. end
  7. hook.Add( "PlayerDeath", "Warn On RDM", tttTeamKill )
  8.  

This should work. Try it out.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Help with a if teamkill code
« Reply #7 on: July 29, 2016, 09:49:28 pm »

-boop

This should work. Try it out.

Thanks for your help, Mr. President.

After testing: yay it works, and to make it only run during the round and not post round what do I do?

Also on another note, could i have help creating a ulx command that would display to all admins/superadmins what role said player is? eg !role (player) displays in chat "(player)'s role is (role)."

Code: Lua
  1. function ulx.role( calling_ply, target_plys)
  2.         for _, v in ipairs( target_plys ) do
  3.                 PrintMessage( HUD_PRINTTALK, ply:GetRole() )
  4.         end
  5. end
  6. local role = ulx.command( CATEGORY_NAME , "ulx role", ulx.role, "!role" )
  7. role:defaultAccess( ULib.ACCESS_SUPERADMIN )
  8. role:help( "Show all time-based ranks" )

I just copy and pasted a command that was similar and tried to edit it. The printmessage thing I know probably isn't going to work, idk, I'm a noob.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Help with a if teamkill code
« Reply #8 on: July 29, 2016, 09:56:37 pm »
Sorry, I don't know enough about TTT to help you get it only working during a round.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Help with a if teamkill code
« Reply #9 on: July 29, 2016, 09:58:03 pm »
Sorry, I don't know enough about TTT to help you get it only working during a round.

It's fine, all i know is that there's a hook (i think) called TTTEndRound or something like that. Tbh I'm not even sure it's a hook but I know it exists. And I'm with lua.

EDIT: It doesn't actually work as intended, I just killed someone as a T and it warned me.
« Last Edit: July 29, 2016, 10:00:49 pm by [?] The Last Centurion »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with a if teamkill code
« Reply #10 on: July 29, 2016, 10:01:33 pm »
Code: Lua
  1. function tttTeamKill( victim, inflictor, attacker )
  2.     if GAMEMODE.round_state == ROUND_ACTIVE
  3.         if attacker:GetRole() == ROLE_INNOCENT then end
  4.             if victim:GetRole() == ROLE_INNOCENT or victim:GetRole() == ROLE_DETECTIVE then
  5.                     awarn_warnplayer( nil, attacker, "Autowarned for RDM" )
  6.             end
  7.         end
  8.     end
  9. hook.Add( "PlayerDeath", "Warn On RDM", tttTeamKill )

Try that.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Help with a if teamkill code
« Reply #11 on: July 29, 2016, 10:06:03 pm »
Code: Lua
  1. local TKreason = "TeamKill" --The reason
  2.  
  3. function tttTeamKill( victim, inflictor, attacker )
  4.                 if ply:IsUserGroup( "superadmin" ) then return end --exempt
  5.                 if GAMEMODE.round_state == ROUND_ACTIVE
  6.                 if not attacker:GetRole() == ROLE_INNOCENT then return end
  7.                 if attack:GetRole() == ROLE_INNOCENT then
  8.                 if victim:GetRole() == ROLE_INNOCENT or victim:GetRole() == ROLE_DETECTIVE then
  9.                 awarn_warnplayer( nil, attacker, TKreason )
  10.         end
  11.         end
  12. end
  13.  

I have this currently, i added the
Code: [Select]
if attack:GetRole() == ROLE_INNOCENT then
because it was flagging all kills as TK. I don't know if it will work yet, will report my findings.

EDIT 1: Seems to work, but I still get warned, and I'm a scrub at ULX and don't remember how to do things with it.
« Last Edit: July 29, 2016, 10:12:18 pm by [?] The Last Centurion »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with a if teamkill code
« Reply #12 on: July 29, 2016, 10:10:16 pm »
attacker:GetRole() not attack. Also, ply will throw errors because it's not defined. Use attacker:IsUserGroup("superadmin").
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline [?] The Last Centurion

  • Newbie
  • *
  • Posts: 23
  • Karma: 2
Re: Help with a if teamkill code
« Reply #13 on: July 29, 2016, 10:12:47 pm »
attacker:GetRole() not attack. Also, ply will throw errors because it's not defined. Use attacker:IsUserGroup("superadmin").

Swear I wrote attacker, and I will do that.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with a if teamkill code
« Reply #14 on: July 29, 2016, 10:23:28 pm »
I'm just going to re-write what you had, but properly indented.

Code: Lua
  1. local TKreason = "TeamKill" --The reason
  2.  
  3. function tttTeamKill( victim, inflictor, attacker )
  4.     if ply:IsUserGroup( "superadmin" ) then return end --exempt
  5.         if GAMEMODE.round_state == ROUND_ACTIVE
  6.         if not attacker:GetRole() == ROLE_INNOCENT then return end
  7.         if attack:GetRole() == ROLE_INNOCENT then
  8.             if victim:GetRole() == ROLE_INNOCENT or victim:GetRole() == ROLE_DETECTIVE then
  9.                 awarn_warnplayer( nil, attacker, TKreason )
  10.             end
  11.         end
  12.     end

This is what you would have exactly. See how there are not enough "end"s for all of your "if"s. Also I will fix your syntax.

Code: Lua
  1. function tttTeamKill( victim, inflictor, attacker )
  2.     if attacker:IsUserGroup( "superadmin" ) then return end --exempt
  3.     if GAMEMODE.round_state == ROUND_ACTIVE then
  4.         if attacker:GetRole() == ROLE_INNOCENT then
  5.             if victim:GetRole() == ROLE_INNOCENT or victim:GetRole() == ROLE_DETECTIVE then
  6.                 awarn_warnplayer( nil, attacker, TKreason )
  7.             end
  8.         end
  9.     end
  10. end
« Last Edit: July 29, 2016, 10:25:16 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print