ULX

Author Topic: Calling a commands function from another addon  (Read 2426 times)

0 Members and 1 Guest are viewing this topic.

Offline kulcris

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Calling a commands function from another addon
« on: September 29, 2014, 03:06:40 PM »
I'm currently coding some RTD results and I'm trying to call a command (that i added to ulx) from this other file. how would i go about calling .... For example the ulx.slap function without running a console command. and if that is not possible then how would i call the console command and use it on a player?

(sorry nub at coding)
Code: [Select]
RESULT.Name = "run"
run2b = math.random(.5,2)
runtime = math.random(15,60)

function RESULT:Trigger(ply)
ulx.sprintspeed(ply,run2b*240)
ulx.walkspeed(ply,run2b*220)
timer.Simple(runtime, function()
if (ply and ply:IsValid()) then
ulx.sprintspeed(ply,240)
ulx.walkspeed(ply,220)
ply:ChatPrint("Returned to normal speed.")
RTD:SendColoredChatMessage(ply, "Has returned to their normal speed.")
end
end)
end

function RESULT:ShowMessage(ply)
RTD:BroadcastMessageAboutPlayer(ply, "has been sped up / slowed down by", Color(0, 255, 0), run2b, color_white, " for ", Color(0, 255, 0), runtime, color_white," Seconds ", Color(0, 255, 0))
end

Offline kulcris

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Calling a commands function from another addon
« Reply #1 on: September 29, 2014, 03:27:37 PM »
Code: [Select]
RESULT.Name = "run"
run2b = math.random(2,10)
runtime = math.random(15,60)

function RESULT:Trigger(ply)
local plyname = ply:GetName( )
RunConsoleCommand("ulx", "sprintspeed", plyname, run2b*240)
RunConsoleCommand("ulx", "walkspeed", plyname, run2b*220)
timer.Simple(runtime, function()
if (ply and ply:IsValid()) then
RunConsoleCommand("ulx", "sprintspeed", plyname, 240)
RunConsoleCommand("ulx", "walkspeed", plyname, 220)
ply:ChatPrint("Returned to normal speed.")
RTD:SendColoredChatMessage(ply, "Has returned to their normal speed.")
end
end)
end

function RESULT:ShowMessage(ply)
RTD:BroadcastMessageAboutPlayer(ply, "has been sped up / slowed down by", Color(0, 255, 0), run2b, color_white, " for ", Color(0, 255, 0), runtime, color_white," Seconds ", Color(0, 255, 0))
end

This seems to have worked the way i would like it to.

Offline kulcris

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Calling a commands function from another addon
« Reply #2 on: October 02, 2014, 02:08:20 PM »
run2b = math.random(2,10)
runtime = math.random(15,60)

I moved this into the trigger function so that it runs everytime it is triggered instead of just once the entire up time of the server

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Calling a commands function from another addon
« Reply #3 on: October 02, 2014, 04:13:47 PM »
Not sure if this really answers what your asking but you could just use ulib functions instead of running ulx commands.

Heres the ulib Doc on slap seen as that is the example you used

and here is the full docs

edit: just read your code and i dont think this will really help you at all, sorry.
« Last Edit: October 02, 2014, 04:17:35 PM by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Calling a commands function from another addon
« Reply #4 on: October 14, 2014, 10:44:10 AM »
You might be able to access a reference to the function by checking the ULib.cmds.translatedCmds["ulx slap"] table- I'm pretty sure you can find one there.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline kulcris

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Calling a commands function from another addon
« Reply #5 on: December 28, 2014, 11:37:04 AM »
Sorry for the super late responses sometimes i get something in my head and then forget about it before i can get home and fully tinker with it XD Thank you for responding guys.

As for getting this to work i just needed to run the commands. it may be a bit messy but it seems to have worked