Ulysses
General => Developers Corner => Topic started by: Tomis13lack on October 16, 2014, 02:12:53 PM
-
I have been trying to make a ulx command, as i have already made a few, but i d not know how to stack commands. The command is going to be ulx.ggoto, it is going to be able to god you when u goto someone.
Thanks!
-
To me, it seems simple enough to add if/then/ulx.god() or player:GodEnable() to our Goto code in a new function, but, as you've already done some commands, what is simple for me may not be as simple for you.
Where exactly are you stuck?
-
ok so this is what i have so far
function ulx.ggoto( calling_ply, target_ply )
if not calling_ply:IsValid() then
Msg( "You may not step down into the mortal world from console.\n" )
return
end
if ulx.getExclusive( calling_ply, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( calling_ply, calling_ply ), true )
return
end
if not target_ply:Alive() then
ULib.tsayError( calling_ply, target_ply:Nick() .. " is dead!", true )
return
end
if target_ply:Alive() then
Player:GodEnable()
return
end
if not calling_ply:Alive() then
ULib.tsayError( calling_ply, "You are dead!", true )
return
end
if target_ply:InVehicle() and calling_ply:GetMoveType() ~= MOVETYPE_NOCLIP then
ULib.tsayError( calling_ply, "Target is in a vehicle! Noclip and use this command to force a goto.", true )
return
end
local newpos = playerSend( calling_ply, target_ply, calling_ply:GetMoveType() == MOVETYPE_NOCLIP )
if not newpos then
ULib.tsayError( calling_ply, "Can't find a place to put you! Noclip and use this command to force a goto.", true )
return
end
if calling_ply:InVehicle() then
calling_ply:ExitVehicle()
end
local newang = (target_ply:GetPos() - newpos):Angle()
calling_ply:SetPos( newpos )
calling_ply:SetEyeAngles( newang )
calling_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!
ulx.fancyLogAdmin( calling_ply, "#A godded and teleported to #T", target_ply )
end
local goto = ulx.command( CATEGORY_NAME, "ulx ggoto", ulx.ggoto, "!ggoto" )
ggoto:addParam{ type=ULib.cmds.PlayerArg, target="!^", ULib.cmds.ignoreCanTarget }
ggoto:defaultAccess( ULib.ACCESS_ADMIN )
ggoto:help( "God and Goto target." )
it is not working. I added this:
if target_ply:Alive() then
Player:GodEnable()
return
end
-
First, when discussing Gmod code, and one describes a player command like I did, player:GodEnable() ... player is a variable... not a literal statement.
The Gmod wiki uses the word "player" in general, but in code, it's almost always going to be a variable you define, and won't often just be "player"
In our code, we almost always use calling_ply or target_ply. Target_ply, in our code, could be a single player table or multiple player object tables depending on the command object setup.
Meaning, you adding Player:GodEnable() would give you an error. Player doesn't exist.
Second:
You only need to add two lines.
Right before
calling_ply:SetPos( newpos )
calling_ply:SetEyeAngles( newang )
calling_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!
Simply add before these lines;
calling_ply:GodEnable()
calling_ply.ULXHasGod = true --the previous command is a general Gmod command, so we set a player variable to let ULX know the player has god access if ever needed later.