Author Topic: Can someone help me check if "message" is something in a table  (Read 69 times)

0 Members and 1 Guest are viewing this topic.

Offline fubar

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Trying to make it so if the user is entering a weapon that is banned, it will not work!
Code: [Select]
local CN= "Trainer"

local bannedSweps = { }
bannedSweps["weapon_keypadchecker"] = true
bannedSweps["arrest_stick"] = true
bannedSweps["door_ram"] = true
bannedSweps["keys"] = true
bannedSweps["pocket"] = true
bannedSweps["unarrest_stick"] = true
bannedSweps["weaponchecker"] = true
bannedSweps["weapon_nav_editor"] = true
bannedSweps["manhack_welder"] = true
bannedSweps["tbfy_manager"] = true
bannedSweps["weapon_vape_mega"] = true



function ulx.give( calling_ply, target_ply, message )

if message == (bannedSweps[""]) then

print("That weapon is banned!")
else

target_ply:Give( message )
end
ulx.fancyLogAdmin( calling_ply, true , "#A gave #T a ".. message ,target_ply)

end

local give = ulx.command( CN, "ulx give", ulx.give , "!give" , true )
give:addParam{ type=ULib.cmds.PlayerArg, target="*"}
give:addParam{ type=ULib.cmds.StringArg, hint="weapon"}
give:defaultAccess( ULib.ACCESS_ADMIN )
give:help( "Gives a certain player a weapon" )

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2636
  • Karma: 413
    • |G4P| Gman4President
Re: Can someone help me check if "message" is something in a table
« Reply #1 on: July 17, 2018, 02:30:42 PM »
Try this:


Code: Lua
  1. local CN= "Trainer"
  2.  
  3. local bannedSweps = {
  4.         "weapon_keypadchecker",
  5.         "arrest_stick",
  6.         "door_ram",
  7.         "keys",
  8.         "pocket",
  9.         "unarrest_stick",
  10.         "weaponchecker",
  11.         "weapon_nav_editor",
  12.         "manhack_welder",
  13.         "tbfy_manager",
  14.         "weapon_vape_mega"
  15. }
  16.  
  17. function ulx.give( calling_ply, target_ply, weapon )
  18.         if table.HasValue( bannedSweps, weapon ) then
  19.                 print("That weapon is banned!")
  20.         else
  21.                 target_ply:Give( weapon )
  22.         end
  23.         ulx.fancyLogAdmin( calling_ply, true , "#A gave #T a ".. weapon ,target_ply)
  24. end
  25. local give = ulx.command( CN, "ulx give", ulx.give , "!give" , true )
  26. give:addParam{ type=ULib.cmds.PlayerArg, target="*"}
  27. give:addParam{ type=ULib.cmds.StringArg, hint="weapon"}
  28. give:defaultAccess( ULib.ACCESS_ADMIN )
  29. give:help( "Gives a certain player a weapon" )
  30.  

Note: Not tested... just fixed the table stuff in your code.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7886
  • Karma: 372
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Can someone help me check if "message" is something in a table
« Reply #2 on: July 17, 2018, 04:00:27 PM »
Additionally, though the actual releases may not work anymore, you might get more ideas from the bare code in releases/archived releases section.
There were 2 or 3 made to control usage of various weapons/items/functions/etc.
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin