General > Developers Corner
Unsure how to make my code a module(+command) for ULX
RandomGamer342:
I've been trying to find out how i do it for a while now, but i havent found a detailed explanation. Sorry if it's already been posted.
Essentially, i need the following to be a console command that is registered by ULX(in the same way as for example ulx slap)
Help would be really appreciated.
--- Code: -----The RTD function itself
function RollTheDice( ply, cmd, args)
--Because i'm lazy
local greencolor = Color( 25, 200, 25 )
local whitecolor = Color( 255, 255, 255 )
if( ply.NextRTD and ply.NextRTD > CurTime() ) then
ULib.tsayError( ply, false, "You have to wait before rolling the dice again!")
elseif ply:GetPoints() < 25 then
ULib.tsayError( ply, false, "You dont have enough points!" )
elseif ply:IsSpec() then
ULib.tsayError( ply, false, "You can not roll the dice while being a spectator!" )
else
ply.NextRTD = (CurTime + 300)
ply:TakePoints( 25 )
local Choice = math.random(1, 17)
--Make sure that the second number is the same as the highest choice that can happen. Otherwise it will do nothing but steal your points most of the time.
if Choice == 1 then
ply:Kill()
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was hit by a truck!" )
elseif Choice == 2 then
local HitPoints = math.random(1, 5) * 10
ply:TakeDamage( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " caught a cold and lost "..HitPoints.." health!")
elseif Choice == 3 then
local HitPoints = ply:Health() + 25
ply:SetHealth( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " found a small health vial and got 25 health!")
elseif Choice == 4 then
local HitPoints = ply:Health() + 50
ply:SetHealth( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " found a medkit and got 50 health!")
elseif Choice == 5 then
local HitPoints = ( ply:Health() * 75 ) / 100
ply:TakeDamage( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was hit by lightning!" )
elseif Choice == 6 then
local HitPoints = ( ply:Health() * 25 ) / 100
ply:TakeDamage( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was hit by a crowbar!" )
elseif Choice == 7 then
ply:Give( "weapon_ttt_binoculars" )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " found a toilet roll and started using it as a pair of binoculars!" )
elseif Choice == 8 then
ply:GivePoints( 125 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " won a moderate amount of points!" )
elseif Choice == 9 then
ply:GivePoints( 50 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " won a small amount of points!" )
elseif Choice == 10 then
ply:GivePoints( 275 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " won a huge amount of points!" )
elseif Choice == 11 then
ply:TakePoints( 75 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " lost a moderate amount of points!" )
elseif Choice == 12 then
ply:TakePoints( 25 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " lost a small amount of points!" )
elseif Choice == 13 then
ply:TakePoints( 225 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " lost a huge amount of points!" )
elseif Choice == 14 then
ply:StripWeapons()
if not ply:IsSpec() then
ply:Give("weapon_zm_improvised")
ply:Give("weapon_zm_carry")
ply:Give("weapon_ttt_unarmed")
end
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was robbed by a homeless guy!" )
elseif Choice == 15 then
ply:Ignite( 20, 0 )
if ply:IsSpec() then
ply:Extinguish()
end
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " spontaneously combusted!" )
elseif Choice == 16 then
ply:GodEnable()
timer.Simple( 30, ply:GodDisable, ply )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " suddenly got Chuck Norris mode for 30 seconds!" )
elseif Choice == 17 then
ply:Lock()
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was frozen by a cold breeze!" )
timer.Simple( 30, ply:UnLock, ply )
end
end
end
--- End code ---
There really isn't a lot more than the above, only a failed attempt at making it a command, AddCSLuaFile and a "reset" function for the delay.
JamminR:
Re: Module
See http://forums.ulyssesmod.net/index.php/topic,5432.msg24508.html#msg24508
Re: Command
See http://forums.ulyssesmod.net/index.php/topic,4464.0.html
Start and Read those, ask questions from there
See also http://www.ulyssesmod.net/docs for ULib documentation.
ULX has a little documentation, but it's mostly notes/comments within the lua files themselves.
RandomGamer342:
It doesnt seem to load the script when i put it into modules/sh in the ulx addon
Tried adding a message that should've been printed in regular intervals(when a TTT round starts) yet it doesn't actually do it.
Any tips? Is there anything special i have to do to get it to load the script?
JamminR:
So, its a bit vague to me... you asked in original post about 1) making that function a ULX addon module, and 2) making it (apparently) a ULX command.
I see you added some ULib tsay commands to it ~12/17/2011, but, I see nowhere (at least in your example) an attempt to make it a ULX command.
It won't 'register' as a command without the ULX command setup structure.
And what do you mean intervals? Right now, your code example has nothing that would start it as an interval, and no way for it to start/be run.
As it stands now, it would load in server memory as a function with no way to run it.
Am I missing code?
RandomGamer342:
Oh, sorry, i forgot to update the script in the OP with the one i tried to make.
--- Code: ---if SERVER then
AddCSLuaFile( "rollthedice.lua" )
end
--The RTD function itself
function ulx.rollthedice( calling_ply )
--Because i'm lazy
local greencolor = Color( 25, 200, 25 )
local whitecolor = Color( 255, 255, 255 )
local ply = calling_ply
if( ply.NextRTD and ply.NextRTD > CurTime() ) then
ULib.tsayError( ply, false, "You have to wait before rolling the dice again!")
elseif ply:GetPoints() < 25 then
ULib.tsayError( ply, false, "You dont have enough points!" )
elseif ply:IsSpec() then
ULib.tsayError( ply, false, "You can not roll the dice while being a spectator!" )
else
ply.NextRTD = (CurTime + 300)
ply:TakePoints( 25 )
local Choice = math.random(1, 17)
--Make sure that the second number is the same as the highest choice that can happen. Otherwise it will do nothing but steal your points most of the time.
if Choice == 1 then
ply:Kill()
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was hit by a truck!" )
elseif Choice == 2 then
local HitPoints = math.random(1, 5) * 10
ply:TakeDamage( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " caught a cold and lost "..HitPoints.." health!")
elseif Choice == 3 then
local HitPoints = ply:Health() + 25
ply:SetHealth( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " found a small health vial and got 25 health!")
elseif Choice == 4 then
local HitPoints = ply:Health() + 50
ply:SetHealth( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " found a medkit and got 50 health!")
elseif Choice == 5 then
local HitPoints = ( ply:Health() * 75 ) / 100
ply:TakeDamage( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was hit by lightning!" )
elseif Choice == 6 then
local HitPoints = ( ply:Health() * 25 ) / 100
ply:TakeDamage( HitPoints )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was hit by a crowbar!" )
elseif Choice == 7 then
ply:Give( "weapon_ttt_binoculars" )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " found a toilet roll and started using it as a pair of binoculars!" )
elseif Choice == 8 then
ply:GivePoints( 125 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " won a moderate amount of points!" )
elseif Choice == 9 then
ply:GivePoints( 50 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " won a small amount of points!" )
elseif Choice == 10 then
ply:GivePoints( 275 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " won a huge amount of points!" )
elseif Choice == 11 then
ply:TakePoints( 75 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " lost a moderate amount of points!" )
elseif Choice == 12 then
ply:TakePoints( 25 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " lost a small amount of points!" )
elseif Choice == 13 then
ply:TakePoints( 225 )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " lost a huge amount of points!" )
elseif Choice == 14 then
ply:StripWeapons()
if not ply:IsSpec() then
ply:Give("weapon_zm_improvised")
ply:Give("weapon_zm_carry")
ply:Give("weapon_ttt_unarmed")
end
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was robbed by a homeless guy!" )
elseif Choice == 15 then
ply:Ignite( 20, 0 )
if ply:IsSpec() then
ply:Extinguish()
end
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " spontaneously combusted!" )
elseif Choice == 16 then
ply:GodEnable()
timer.Simple( 30, ply:GodDisable, ply )
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " suddenly got Chuck Norris mode for 30 seconds!" )
elseif Choice == 17 then
ply:Lock()
ULib.tsayColor( nil, false, greencolor, ply:Nick(), whitecolor, " was frozen by a cold breeze!" )
timer.Simple( 30, ply:UnLock, ply )
end
end
end
local rtd = ulx.command("Fun", "ulx rtd", ulx.rollthedice, "!rtd" )
rtd:help( "Feeling lucky? Rolling the dice will run a random command on the user." )
ulx.addToMenu( ulx.ID_MCLIENT, "Roll The Dice", "ulx rtd" )
function ResetRTDPerRound()
for k, v in pairs( player.GetAll() ) do
v.NextRTD = nil
end
ULib.tsayError( nil, "DEBUG: Reset RTD delay for everyone." )
end
hook.Add( "TTTBeginRound", "ResetRTDPerRound", ResetRTDPerRound )
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version