ULX

Author Topic: Help with a ulx command - adding God to Goto  (Read 3470 times)

0 Members and 1 Guest are viewing this topic.

Offline Tomis13lack

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Help with a ulx command - adding God to Goto
« 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!
« Last Edit: October 16, 2014, 05:42:30 PM by JamminR »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with a ulx command - adding God to Goto
« Reply #1 on: October 16, 2014, 05:42:08 PM »
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?

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Tomis13lack

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Help with a ulx command - adding God to Goto
« Reply #2 on: October 16, 2014, 06:48:01 PM »
ok so this is what i have so far

Code: [Select]
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:

Code: [Select]
if target_ply:Alive() then
Player:GodEnable()
return
end

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with a ulx command - adding God to Goto
« Reply #3 on: October 17, 2014, 10:25:03 PM »
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
Code: [Select]
calling_ply:SetPos( newpos )
calling_ply:SetEyeAngles( newang )
calling_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!

Simply add before these lines;
Code: [Select]
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming