General > Developers Corner
Unsure how to make my code a module(+command) for ULX
Stickly Man!:
--- Code: ---if SERVER then
AddCSLuaFile( "rollthedice.lua" )
end
--- End code ---
This bit of code is not needed-- ULX will automatically add the file since you put it in the /modules/sh folder.
--- Code: ---ulx.addToMenu( ulx.ID_MCLIENT, "Roll The Dice", "ulx rtd" )
--- End code ---
Unless I'm mistaken, this line of code is no longer needed now that we're using XGUI. (XGUI gets the registered commands automatically)
And lastly, to test if the script is actually loading, try putting a print statement before the hook.add, and see if you can see the message in your server/client console:
--- Code: ---print("Is it working!!?/1!?1?1?")
hook.Add( "TTTBeginRound", "ResetRTDPerRound", ResetRTDPerRound )
--- End code ---
EDIT: Also, you may need to add this line of code to make sure that everyone has access to your ULX command by default:
--- Code: ---rtd:defaultAccess( ULib.ACCESS_ALL )
--- End code ---
You can always look at our lua files to see examples of how ULX commands work, slap and psay are examples I've been looking at for reference:
http://ulyssesmod.net/ulx/trunk/lua/ulx/modules/sh/chat.lua
http://ulyssesmod.net/ulx/trunk/lua/ulx/modules/sh/fun.lua
JamminR:
--- Quote from: Stickly Man! on December 20, 2011, 08:29:22 AM ---
--- Code: ---ulx.addToMenu( ulx.ID_MCLIENT, "Roll The Dice", "ulx rtd" )
--- End code ---
Unless I'm mistaken, this line of code is no longer needed now that we're using XGUI. (XGUI gets the registered commands automatically)
--- End quote ---
Indeed. That code bit is left over from pre ULX 3.5 days.
Setting up the object with ulx.command, along with the <object>:help sets it in menus, both text/console (ulx help) and in XGUI.
By the way, this is looking quite fun. Good 'first' project for a conversion. Good way to learn Lua, and ULX/ULib structures.
RandomGamer342:
--- Quote from: Stickly Man! on December 20, 2011, 08:29:22 AM ---And lastly, to test if the script is actually loading, try putting a print statement before the hook.add, and see if you can see the message in your server/client console:
--- Code: ---print("Is it working!!?/1!?1?1?")
hook.Add( "TTTBeginRound", "ResetRTDPerRound", ResetRTDPerRound )
--- End code ---
--- End quote ---
I did that, but it doesn't actually print anything(so it isn't being loaded)
RandomGamer342:
Bump, would there be any reason for the following code not to get loaded as a module when it's in the modules/sh folder?
--- Code: -----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." )
rtd:defaultAccess( ULib.ACCESS_ALL )
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 ---
Aaron113:
--- Code: -----The RTD function itself
function ulx.rollthedice( ply )
--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
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." )
rtd:defaultAccess( ULib.ACCESS_ALL )
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 ---
I believe I got it into a working state.
Navigation
[0] Message Index
[*] Previous page
Go to full version