ULX

Author Topic: Starting LUA on ULX  (Read 3209 times)

0 Members and 1 Guest are viewing this topic.

Offline Aqua92

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Starting LUA on ULX
« on: June 16, 2010, 08:44:48 AM »
Hey Guys,
i dont know if some of you remember me. If not, never mind :P

Okay i have a Question. About 2 Years ago i wanted to learn Lua. I wasn't patient enough, i failed.
Now i want to start again.

My first aim on ULX/LUA is a little Player Control Plugin. Like !explode, !slay and others.
It should get the name !rocket <Player>.

What it should do:
Pushing the Player in the air and after about 10 Seccounds he explodes.

Can you maybe give me some hints how to start?
I have experiences with PHP, C++, Java and some other Programming Langauge.


My Idea how it should work:
When Activating the Command, first it checks the Players Rank.
If he's admin, the Action starts.
It takes the Name of the Player and looks on the Server if someone with that Name is online.
If yes -> Getting his current Position and Increasing in a loop his Z-Value (I guess z is up?)
During this Loop, a var starts Counting. If it becomes 200 or something like that -> Kill the Player
If no -> Error Message

Well, i dont know the LUA Syntax yet, but just wanted to know if this idea is... let's say "correct"

I will post my first experiments soon :)

Hope i can finish this little "Project" with your help soon :P

Aqua

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Starting LUA on ULX
« Reply #1 on: June 16, 2010, 01:51:29 PM »
Welcome back.

First, this is NOT to discourage you from learning or making your own rocket command. It's only to let you know that there is a release here where it's been done.
http://forums.ulyssesmod.net/index.php/topic,3955.0.html
You may write your own and learn things/find new features where ahref didn't include.

As for your step logic, it really depends on what version you are writing for.
We recommend writing for SVN version of ULX and ULib. 1) Command structure has been rewritten compared to old 'release' version and therefore 2) will not be compatible with old command structure. and 3) I'm not even sure our release version works any more with all the Gmod updates over the past 2 months.
Some have written releases for both.
The rocket release mentioned above, ahref  wrote for original, vader and I had discussions later converting to the SVN structure. Overall, it's more efficient code wise because your first three steps
Code: [Select]
When Activating the Command, first it checks the Players Rank.
If he's admin, the Action starts.
It takes the Name of the Player and looks on the Server if someone with that Name is online.
can be done just during the command setup.
Our 'release' version, you'd definitely have to check all within the function itself.

Code: [Select]
If yes -> Getting his current Position and Increasing in a loop his Z-Value (I guess z is up?)
During this Loop, a var starts Counting. If it becomes 200 or something like that -> Kill the Player
If no -> Error Message
Pretty sure the loop isn't required, but I guess it could be done that way in small force increments.
To be honest, I'd have to look at ahref's rocket to remember.
« Last Edit: June 16, 2010, 01:53:46 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Aqua92

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: Starting LUA on ULX
« Reply #2 on: June 19, 2010, 05:29:14 AM »
Here we Go :)
My first Lua Ulx Thingie. I simply called it "Test".
Yeah a loop wasn't required. SetVelocity did a well job.

Code: [Select]
local CATEGORY_NAME = "Fun"

function ulx.test( calling_ply, target_plys )

for _, v in ipairs( target_plys ) do

if v:Alive() then
local Playerposition = v:GetPos()
local Targetposition = Playerposition + Vector(0, 0, 3000)
v:SetVelocity(Targetposition)
timer.Simple(3, function()
local vPoint = v:GetPos() + Vector(0,0,10)
local Effekt = EffectData()
Effekt:SetStart( vPoint )
Effekt:SetOrigin( vPoint )
Effekt:SetScale( 1 )
util.Effect( "HelicopterMegaBomb", Effekt )
util.BlastDamage(v, calling_ply, v:GetPos(), 500, 2000)
end)
else
ULib.tsay( calling_ply, v:Nick() .. "Your Victim is already dead!", true )
end
end
end

local test = ulx.command( CATEGORY_NAME, "ulx test", ulx.test, "!test" )
test:addParam{ type=ULib.cmds.PlayersArg }
test:defaultAccess( ULib.ACCESS_ADMIN )
test:help("Pushes <user(s) into the air and killing him")
test:logString( "#1s granted #2s a Freeflight :)" )
ulx.addToMenu( ulx.ID_MCLIENT, "Test", "ulx test" )

Just one Question, "logString" does not work for me. Am i doing something wrong?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Starting LUA on ULX
« Reply #3 on: June 19, 2010, 09:33:39 AM »
Here we Go :)
My first Lua Ulx Thingie. I simply called it "Test".
Yeah a loop wasn't required. SetVelocity did a well job.

Code: [Select]
local CATEGORY_NAME = "Fun"

function ulx.test( calling_ply, target_plys )

for _, v in ipairs( target_plys ) do

if v:Alive() then
local Playerposition = v:GetPos()
local Targetposition = Playerposition + Vector(0, 0, 3000)
v:SetVelocity(Targetposition)
timer.Simple(3, function()
local vPoint = v:GetPos() + Vector(0,0,10)
local Effekt = EffectData()
Effekt:SetStart( vPoint )
Effekt:SetOrigin( vPoint )
Effekt:SetScale( 1 )
util.Effect( "HelicopterMegaBomb", Effekt )
util.BlastDamage(v, calling_ply, v:GetPos(), 500, 2000)
end)
else
ULib.tsay( calling_ply, v:Nick() .. "Your Victim is already dead!", true )
end
end
end

local test = ulx.command( CATEGORY_NAME, "ulx test", ulx.test, "!test" )
test:addParam{ type=ULib.cmds.PlayersArg }
test:defaultAccess( ULib.ACCESS_ADMIN )
test:help("Pushes <user(s) into the air and killing him")
test:logString( "#1s granted #2s a Freeflight :)" )
ulx.addToMenu( ulx.ID_MCLIENT, "Test", "ulx test" )

Just one Question, "logString" does not work for me. Am i doing something wrong?

return true from the function to log.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Starting LUA on ULX
« Reply #4 on: June 19, 2010, 11:02:10 AM »
return true from the function to log.
In other words aqua, depending on how you want it to log.
If you want it to log ONLY if the lift was successful
Code: [Select]
     util.BlastDamage(v, calling_ply, v:GetPos(), 500, 2000)
         end)
      return true -- <-------------------- Player got lifted, log that the admin did it to the player.
      else
         ULib.tsay( calling_ply, v:Nick() .. "Your Victim is already dead!", true )
      end
   end

But if you want it logged whether or not player got lifted or was dead and command ran successfully.
Code: [Select]
     util.BlastDamage(v, calling_ply, v:GetPos(), 500, 2000)
         end)
      else
         ULib.tsay( calling_ply, v:Nick() .. "Your Victim is already dead!", true )
      end
      return true -- <-------------------- Command ran, admin tried, whether player was dead or not.
   end
« Last Edit: June 19, 2010, 11:03:57 AM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming