• Print

Author Topic: !notarget npc command  (Read 8207 times)

0 Members and 1 Guest are viewing this topic.

Offline Envious™Savage

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
!notarget npc command
« on: July 05, 2017, 10:02:56 am »
Is it possible to have a !notarget command so npc do not target certain people in starwarsrp...i noticed  http://wiki.garrysmod.com/page/Player/SetNoTarget but i cant figure out how to get it to work...

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: !notarget npc command
« Reply #1 on: July 05, 2017, 07:52:08 pm »
Player:SetNoTarget sets a player's ability to be targeted by bots. I wrote up a script real fast with comments so that you can see how to do it for yourself :)

Code: Lua
  1. function ulx.notarg( calling_ply, target_ply, should_notarg ) -- Initializes the function, everything executed is after here and before the 'end'.
  2.     target_ply:SetNoTarget( not should_notarg ) -- Uses Player:SetNoTarget() to set a player's targetability.
  3.     ulx.fancyLogAdmin( calling_ply, "#A set #T's targetability to #s", target_ply, tostring( should_notarg ) ) -- Logs the command in the chat so everyone knows what happened.
  4. end -- Ends the function. Nothing after this will be executed in the command below.
  5. local notarg = ulx.command( "Utility", "ulx notarg", ulx.notarg, "!notarget" ) -- Registers the command under the "Utility" tab, makes the console command to "ulx notarg", makes the command execute the 'ulx.notarg' function, and makes the chat command "!notarget".
  6. notarg:addParam{ type=ULib.cmds.PlayerArg } -- Allows to target another player. This param is added to the 'target_ply' variable above.
  7. notarg:addParam{ type=ULib.cmds.BoolArg, invisible=true } -- Allows for an opposite command. This param is added to the 'should_notarg' variable above.
  8. notarg:defaultAccess( ULib.ACCESS_ADMIN ) -- Sets the default access for the command to 'admin' or higher.
  9. notarg:setOpposite( "ulx allowtarget", { _, _, false }, "!allowtarget" ) -- Adds an opposite command to allow resetting targetability.
  10. notarg:help( "Makes a target either targetable or not targetable by bots." ) -- The message that shows up under 'ulx help'

Keep in mind I wrote this up really quickly, can't guarantee if this will work or not, but that is how the Player:SetNoTarget works, and future reference for how to write up your own ULX commands :)
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print