ULX

I am having issues with my ULX. I have the newest version from the Steam workshop and everything. When using commands it doesn’t check for if the player is dead, frozen, or in a vehicle. A good example of this is the ignite command. It clearly has the code checking if the player is frozen or dead but completely ignores it on execution since anyone can ignite themselves when dead and just kill alive players. Can someone please check if the code is correct?


function ulx.ignite( calling_ply, target_plys, seconds, should_extinguish )
	local affected_plys = {}

	for k,v in pairs( target_plys ) do
		
		if ( not v:Alive() ) then -- Is the player dead?
	
			ULib.tsayError( calling_ply, v:Nick() .. " is dead!", true )
	
		elseif v:IsFrozen() then -- Is the player frozen?
	
			ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )


			if not should_extinguish then
				v:Ignite( seconds )
				v.ulx_ignited_until = CurTime() + seconds
				table.insert( affected_plys, v )
			elseif v:IsOnFire() then
				v:Extinguish()
				v.ulx_ignited_until = nil
				table.insert( affected_plys, v )
			end
		end
	end

	if not should_extinguish then
		ulx.fancyLogAdmin( calling_ply, "#A ignited #T for #i seconds", affected_plys, seconds )
	else
		ulx.fancyLogAdmin( calling_ply, "#A extinguished #T", affected_plys )
	end
end
local ignite = ulx.command( CATEGORY_NAME, "ulx ignite", ulx.ignite, "!ignite" )
ignite:addParam{ type=ULib.cmds.PlayersArg }
ignite:addParam{ type=ULib.cmds.NumArg, min=1, max=300, default=300, hint="seconds", ULib.cmds.optional, ULib.cmds.round }
ignite:addParam{ type=ULib.cmds.BoolArg, invisible=true }
ignite:defaultAccess( ULib.ACCESS_ADMIN )
ignite:help( "Ignites target(s)." )
ignite:setOpposite( "ulx unignite", {_, _, _, true}, "!unignite" )

local function checkFireDeath( ply )
	if ply.ulx_ignited_until and ply.ulx_ignited_until >= CurTime() and ply:IsOnFire() then
		ply:Extinguish()
		ply.ulx_ignited_until = nil
	end
end
hook.Add( "PlayerDeath", "ULXCheckFireDeath", checkFireDeath, HOOK_MONITOR_HIGH )

You should have an else after the frozen check. Currently, the player will only be ignited if they’re frozen.

I added an else and it still isn’t working. I check the command above ignite and that already had an else in it, but when using that command I can also “slay” myself while in spectator aka dead.


function ulx.sslay( calling_ply, target_plys )
	local affected_plys = {}

	for i=1, #target_plys do
		local v = target_plys[ i ]

		if ulx.getExclusive( v, calling_ply ) then
			ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
		elseif not v:Alive() then
			ULib.tsayError( calling_ply, v:Nick() .. " is already dead!", true )
		elseif v:IsFrozen() then
			ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
		else
			if v:InVehicle() then
				v:ExitVehicle()
			end

			v:KillSilent()
			table.insert( affected_plys, v )
		end
	end

	ulx.fancyLogAdmin( calling_ply, "#A silently slayed #T", affected_plys )
end
local sslay = ulx.command( CATEGORY_NAME, "ulx sslay", ulx.sslay, "!sslay" )
sslay:addParam{ type=ULib.cmds.PlayersArg }
sslay:defaultAccess( ULib.ACCESS_ADMIN )
sslay:help( "Silently slays target(s)." )

Check if you count as alive while in spectator – some gamemodes do not set that properly.

How do I check that? My server is running Trouble in Terrorist Town.

Just add return in the end of each exception, it will end function execution. Like this:


if ( not v:Alive() ) then -- Is the player dead?
    ULib.tsayError( calling_ply, v:Nick() .. " is dead!", true )
    return
elseif v:IsFrozen() then -- Is the player frozen?
    ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
    return
end

lua_run print(Entity(1):Alive())

I am still able to ignite myself and sslay myself. :confused: I don’t understand why it’s not working, but it’s also not saying the error message in my chat.

[editline]13th January 2017[/editline]

Sorry, I am not that good with Lua yet, where do you want me to put that in the code?

Server console

> print(Entity(1):Alive())…
true

I am assuming this means that entity 1 (player 1) is alive? I don’t know, but when I typed this I was spectating. Very strange.

I think TTT has a function IsSpectating that you can check as well.

[editline]13th January 2017[/editline]

It’s Player:IsSpec()

What exactly do I type? Sorry I am really bad in this…it’s kind of embarrassing.

try replacing


if ( not v:Alive() )

with


if ( v:Alive() and v:IsSpec() )

Alive because Spectator thinks your alive for some reason.

What he said vvvvvvvvvvvvvv
I assumed it was that because of line 189 of player_ext.lua for TTT
my bad

I think you mean not v:Alive () or not v:IsSpec ().

I have ulxmaster and ulx installed because you need both to work. I edited the ulx one instead of the ulxmaster one and it works now. Your addition with IsSpec helps for sure though! Thank you very much!