General > Developers Corner
Calling a commands function from another addon
kulcris:
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: --- 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
--- End code ---
kulcris:
--- Code: ---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
--- End code ---
This seems to have worked the way i would like it to.
kulcris:
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
bender180:
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.
Stickly Man!:
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.
Navigation
[0] Message Index
[#] Next page
Go to full version