Ulysses
General => Developers Corner => Topic started by: tssge on February 15, 2010, 05:58:36 AM
-
So i was thinking of replacing the old jail's props and vectors with other models, but how can i make it a separate module, and what variables do i need to change ? This would be like a big cage, which would have some running room for minges, so they don't get bored, but they get their own little playground.
Notice: I'm a total noob to LUA, but i have done this before, i have converted ulx jail to assmod's jail.
-
Create a folder in addons (ex; addons/ulx_cage)
Create an info.txt in addons/ulx_cage (http://wiki.garrysmod.com/?title=Creating_an_addon)
Create folders in your addons/ulx_cage of lua/ulx/modules
Place your my_cage_codename.lua file in the above mentioned modules.
Place your code in that lua file
You'll need to research on the Garry's mod lua wiki what names you'll need to change, specifically the function name and unique identifiers for the functions. You shouldn't have too difficult a time by looking at the original jail code.
-
Ty, this will give me a start. Very hepfull :D I kinda like your forums ;)
-
Your welcome, and thank you. We're a bit partial to them ourselves. :D
-
I don't like them... I think they yukky.. and JamminR's side of the forums smell funny!
-
I don't like them... I think they yukky.. and JamminR's side of the forums smell funny!
Oops, forgot to clean the cage out. ;)
-
Well, I am doing some work from home today due to icy roads..and I haven't taken my shower.
Now if only I had bunny slippers to wear.
/me sees Megiddo with big spray hose like seen at zoos.
-
Btw, while i make it a separate addon, can i use the original existing ULX hooks ?
-
Well here's the code i made, replaces every jail string with a cage one, don't know if it works, im going to start making it to addon form.
What do you think ? Give me tips how to get it working/improve it.
Notice: My first ever LUA, and my second leeched from another LUAs.
------------------------------ Jail ------------------------------
function ulx.cage( calling_ply, target_plys, seconds, should_uncage ) --Renamed to ulx.cage from ulx.jail and should_unjail to should_uncage
local mdl1 = Model( "models/props_wasteland/interior_fence002d.mdl" ) --Changed mdl1 "models/props_c17/fence01b.mdl" to models/props_wasteland/interior_fence002d.mdl
local mdl2 = Model( "models/props_wasteland/interior_fence002d.mdl" ) --Changed mdl1 "models/props_c17/fence01b.mdl" to models/props_wasteland/interior_fence002d.mdl
local cage = {
{ pos = Vector( 0, 0, 0 ), ang = Angle( -0.032495182007551, -90.190528869629, 0.156479626894 ), mdl=mdl2 }, --All vectors and angles changed, will need to add 2 mroe if these work
{ pos = Vector( 129.97778320313, -127.38626098633, -0.13224792480469 ), ang = Angle( 0.12636932730675, 179.84873962402, 0.025045685470104 ), mdl=mdl2 },
{ pos = Vector( 2.905517578125, -258.35272216797, -0.79289245605469 ), ang = Angle( -3.4093172871508, -90, 5.7652890973259 ), mdl=mdl2 },
{ pos = Vector( -123.9228515625, -127.88626098633, -1.0640182495117 ), ang = Angle( -0.00059019651962444, 179.99681091309, 359.99996948242 ), mdl=mdl2 },
{ pos = Vector( -63.728271484375, -129.30960083008, -63.381893157959 ), ang = Angle( -89.999015808105, -179.42805480957, 180 ), mdl=mdl1 },
{ pos = Vector( 62.65771484375, -131.56051635742, -63.381889343262 ), ang = Angle( -89.999015808105, 179.91276550293, 180 ), mdl=mdl1 },
}
local i = 1
while i <= #target_plys do
local v = target_plys[ i ]
if not should_uncage then
if v.cage then -- They're already jailed
v.cage.uncage()
end
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
table.remove( target_plys, i )
else
if v:InVehicle() then
local vehicle = v:GetParent()
v:ExitVehicle()
vehicle:Remove()
end
if v:GetMoveType() == MOVETYPE_NOCLIP then -- Take them out of noclip
v:SetMoveType( MOVETYPE_WALK )
end
local pos = v:GetPos()
local walls = {}
for _, info in ipairs( cage ) do
local ent = ents.Create( "prop_physics" )
ent:SetModel( info.mdl )
ent:SetPos( pos + info.pos )
ent:SetAngles( info.ang )
ent:Spawn()
ent:GetPhysicsObject():EnableMotion( false )
ent.cageWall = true
table.insert( walls, ent )
end
local key = {}
local function uncage() --Changed unjail to -cage
if not v:IsValid() or not v.cage or v.cage.key ~= key then -- Nope
return
end
for _, ent in ipairs( walls ) do
if ent:IsValid() then
ent:DisallowDeleting( false )
ent:Remove()
end
end
if not v:IsValid() then return end -- Make sure they're still connected
v:DisallowNoclip( false )
v:DisallowSpawning( false )
v:DisallowVehicles( false )
ulx.clearExclusive( v )
ulx.setNoDie( v, false )
v.cage = nil
end
if seconds > 0 then
timer.Simple( seconds, uncage ) --Changed unjail to -cage
end
local function newWall( old, new )
table.insert( walls, new )
end
for _, ent in ipairs( walls ) do
ent:DisallowDeleting( true, newWall )
ent:DisallowMoving( true )
end
v:DisallowNoclip( true )
v:DisallowSpawning( true )
v:DisallowVehicles( true )
v.cage = { pos=pos, uncage=uncage, key=key }
ulx.setExclusive( v, "in cage" )
ulx.setNoDie( v, true )
i = i + 1
end
elseif v.cage then
v.cage.uncage()
v.cage = nil
i = i + 1
else
table.remove( target_plys, i )
end
end
return #target_plys > 0
end
local cage = ulx.command( CATEGORY_NAME, "ulx cage", ulx.cage, "!cage" )
cage:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
cage:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, forever is 0", ULib.cmds.round, ULib.cmds.optional }
cage:addParam{ type=ULib.cmds.BoolArg, invisible=true }
cage:defaultAccess( ULib.ACCESS_ADMIN )
cage:help( "Cages target(s)." )
cage:logString( "#1s caged #2s for #3i seconds" )
cage:setOpposite( "ulx uncage", {_, _, _, true}, "!uncage" )
cage:oppositeLogString( "#1s uncaged #2s" )
ulx.addToMenu( ulx.ID_MCLIENT, "Cage", "ulx cage" )
ulx.addToMenu( ulx.ID_MCLIENT, "Uncage", "ulx uncage" )
local function cageDisconnectedCheck( ply )
if ply.cage then
ply.cage.uncage()
end
end
hook.Add( "PlayerDisconnected", "ULXCageDisconnectedCheck", cageDisconnectedCheck )
-
O-M-G (sorry for speaking alone here :D) i got it working ! My first ever working useful .lua file. Need to add offset vector, and a few mroe models, and it's ready. Ty for your help, .lua is pretty simple. Well half of it is leeched from ulx's own jail, but nvm... :D
-
No worries, modification on existing scripts is a great way to learn. We'll try to answer any questions you may have, just remember to always check the lua docs and reference manuals first for general questions (the documentation for lua is awesome after all).
-
Also remember not to ever edit ULiB/ULX files. Whilst you can, this is not the correct way to do it.
Always make a new module in the addon format just like explained JamminR's first post.
-
I did, and it worked. I only copied the "base" code of mine from the ULX's jail. The Cage is working nicely, i have some more things in there too for the mingebags weapons and so-on...
Perhaps i should release my first script ever, with credits to ULX team ? :P
-
I did, and it worked. I only copied the "base" code of mine from the ULX's jail. The Cage is working nicely, i have some more things in there too for the mingebags weapons and so-on...
Perhaps i should release my first script ever, with credits to ULX team ? :P
Sure, do you know how to get it in addon format?
-
I hope he would. :D
Create a folder in addons (ex; addons/ulx_cage)
Create an info.txt in addons/ulx_cage (http://wiki.garrysmod.com/?title=Creating_an_addon)
Create folders in your addons/ulx_cage of lua/ulx/modules
Place your my_cage_codename.lua file in the above mentioned modules.
Place your code in that lua file
<clip>
Then from addons right click <your addon folder>, select zip/add to archive.
Most zip applications will take the proper folders/files all inclusive
-
With the "I did" i meant i made it an addon yes. Garry's wiki is pretty much helpful, i learned some lua basics there.