[QUOTE=Stillnex;36462230]How can I get all the files from a folder? I tried doing:
[lua]
local cmdsfiles = file.FindInLua("../../commands" .. "*.lua")
[/lua]
but I'm not sure if it is right because the table returns empty...
the folder structures are this:
The init.lua folder:
\addons\MyAddon\lua\autorun\server\
The folder I want to get the files from:
\addons\MyAddon\lua\commands
am I doing it wrong?[/QUOTE]
Why are you going up 2 folders? Just do
[lua]
local cmdsfiles = file.FindInLua("commands/*.lua")
[/lua]
So I have this very basic third person camera, that activates when I enter a vehicle, and deactivates when I leave it. I need the view angle to be independent of the vehicle's orientation, if you get what I mean. Imagine the vehicle's orientation is flat, the camera rotates nicely around the player in the vehicle. I need the camera to act this same way regardless of how the vehicle is rotated(its easier to understand what I am talking about if you try this script for yourself, rotate the chair and get in). Anyone have any ideas?
[lua]
local Active = false
local Distance = 200
local Origin = Vector(0,0,50)
hook.Add("CalcView", "thirdPerson", function(ply, pos, angles, fov)
if ply:InVehicle() then
Active = true
local view = {}
view.origin = (pos + Origin) - angles:Forward()*Distance
view.angles = angles
view.fov = fov
return view
else
Active = false
end
end)
hook.Add("ShouldDrawLocalPlayer", "ShouldDrawLocalPlayer", function(ply)
return Active
end)
[/lua]
Using Drakehawk's example [url]http://facepunch.com/showthread.php?t=1160598&p=34534468&viewfull=1#post34534468[/url]
Here's the code [url]http://codepad.org/WC5pXHQ7[/url]
My problem is, whenever it spawns, it is unaffected by props (They fall through) and there's collisions below the rendered props. Is there a better way of freezing these props?
If you want to fix the unaffected by props part, use ent:PhysWake() I think when you spawn it.
Are you sure it's running server-side? Also you don't need PhysicsInit with prop_physics
How does sending an entity over the network with the net library work internally? Does net.WriteEntity send the EntIndex of the entity and net.ReadEntity get the entity related to the EntIndex?
What would be more optimized, this ...
[lua]
--Server side.
net.WriteLong( ent:EntIndex() )
--Client side.
local ent = Entity( net.ReadLong() )
[/lua]
... or this?
[lua]
--Server side.
net.WriteEntity( ent )
--Client side.
local ent = net.ReadEntity()
[/lua]
[QUOTE=Panto;36496549]How does sending an entity over the network with the net library work internally? Does net.WriteEntity send the EntIndex of the entity and net.ReadEntity get the entity related to the EntIndex?
What would be more optimized, this ...
[lua]
--Server side.
net.WriteLong( ent:EntIndex() )
--Client side.
local ent = Entity( net.ReadLong() )
[/lua]
... or this?
[lua]
--Server side.
net.WriteEntity( ent )
--Client side.
local ent = net.ReadEntity()
[/lua][/QUOTE]
It sends the EntIndex of the entity.
[QUOTE=ralle105;36495406]Are you sure it's running server-side? Also you don't need PhysicsInit with prop_physics[/QUOTE]
It's in the directory addons\autostartbase\lua\autorun\server.
Using ent:PhysWake() did not affect it in any way
I did some testing and it seems the physics object is moving even though the prop appears to be frozen (pretty sure this is a bug)
Anyways to fix it simply disable motion on the physics object.
[QUOTE=ralle105;36497847]I did some testing and it seems the physics object is moving even though the prop appears to be frozen (pretty sure this is a bug)
Anyways to fix it simply disable motion on the physics object.[/QUOTE]
This fixed it. Thank you very much!
EDIT:
Another Question. How do I call the function ENT:Touch() when I'm just running lua_openscript?
Is there a proper way to call a function from JavaScript to gLua? I found [URL="http://www.facepunch.com/threads/1110722"]this[/URL] and while it's a great idea, it seems really hacky..
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexc723-3.html?title=Entity.PhysicsFromMesh&oldid=53466[/url]
Is this broken?
[QUOTE=BradenFase;36498073]This fixed it. Thank you very much!
EDIT:
Another Question. How do I call the function ENT:Touch() when I'm just running lua_openscript?[/QUOTE]
You just do
[lua]ent:Touch( hitEnt[/lua]
Where ent is the variable storing the entity you wanna call Touch on and hitEnt being the entity that did the touch.
How can I check if my SWEP is aimed at a NPC when I fire it?
I've tried using Player:GetViewEntity( ), but i just retruns player every time?
Can anyone tell me how to get the class of an entity that I aim at?
Thanks
[QUOTE=Bletotum;36507641][url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexc723-3.html?title=Entity.PhysicsFromMesh&oldid=53466[/url]
Is this broken?[/QUOTE]
From my experience the first vertex is always at the center of the entity so I have this theory that you have to start at index 0 of your table. But yeah, just a theory.
[code]
file.Write("data/crashtime.txt",tostring(os.time()))
.....................
local time = file.Read("data/crashtime.txt")
print(time)
print(tonumber(time))
[/code]
Output:
1340798864
nil
what... the... hell.....
help?
I'm guessing you didn't copy that code from your script and that you made a typo and wrote something like tonumber(tiem)
[QUOTE=ralle105;36513734]I'm guessing you didn't copy that code from your script and that you made a typo and wrote something like tonumber(tiem)[/QUOTE]
Nevermind, turns out the file function was adding a newline character at the end of the string.
[QUOTE=Loures;36507732]You just do
[lua]ent:Touch( hitEnt[/lua]
Where ent is the variable storing the entity you wanna call Touch on and hitEnt being the entity that did the touch.[/QUOTE]
Alright, I've modified my code to show something like that.
[url]http://codepad.org/Kha71qle[/url]
No matter what I touch it with it will not remove. Is my code correct?
Try spawning it after you do all the physics stuff. Not sure here, just a guess
[QUOTE=Deadman123;36522418]Try spawning it after you do all the physics stuff. Not sure here, just a guess[/QUOTE]
Didn't fix it.
Still unable to change what happens when it is touched.
[lua]function FakeMove(cmd)
local btn = cmd:GetButtons()
local forward = btn & IN_FORWARD
local back = btn & IN_BACK
btn = btn - forward - back
if forward > 0 then
btn = btn | IN_BACK
end
if back > 0 then
btn = btn | IN_FORWARD
end
cmd:SetButtons(btn)
end
hook.Add("CreateMove", "FakeMove", FakeMove)
[/lua]
I don't get why isn't it working. It's clientside.
[b]edit:[/b]
I got it working.
[lua]cmd:SetForwardMove( -cmd:GetForwardMove() )[/lua]
[QUOTE=awly;36549166][lua]function FakeMove(cmd)
local btn = cmd:GetButtons()
local forward = btn & IN_FORWARD
local back = btn & IN_BACK
btn = btn - forward - back
if forward > 0 then
btn = btn | IN_BACK
end
if back > 0 then
btn = btn | IN_FORWARD
end
cmd:SetButtons(btn)
end
hook.Add("CreateMove", "FakeMove", FakeMove)
[/lua]
I don't get why isn't it working. It's clientside.
[b]edit:[/b]
I got it working.
[lua]cmd:SetForwardMove( -cmd:GetForwardMove() )[/lua][/QUOTE]
Lua doesn't support bitwise operations such as & and |. (Unless this is something new Garry added to gm13)
They've been supported in GMod Lua since the dawn of time.
[QUOTE=Gran PC;36550168]They've been supported in GMod Lua since the dawn of time.[/QUOTE]
... they have?
They have.
I need to draw a rotating model of melon in right upper corner of players screen.
Any ideas how can I do that ?
Try using a [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7401.html]clientside model.[/url]
--
Does anyone know what's up with vgui panels after the source engine update? Someone tweeted garry about it but it wasn't very informative. My scoreboards now really laggy to open and I was wondering if anyone had found what's wrong or how to fix it.
[QUOTE=Drakehawke;36567023]Try using a [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7401.html]clientside model.[/url]
--
Does anyone know what's up with vgui panels after the source engine update? Someone tweeted garry about it but it wasn't very informative. My scoreboards now really laggy to open and I was wondering if anyone had found what's wrong or how to fix it.[/QUOTE]
That's actually none of the help, I know that I can make clientside model and attach it to players head, but it's a tricky way to do it and I was thinking about something better
That isn't the right way to use it. [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0d85.html]DModelPanel[/url] does a similar thing and if you look at the source for that it uses a clientside model. I'd link you to the source but the last update broke luabin.
Sorry, you need to Log In to post a reply to this thread.