RunConsoleCommand

Hi,

I made this script but don’t work, you know why ?

thx for your help


if ply:Team() == TEAM_GIGN then
RunConsoleCommand( nv_toggle_nightvision, 1 ) 
end

is nv_toggle_nightvision a variable? You seem to be treating it as one

[editline]23rd August 2016[/editline]

If it’s meant to be a string it should be



RunConsoleCommand( "nv_toggle_nightvision", 1 ) 


Still, the way you’re enabling nightvision seems a bit exploitable since anyone could run that command… unless that’s what you want

I think using RunConsoleCommand like that would run the console command through the server, where it seems like you want to run it on the player. I think using ply:ConCommand(“nv_toggle_nightvision 1”) would do it.

from this addon http://steamcommunity.com/sharedfiles/filedetails/?id=138163375 it’ is no ?

[editline]23rd August 2016[/editline]

I want for player spawn TEAM_GIGN (retrict for this steam)



hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
	if ply:Team() == TEAM_GIGN then
		ply:ConCommand( "nv_toggle_nightvision 1" ) 
	end
end )


thx work but when I change team is no disable

Because you never made it disable? Just use an else statement

Also, as I said before, the way you’re doing it makes it easy for ANYONE to enable or disable night vision no matter what team they’re on


hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
	if ply:Team() == TEAM_GIGN then
		ply:ConCommand( "nv_toggle_nightvision 1" ) 
         else ply:ConCommand( "nv_toggle_nightvision 0" )
	end
end ) 

Should do it. You get what you pay for…


hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    ply:ConCommand( "nv_toggle_nightvision " .. ply:Team() == TEAM_GIGN and 1 or 0 )
end )

Could also simplify it to this.

ok for restrict another team it’s correct this ?


hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    if (client:IsUserGroup("admin") or client:IsUserGroup("superadmin"))) then
    return true   
	    if ply:Team() == TEAM_GIGN then
		    ply:ConCommand( "nv_toggle_nightvision 1" ) 
            else ply:ConCommand( "nv_toggle_nightvision 0" )
	    end
	end
end )

[editline]23rd August 2016[/editline]

thx man ^^



if (client:IsUserGroup("admin") or client:IsUserGroup("superadmin"))) then
return true  


Firstly, you never specified client, secondly, returning true ends the whole script making nothing after it run, thirdly, you could simplify all that by using IsAdmin, and fourthly, 2 other people already posted working code

[editline]23rd August 2016[/editline]

If you want it to be admin only:



hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    ply:ConCommand( "nv_toggle_nightvision " .. ( ply:Team() == TEAM_GIGN and ply:IsAdmin() ) and '1' or '0' )
end )


this don’t work


hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    ply:ConCommand( "nv_toggle_nightvision " .. ply:Team() == TEAM_GIGN and 1 or 0 )
end )

and this too


hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    ply:ConCommand( "nv_toggle_nightvision " .. ( ply:Team() == TEAM_GIGN and ply:IsAdmin() ) and '1' or '0' )
end )

NightVision is no enable and disable

Then just



hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    if ply:Team() == TEAM_GIGN and ply:IsAdmin() then
        ply:ConCommand( "nv_toggle_nightvision" )
    end
end )


If it’s togglable then that should work unless the player changes teams or it starts off enabled - if so then it’s going to be painful and you’ll probably have to decompile the night vision addon just to figure out what it uses to toggle itself

this code run but if you change team NightVision is not disable and I tested give my rank user but I can use concommand

then I tested this


hook.Add( 'PlayerSpawn', 'NightVision', function( ply )
    if ply:Team() == TEAM_GIGN and ply:IsAdmin() then
        ply:ConCommand( "nv_toggle_nightvision 1" )
		else oldteam == TEAM_GIGN  and ply:IsAdmin() then
	    ply:ConCommand( "nv_toggle_nightvision 0" )
    end
end )

work but user can use too ConCommand nv_toggle_nightvision wtf what is happening

I decompiled addon and I see this


local on = false

concommand.Add("nv_toggle_nightvision", function(ply, cmd, args)
    LocalPlayer():EmitSound(toggle_sound)
	on = not on
end)

No shit

And ?

You mean this command is working for all players. Not matter the rank.



concommand.Add("nv_toggle_nightvision", function(ply, cmd, args)
    if LocalPlayer():IsAdmin() then
    LocalPlayer():EmitSound(toggle_sound)
	on = not on
    else
    end
end)


Also this command added in ClientSide.
Interesting…
Can you link me the addon. maybe I find what is your problem with the permission :slight_smile:

Clean up your code, man. Got a random else statement, and use LocalPlayer() despite the provided player argument.



concommand.Add( "nv_toggle_nightvision", function( ply )
    if ply:IsAdnin() then
        ply:EmitSound( toggle_sound )
        on = not on
    end
end )


This is block for all user ? Maybe my code workind now for restrict for my Team GIGN and admin

Do this on the client, and use actual cvars and not some console command to set a local variable. This is some half assed system.