• 2 Questions, about an addon that I would like to make.
    26 replies, posted
First, I would like to know if it would really be any good: It would be a mod with which fast moving large objects would drag nearby objects with it, like wind. Second, is there a way to get the Size of a model? Kind of like when a car drives by and paper flies everywhere, only on a larger scale.
It's a cool idea, but it doesn't have any practical use. You should go forward with it. For the sake of learning. The closest you can get to a "size" is calculating the object's volume from it's bounding box. Though, it won't always be accurate.
Not sure how to get the bounding box, but I'll find out, thanks!
Personally I'd do local BBOX = (ent:OBBMaxs()-ent:OBBMins()) then do BBOX.z and BBOX.x - Just easier imo.
Actually, made this adddon last night using BoundingRadius. [url]http://www.facepunch.com/threads/1018957-Air-dragging-physics?p=25653001[/url]
[QUOTE=Fatman55;25658452]Actually, made this adddon last night using BoundingRadius. [url]http://www.facepunch.com/threads/1018957-Air-dragging-physics?p=25653001[/url][/QUOTE] You could probably factor mass into it too.
Oops, I thought I did, I'll include that in V2
Oh, I didn't look at the code. You just said bounding radius so I assumed you didn't use anything else.
Oh, no that would be stupid, and I did. :v: Here is the code: [code] //You are reading this. function Pull() for k,v in ipairs( ents.GetAll() ) do local physics = v:GetPhysicsObject() if physics:IsValid() then if physics:GetMass() > 200 then if physics:GetVelocity():Length() > 2500 then for k,b in ipairs(ents.FindInSphere(v:GetPos(), v:BoundingRadius() * 2.5)) do local phys = b:GetPhysicsObject() if phys:IsValid() then phys:ApplyForceCenter((physics:GetVelocity() - Vector(400, 400, 400)) * v:GetMass() / 199) end end end end end end end //Think hook. hook.Add("Think", "Pull", Pull) [/code] [editline]26th October 2010[/editline] The ends...
[QUOTE=Fatman55;25658745]Oh, no that would be stupid, and I did. :v: Here is the code: [code]//You are reading this. function Pull() for k,v in ipairs( ents.GetAll() ) do local physics = v:GetPhysicsObject() if physics:IsValid() then if physics:GetMass() > 200 then if physics:GetVelocity():Length() > 2500 then for k,b in ipairs(ents.FindInSphere(v:GetPos(), v:BoundingRadius() * 2.5)) do local phys = b:GetPhysicsObject() if phys:IsValid() then phys:ApplyForceCenter((physics:GetVelocity() - Vector(400, 400, 400)) * v:GetMass() / 199) end end end end end end end //Think hook. hook.Add("Think", "Pull", Pull) [/code] [editline]26th October 2010[/editline] The ends...[/QUOTE] You should try indenting, it works wonders.
No, he should try Lua tags.
[QUOTE=Overv;25660915]No, he should try Lua tags.[/QUOTE] Lua tags are broken for me.
Which browser do you use?
FireFox [editline]26th October 2010[/editline] Let me try: [lua] function doesnotexist() return end() [/lua] [editline]26th October 2010[/editline] See
[QUOTE=Fatman55;25669499]See[/QUOTE] [img]http://localhostr.com/files/0f515d/luatags.png[/img] Works for me.
testing [lua] hello = math.floor(1) function Hello() return true end [/lua] [editline]27th October 2010[/editline] [lua] function test() retrun math.floor() end [/lua] [editline]27th October 2010[/editline] the default fp highlighter seems broken. I was trying to recreate this: [url]http://www.facepunch.com/threads/786778-UtilX-Extending-GLua-Need-community-input?p=18306139&viewfull=1#post18306139[/url] which makes the end on both of his functions pink but the tests I did made it not highlight some keywords though (true and return) [editline]27th October 2010[/editline] [QUOTE=Overv;25660915]No, he should try Lua tags.[/QUOTE] This doesn't work for me anymore in FireFox.
The lua tags should work for you, maybe you should try updating Firefox? Or you could test it in IE or Chrome. Anyways, I took the liberty of indenting and optimizing your code a bit. Seemed like you had a lot more 'if, then' statements then you actually needed. You may want to take a look at this tutorial - [b][url=wiki.garrysmod.com/?title=More_tricks_with_conditions]More tricks with conditions [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [lua]function Pull() for k,v in ipairs( ents.GetAll() ) do local physics = v:GetPhysicsObject() if physics:IsValid() && physics:GetMass() > 200 && physics:GetVelocity():Length() > 2500 then for k,b in ipairs(ents.FindInSphere(v:GetPos(), v:BoundingRadius() * 2.5)) do local phys = b:GetPhysicsObject() if phys:IsValid() then phys:ApplyForceCenter((physics:GetVelocity() - Vector(400, 400, 400)) * v:GetMass() / 199) end end end end end hook.Add("Think", "Pull", Pull)[/lua] [code]function Pull() for k,v in ipairs( ents.GetAll() ) do local physics = v:GetPhysicsObject() if physics:IsValid() && physics:GetMass() > 200 && physics:GetVelocity():Length() > 2500 then for k,b in ipairs(ents.FindInSphere(v:GetPos(), v:BoundingRadius() * 2.5)) do local phys = b:GetPhysicsObject() if phys:IsValid() then phys:ApplyForceCenter((physics:GetVelocity() - Vector(400, 400, 400)) * v:GetMass() / 199) end end end end end hook.Add("Think", "Pull", Pull)[/code]
[lua]local phys local function Pull() for k,v in ipairs( ents.GetAll() ) do phys = v:GetPhysicsObject() if IsValid(phys) && phys:GetMass() > 200 && phys:GetVelocity():Length() > 2500 then for k,b in ipairs(ents.FindInSphere(v:GetPos(), v:BoundingRadius() * 2.5)) do phys = b:GetPhysicsObject() if IsValid(phys) then phys:ApplyForceCenter((phys:GetVelocity() - Vector(400, 400, 400)) * v:GetMass() / 199) end end end end end hook.Add("Think", "Think_PullPhysics", Pull) [/lua] You can move the local phys to line 5 though. I think this kind of optimization make the code look confusing, so you can put local in front of line 8, line 5 and remove line 1 if you want. [editline]27th October 2010[/editline] Hmm, I always thought NULL didn't have an IsValid index. Would be better if NULL would trigger false in a condition in gmod though.
The Lua tags work now, not sure what was wrong.
They worked for me, but then they stopped working. (Overv's)
well OP, you just got the deluxe tutorial
[QUOTE=CapsAdmin;25672486]They worked for me, but then they stopped working. (Overv's)[/QUOTE] I don't know what's wrong. The script randomly doesn't load anymore for me. Greasemonkey says no scripts are installed and Google Chrome just ignores the extension.
I don't have any scripts for the lua tags installed and they work fine. They're just ugly as hell with no highlighting. Maybe try uninstalling the extensions?
[QUOTE=Azur;25679416]I don't have any scripts for the lua tags installed and they work fine. They're just ugly as hell with no highlighting. Maybe try uninstalling the extensions?[/QUOTE] No, my pretty Lua tags don't work. I keep seeing the original ones.
OK, Just posting the new code here(Not Done, Experimenting with distance) [lua] //You are reading this v2. function Pull() for k,v in ipairs( ents.GetAll() ) do local physics = v:GetPhysicsObject() if physics:IsValid() && physics:GetMass() > 1999 && physics:GetVelocity():Length() > 2500 then local rad = v:BoundingRadius() * 2.5 for k,b in ipairs(ents.FindInSphere(v:GetPos(), rad)) do local phys = b:GetPhysicsObject() if phys:IsValid() then phys:ApplyForceCenter((physics:GetVelocity() / (Vector(b:GetPos() - v:GetPos()):Length()) / (rad / 2)) * (physics:GetMass() / 2000)) end end end end end //Think hook hook.Add("Think", "Pull", Pull) [/lua] [editline]27th October 2010[/editline] Also, yes I know it is broken
Make pull() local.
Sorry, you need to Log In to post a reply to this thread.