[QUOTE=HyperShifter;46916143]Go onto your server. Lua > Autorun > Server > Make a file called 'insertnamehere.lua'
The addons you want to use resource.AddWorkshop on, just get the number id from the URL.
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=198142365[/url]
The one for this would be '198142365'
Then just do resource.AddWorkshop('198142365') in the file. :)
I might be a bit wrong on some places so you will have to double check.[/QUOTE]
That's the long way, I want the Lua way, because I already placed my collection on the server's command line, and I'm using this code:
[lua]
// Workshop FastDL - fastdl.lua
// By GGG KILLER
if SERVER then
local function log(str) MsgN("[FastDL]"..str) file.Append("fastdl_log.txt",str.."\n") end
local function AddAll()
file.Write("fastdl_log.txt","Workshop Collection FastDL Log:\n")
log("Start")
for _, addon in pairs(engine.GetAddons()) do
if tostring(addon.wsid) == "0" then continue end
log(" Adding addon from workshop with the ID "..tostring(addon.wsid))
resource.AddWorkshop(tostring(addon.wsid))
end
resource.AddWorkshop("372767154") -- Added here because of the wsid 0
resource.AddWorkshop("171296570") -- Added here because of the wsid 0
log("Finished")
end
AddAll()
end
[/lua]
[QUOTE=Robotboy655;46913654]It does work, at least with default chatbox. It may not work with custom chatbox.[/QUOTE]
Aw FUCK, I'll test the print with the default chatbox then
[QUOTE=zeaga;46913918]Apparently it returns a number? The fuck?[/QUOTE]
Well, in lua, everything is true and nil is false so whatever
I'm using CalcView to create a top down view (which works perfectly) but how would I go about getting the users mouse position on the screen and converting it to a Vector position in the world. The wiki has a function [url=http://wiki.garrysmod.com/page/gui/ScreenToVector]ScreenToVector[/url] but it just seems to return the a location just above the player's head with the following sample code:
[code]
local tr = util.QuickTrace( LocalPlayer():GetShootPos(), gui.ScreenToVector( gui.MousePos() ), LocalPlayer() )
print( tr.HitPos )
[/code]
Just wondering, how does one actually do interractive 2D3D? Like a pressable button or whatever.
Also been wondering about head bobbing.
[QUOTE=NiandraLades;46913142]Uh, is this actually a thing
[url]http://wiki.garrysmod.com/page/Player/IsTyping[/url]
Tried printing for it, always says false and there's fuck all on it[/QUOTE]
[QUOTE=NiandraLades;46916514]Aw FUCK, I'll test the print with the default chatbox then[/QUOTE]
Simply hook into Start/Begin Chat and End/Finish Chat hooks. Set a variable to true / false depending on the hook then overwrite IsTyping to check for the new variable ( for a different chat-box ).
How would one go about using a hook/ Use override to change the default behavior upon pressing Use on a Chair (Vehicle Class)?
I want to prevent the player from using the chair if certain conditions are not met, as well as modify the position in which they are placed upon exiting the vehicle. Is this something that is possible?
[QUOTE=SeveredSkull;46917914]How would one go about using a hook/ Use override to change the default behavior upon pressing Use on a Chair (Vehicle Class)?
I want to prevent the player from using the chair if certain conditions are not met, as well as modify the position in which they are placed upon exiting the vehicle. Is this something that is possible?[/QUOTE]
Take a look at these hooks:
[url]http://wiki.garrysmod.com/page/GM/CanPlayerEnterVehicle[/url]
[url]http://wiki.garrysmod.com/page/GM/PlayerEnteredVehicle[/url]
[url]http://wiki.garrysmod.com/page/GM/CanExitVehicle[/url]
[url]http://wiki.garrysmod.com/page/GM/PlayerLeaveVehicle[/url]
Those should provide the events to modify whether or not a player can enter a vehicle, what to do if they entered, if they can exit and what to do on exit..
[QUOTE=Acecool;46918431]Take a look at these hooks:
[URL]http://wiki.garrysmod.com/page/GM/CanPlayerEnterVehicle[/URL]
[URL]http://wiki.garrysmod.com/page/GM/PlayerEnteredVehicle[/URL]
[URL]http://wiki.garrysmod.com/page/GM/CanExitVehicle[/URL]
[URL]http://wiki.garrysmod.com/page/GM/PlayerLeaveVehicle[/URL]
Those should provide the events to modify whether or not a player can enter a vehicle, what to do if they entered, if they can exit and what to do on exit..[/QUOTE]
Ah. I was looking in the wrong place then! Wouldn't have expected them to be in the GM table... Figured they were gonna be a part of the Vehicle library but saw nothing related there. Thanks mate!
Is there a hook when a player used a tool?
[url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnProp]SANDBOX:PlayerSpawnProp[/url] is to [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnedProp]SANDBOX:PlayerSpawnedProp[/url]
like
[url=http://wiki.garrysmod.com/page/SANDBOX/CanTool]SANDBOX:CanTool[/url] is to...?
I need this desperately.
Alternatively, is there a way to detect when something has been added to a player's undo list?
[QUOTE=Splatpope;46917139]Well, in lua, everything is true and nil is false so whatever[/QUOTE]
I don't think you understand what my concern was for. That's why this would be a problem.
[QUOTE=RedNinja;46917278]Just wondering, how does one actually do interractive 2D3D? Like a pressable button or whatever.[/QUOTE]
I'd also like to know about this. I tried my hand at 2D3D and got so lost so quickly.
About the collection workshopdl:
[url]https://github.com/demgod/Resource-Extension[/url]
[QUOTE=Neat-Nit;46920225]Is there a hook when a player used a tool?
[url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnProp]SANDBOX:PlayerSpawnProp[/url] is to [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnedProp]SANDBOX:PlayerSpawnedProp[/url]
like
[url=http://wiki.garrysmod.com/page/SANDBOX/CanTool]SANDBOX:CanTool[/url] is to...?
I need this desperately.
Alternatively, is there a way to detect when something has been added to a player's undo list?[/QUOTE]
If there is no hook, you can always just override the undo.Finish() function to run hook.Call() on a custom hook.
I want to make my own custom NPC using the manhack AI, or the rollermine AI, but I don't even know where to start besides the fact nextbot wouldn't work, because it only works for ground NPCs like combine soldiers.
For 3d2d interactive stuff you use util.IntersectRayWithPlane where the plane is your 3d screen and the ray is the user's aim. It will give you the point where the user is aiming on the screen IN THE WORLD. You then convert that point to be relative to the top left of your 3d screen, then convert that point into 2d screen coordinates.
Is there a way to stop screen shaking caused by heavy props with lua?
[QUOTE=zeaga;46920577]I don't think you understand what my concern was for. That's why this would be a problem.
[/QUOTE]
Yeah, wiki is bonkers, watevs
Does anyone know if [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Panel/Dock"]Panel:Dock[/URL] is able to do something like PANEL:Dock(BOTTOM+RIGHT), or is it strictly only able to dock something to one constraint? Looking at the enums for it, it doesn't seem so. Are there any alternatives other than manually sizing and placing if this is the case?
[QUOTE=Revenge282;46928788]Does anyone know if [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Panel/Dock"]Panel:Dock[/URL] is able to do something like PANEL:Dock(BOTTOM+RIGHT), or is it strictly only able to dock something to one constraint? Looking at the enums for it, it doesn't seem so. Are there any alternatives other than manually sizing and placing if this is the case?[/QUOTE]
Not that I know about, I'd just dock to bottom and SetWide and SetTall to make it fit.
[QUOTE=Neat-Nit;46920225]Is there a hook when a player used a tool?
[url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnProp]SANDBOX:PlayerSpawnProp[/url] is to [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnedProp]SANDBOX:PlayerSpawnedProp[/url]
like
[url=http://wiki.garrysmod.com/page/SANDBOX/CanTool]SANDBOX:CanTool[/url] is to...?
I need this desperately.
Alternatively, is there a way to detect when something has been added to a player's undo list?[/QUOTE]
CanTool should be sufficient. Here's the source to the toolgun uses, maybe it will help you. I think most prop protection mods do use the undo system to track entities created via tools.
[lua]
function SWEP:PrimaryAttack()
local mode = self:GetMode()
local tr = util.GetPlayerTrace( self.Owner )
tr.mask = bit.bor( CONTENTS_SOLID, CONTENTS_MOVEABLE, CONTENTS_MONSTER, CONTENTS_WINDOW, CONTENTS_DEBRIS, CONTENTS_GRATE, CONTENTS_AUX )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
local tool = self:GetToolObject()
if ( !tool ) then return end
tool:CheckObjects()
-- Does the server setting say it's ok?
if ( !tool:Allowed() ) then return end
-- Ask the gamemode if it's ok to do this
if ( !gamemode.Call( "CanTool", self.Owner, trace, mode ) ) then return end
if ( !tool:LeftClick( trace ) ) then return end
self:DoShootEffect( trace.HitPos, trace.HitNormal, trace.Entity, trace.PhysicsBone, IsFirstTimePredicted() )
end
function SWEP:SecondaryAttack()
local mode = self:GetMode()
local tr = util.GetPlayerTrace( self.Owner )
tr.mask = bit.bor( CONTENTS_SOLID, CONTENTS_MOVEABLE, CONTENTS_MONSTER, CONTENTS_WINDOW, CONTENTS_DEBRIS, CONTENTS_GRATE, CONTENTS_AUX )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
local tool = self:GetToolObject()
if ( !tool ) then return end
tool:CheckObjects()
-- Ask the gamemode if it's ok to do this
if ( !tool:Allowed() ) then return end
if ( !gamemode.Call( "CanTool", self.Owner, trace, mode ) ) then return end
if ( !tool:RightClick( trace ) ) then return end
self:DoShootEffect( trace.HitPos, trace.HitNormal, trace.Entity, trace.PhysicsBone, IsFirstTimePredicted() )
end
function SWEP:Reload()
-- This makes the reload a semi-automatic thing rather than a continuous thing
if ( !self.Owner:KeyPressed( IN_RELOAD ) ) then return end
local mode = self:GetMode()
local tr = util.GetPlayerTrace( self.Owner )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
local tool = self:GetToolObject()
if ( !tool ) then return end
tool:CheckObjects()
-- Does the server setting say it's ok?
if ( !tool:Allowed() ) then return end
-- Ask the gamemode if it's ok to do this
if ( !gamemode.Call( "CanTool", self.Owner, trace, mode ) ) then return end
if ( !tool:Reload( trace ) ) then return end
self:DoShootEffect( trace.HitPos, trace.HitNormal, trace.Entity, trace.PhysicsBone, IsFirstTimePredicted() )
end
[/lua]
Here's what nadmod pp does
[lua]
-- Hook into the cleanup and sbox-limit adding functions to catch most props
if(cleanup) then
local backupcleanupAdd = cleanup.Add
function cleanup.Add(ply, enttype, ent)
if IsValid(ent) and ply:IsPlayer() then
NADMOD.PlayerMakePropOwner(ply, ent)
end
backupcleanupAdd(ply, enttype, ent)
end
end
if(metaply.AddCount) then
local backupAddCount = metaply.AddCount
function metaply:AddCount(enttype, ent)
NADMOD.PlayerMakePropOwner(self, ent)
backupAddCount(self, enttype, ent)
end
end
[/lua]
[editline]14th January 2015[/editline]
[QUOTE=thegrb93;46927937]Is there a way to stop screen shaking caused by heavy props with lua?[/QUOTE]
I found the console command "collision_shake_time 0" I guess this will suffice for now.
I can't figure this out, my functions shall remain nil forever. Maybe someone can help me out?
CreateMSensorScreen is turning up nil
[quote=Developer's Console][ERROR] lua/autorun/client/diskcircle.lua:145: attempt to call global 'CreateMSensorScreen' (a nil value)
1. v - lua/autorun/client/diskcircle.lua:145
2. unknown - lua/includes/modules/hook.lua:84[/quote]
I really didn't want to share ALL of my code, but it may be the only way anyone could help me out here. Maybe the error is located somewhere I haven't even considered. That is all of the error code I get, not more, not less.
[code]local function CreateCircleTop( x, y, rad, ang, start )
local x, y, rad = x, y, rad
local ang = ang or 360
local circle = circle or {}
table.Empty( circle )
table.insert( circle, 1, { x = x + 0, y = y + 0 } )
for ind = 2, 92 do
local xCoord, yCoord = x, y
if ang + 2 > (ind)*2 then
local ANG = (ind)*2
local sin, cos = math.sin( math.rad( ANG+90+start ) ), math.cos( math.rad( ANG+90+start ) )
xCoord = x+rad*cos
yCoord = y+rad*sin
-- print( "ang "..ang )
-- print( "ANG "..ANG )
-- print( "xCoord "..xCoord )
-- print( "yCoord "..yCoord )
end
if ang + 2 > (ind)*2 then
table.insert( circle, (ind), { x = xCoord, y = yCoord } )
end
end
-- print( #circle.." Circle" )
return circle
end
local function CreateCircleBot( x, y, rad, ang, start )
local x, y, rad = x, y, rad
local ang = ang or 360
ang = ang - 180
local circle = circle or {}
table.Empty( circle )
table.insert( circle, 1, { x = x + 0, y = y + 0 } )
for ind = 2, 92 do
local xCoord, yCoord = x, y
if ang + 2 > (ind)*2 then
local ANG = (ind)*2
local sin, cos = math.sin( math.rad( ANG-90+start ) ), math.cos( math.rad( ANG-90+start ) )
xCoord = x+rad*cos
yCoord = y+rad*sin
-- print( "ang "..ang )
-- print( "ANG "..ANG )
-- print( "xCoord "..xCoord )
-- print( "yCoord "..yCoord )
end
if ang + 2 > (ind)*2 then
table.insert( circle, (ind), { x = xCoord, y = yCoord } )
end
end
-- print( #circle.." Circle" )
return circle
end
local function CreateCenterCircle( x, y, rad )
local x, y, rad = x, y, rad
local circle = circle or {}
table.Empty( circle )
for vrt = 1, 179 do
local xCoord, yCoord = 0, 0
local sin, cos = math.sin( math.rad( vrt*2 ) ), math.cos( math.rad( vrt*2 ) )
xCoord = x+rad*cos
yCoord = y+rad*sin
table.insert( circle, vrt, { x = xCoord, y = yCoord } )
end
return circle
end
local InitTime = CurTime()
local function DISK()
local x, y = ScrH()*0.32, ScrH()*0.86
InitTime = InitTime or CurTime()
local DTime = (CurTime()-InitTime)
-- if 2*DTime > 4 then InitTime = CurTime() end
-- print( " " )
-- print( math.min(1,(CurTime()-InitTime)).." you know" )
-- print( " " )
-- print( x.." "..y )
-- print( " " )
local baseRadAdd = baseRadAdd or .03--+.05*math.min(1,1.3*DTime)
baseRadAdd = Lerp( math.max(.01,.5-math.min(1,DTime*DTime)), baseRadAdd, .08 )
local ang = math.min(1,2*DTime)*363
local rad = math.min(1,2*DTime)*(ScrH()*.08) +(ScrH()*baseRadAdd)
local radb = math.min(1,2*DTime)*(ScrH()*.0725) +(ScrH()*baseRadAdd)
local ang2 = math.min(1,2*DTime)*363
local rad2 = math.min(1,4*DTime)*(ScrH()*.085) +(ScrH()*baseRadAdd)
local rad3 = math.min(1,4*(DTime-.5))*(ScrH()*.0725) +(ScrH()*baseRadAdd)
local start = math.min(1,2*DTime) * -180
surface.SetDrawColor( 0, 64, 128, 255*DTime*4 )
surface.DrawPoly( CreateCircleTop( x, y, rad2, ang2, start ) )
surface.DrawPoly( CreateCircleBot( x, y, rad2, ang2, start ) )
surface.SetDrawColor( 0, 80, 160, 255*DTime*2 )
surface.DrawPoly( CreateCircleTop( x, y, rad, ang, start ) )
surface.DrawPoly( CreateCircleBot( x, y, rad, ang, start ) )
-- if DTime < .75 then
-- surface.SetDrawColor( 0, 16, 32, 255*DTime*2 )--
surface.SetDrawColor( 0, 96*(1-math.min(.666,DTime*2)), 192*(1-math.min(.666,DTime*2)), 255*DTime*2 )--
surface.DrawPoly( CreateCircleTop( x, y, radb, ang, start ) )
surface.DrawPoly( CreateCircleBot( x, y, radb, ang, start ) )
-- end
if DTime > .6 then
CreateMSensorScreen( x, y, radb, DTime )
end
-- surface.SetDrawColor( 0, 0, 0, 255*(DTime-.5)*4 )
-- surface.DrawPoly( CreateCenterCircle( x, y, rad3 ) )
end
local RTTex = GetRenderTarget( "MotionSensorScreen", 256, 256 )
local RTScrnTex = Material( "conhud/motion/render" )
local OurBG = Material( "conhud/motion/background" )
local Circl = Material( "conhud/motion/circle" )
local Tring = Material( "conhud/motion/triangle" )
local Cross = Material( "conhud/motion/cross" )
local InitTimeScreen = nil
local function CreateMSensorScreen( x, y, r, t ) -- (line 148)
InitTimeScreen = InitTimeScreen or CurTime()
if !InitTimeScreen then return end
local DTime = CurTime() - InitTimeScreen
DTime = DTime * DTime * 4
-- if t > 2 then InitTimeScreen = nil end
local Dimension = 256
local oldW = ScrW()
local oldH = ScrH()
RTScrnTex:SetTexture( "$basetexture", RTTex )
local LastRT = render.GetRenderTarget()
local FadeTables = FadeTables or {}
render.SetRenderTarget( RTTex )
render.SetViewPort( 0, 0, Dimension, Dimension )
cam.Start2D()
-- cam.IgnoreZ( true )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( OurBG )
surface.DrawTexturedRect( 0, 0, Dimension, Dimension )
for k, v in ipairs( FindSensorEnts() ) do
local colr = v[1]
local post = v[2]
local size = v[3]
local Type = v[4] -- 1 = Triangle, 2 = Cross, Other = Circle
local Indx = v[5]
-- local ETim = v[ Indx ]
local Move = v[6]
-- local DTimeEntry = CurTime() - ETim
local EAlpha = 0
if Move then
EAlpha = 255
else
EAlpha = 0
end
if !FadeTables[Indx] then FadeTables[Indx] = 0 end
FadeTables[Indx] = Lerp( FrameTime(), FadeTables[Indx], EAlpha )
surface.SetDrawColor( colr[1], colr[2], colr[3], FadeTables[Indx] )
if Type == 1 then
surface.SetMaterial( Tring )
elseif Type == 2 then
surface.SetMaterial( Cross )
else
surface.SetMaterial( Circl )
end
surface.DrawTexturedRect( post[1]-size*.5, post[2]-size*.5, size, size )
end
-- cam.IgnoreZ( false )
cam.End2D()
render.SetRenderTarget( LastRT )
render.SetViewPort( 0, 0, oldW, oldH )
if 255*math.min(1,DTime) < 255 then
local FlatColor = { r=0, g=0, b=0, a=(255*math.min(1,DTime)) }
surface.SetDrawColor( FlatColor )
surface.DrawPoly( CreateCenterCircle( x, y, r ) )
else
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( GetRenderTarget( "MotionSensorScreen", 256, 256 ) )
surface.DrawPoly( UVCircle( x, y, r ) )
end
end
local function UVCircle( x, y, rad ) -- (line 231)
local circle = {}
for i = 1, 180 do
local xCoord, yCoord = x, y
local sin, cos = math.sin( math.rad( i*2 ) ), math.cos( math.rad( i*2 ) )
xCoord = x+rad*cos
yCoord = y+rad*sin
uCoord = (cos+1)/2
vCoord = (sin+1)/2
-- print( "xCoord "..xCoord )
-- print( "yCoord "..yCoord )
table.insert( circle, (i), { x = xCoord, y = yCoord, u = uCoord, v = vCoord } )
end
return circle
end
local function FindSensorEnts() -- (line 255)
local Entries = {}
-- local EntryTimes = {}
local LPP = LocalPlayer():GetPos()
local SensorEnts = ents.FindInBox( LPP-Vector(400,400,8192), LPP+Vector(400,400,8192) )
for k, v in pairs( SensorEnts ) do
if !v:IsValid() || !IsEntity(v) then continue end
local EPos = { v:GetPos().x, v:GetPos().y }
local size = (((v:OBBMaxs().x - v:OBBMins().x) + (v:OBBMaxs().y - v:OBBMins().y))/2)/400
local blipcolor = Color(128,0,255)
if v:IsNPC() then
if IsFriendEntityName(v:GetClass()) then
blipcolor = Color(255,255,0)
else
blipcolor = Color(255,0,0)
end
if string.match( v:GetClass(), "vortigaunt" ) then
blipcolor = Color(192,255,0)
end
elseif v:IsPlayer() then
blipcolor = team.GetColor( v:Team() )
elseif v:IsVehicle() then
bli
It's out of scope because you defined it locally after another function which attempts to use it.
How do I assign a unique ID to an entity? For example when I needed to do it with players I did
[lua]ply:SetNWInt("Num_"..ply:SteamID64(),25)[/lua]
How do I do it with entities? I don't want to use their ID or whatever as it may change.
EntIndex
[QUOTE=arcaneex;46933124]EntIndex[/QUOTE]
Can't it change when new ents are added?
[QUOTE=RedNinja;46933332]Can't it change when new ents are added?[/QUOTE]
Why don't you test and figure out? Takes a few seconds.
What's the most inexpensive way to prevent "MySQL server has gone away" with MySQLoo, I've been looking and apparently the status command freezes the server until it receives a response? Is there no better way of reconnecting to the database when connection is lost.
[QUOTE=Adzter;46933583]What's the most inexpensive way to prevent "MySQL server has gone away" with MySQLoo, I've been looking and apparently the status command freezes the server until it receives a response? Is there no better way of reconnecting to the database when connection is lost.[/QUOTE]
Use the SET command to alter the timeout if you have the privileges, if you can't then you're probably best off sending a SELECT 1+1; query every X seconds so that you keep the connection alive.
Is there a way to prevent the ragdoll created with ply:CreateRagdoll() from getting removed when the player respawns?
Does anyone know if it's possible to use .res files from another game to replace the default HUD and UI in GMod without actually coding the whole HUD/UI with derma?
Sorry, you need to Log In to post a reply to this thread.