Functioning, admin only "notarget" style command, for multiplayer.

Notarget doesn’t work and everyone knows this, so I am asking for an admin only command or maybe a ULX plugin or something (!notarget <user> to notarget someone else or simply !notarget just for yourself, works as a toggle) so that I can have NPCs ignore me when I’m trying to do something such as film players combating NPCs or simply just spawning them for players to fight and so on and so forth, I suppose you get the picture and the rest is all just useless details, so if you have any questions, feel free to ask, help me help you help me and everyone else in GMod, et cetera. :slight_smile:

That was one sentence.

well you can use the **[Player.SetNoTarget

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.SetNoTarget)** function.

Well if this was ASSMOD

you could do something like

If ply:IsAdmin then
Ply.SetNoTarget
end

[editline]29th January 2011[/editline]

Actually , u can do this w/o ASSMOD , since its Gmod Default, but u have to make sure ULX corresponds

ULX should work with that code.

Well, could someone make it ‘compatible’ with ULX? The best I can do with lua is find an error for a dev, lol.

Should be Compatable

All admin mods use ply:IsAdmin
For their Admins.

[lua]
ulx.setCategory( “Fun” )

function ulx.cc_notarget( ply, command, argv, args )
if #argv < 1 then
ULib.tsay( ply, ulx.LOW_ARGS, true )
return
end

local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply )

if not targets then
	ULib.tsay( ply, err, true )
	return
end

for _, v in ipairs( targets ) do
	if v.noTarget != true
		ulx.logUserAct( ply, v, "#A set notarget on #T" )
		v:SetNoTarget(true)
		v.noTarget = true
	else
		ulx.logUserAct( ply, v, "#A removed notarget on #T" )
		v:SetNoTarget(false)
		v.noTarget = false
	end
end

end
ulx.concommand( “notarget”, ulx.cc_notarget, “<user(s)> - Set’s notarget on the person.”, ULib.ACCESS_ADMIN, “!notarget”, _, ulx.ID_PLAYER_HELP )
ulx.addToMenu( ulx.ID_MCLIENT, “Notarget”, “ulx notarget” )
[/lua]

Untested + never worked with ULX, just edited one of the existing modules. Think it will work though.

Putting it in autorun/server didn’t work :frowning: Also, the command notarget itself requires sv_cheats to be set to 1, maybe there’s another way?

Put it in ULX’s modules folder.

This one is tested, works, and goes into autorun/server.
However, it’s used through console commands rather than chat ( haven’t figured chat out yet )

Command is notarget_admin “name” (name isn’t needed)

[lua]function ToggleNoTarget( ply, cmd, args ) – Toggle command
if ply:IsAdmin() then else return end

target = ply
if args and args[ 1 ] then
    if string.len( args[ 1 ] ) &lt; 3 then
        ply:PrintMessage( HUD_PRINTCONSOLE, "Please enter atleast 3 letters" )
        return
    else
        target = FindPlayer_ByName( args[ 1 ] )
    end
end

if target == "Fail1" then
    ply:PrintMessage( HUD_PRINTCONSOLE, "There are too many people with this in their name, please make it more clear." )
    return
elseif target == "Fail2" then
    ply:PrintMessage( HUD_PRINTCONSOLE, "Player not found." )
    return
end

if target.NoTarget then
    target:SetNoTarget( false )
    target.NoTarget = false
    ply:PrintMessage( HUD_PRINTCONSOLE, "No Target OFF." )
else
    target:SetNoTarget( true )
    target.NoTarget = true
    ply:PrintMessage( HUD_PRINTCONSOLE, "No Target ON." )
end

end
concommand.Add( “notarget_admin”, ToggleNoTarget )

function FindPlayer_ByName( name )
playerfound = false
playersfound = 0

for k, v in pairs( player.GetAll() ) do
    if v:Nick() == name then
        playerfound = v
        playersfound = playersfound + 1
    end
end

if not playerfound then
    for k, v in pairs( player.GetAll() ) do
        for i = 1, string.len( v:Nick() ) do
            if string.sub( v:Nick(), i, ( ( i-1 ) + string.len( name ) ) ) == name then
                playerfound = v
                playersfound = playersfound + 1
            end
        end
    end
end

if playersfound &gt; 1 then
    return "Fail1"
elseif playersfound == 0 then
    return "Fail2"
elseif playerfound then
    return playerfound
end

end[/lua]

Thank you for this script and your efforts, sirs.

Sigh, just realised I should have used string.find, oh well - this way works too.

The script works wonderfully, thanks a ton.