Hey, I need some help figuring out how to freeze weapon entities with either ent:GetPhysicsObject():EnableMotion(false) or ent:GetPhysicsObject():Sleep(), so far I've come with this
[lua]
if SERVER then
hook.Add("InitPostEntity","FreezeProps",function()
for k,v in pairs(ents.GetAll()) do
if (!v:IsWeapon()) then continue; end
v:GetPhysicsObject():EnableMotion(false);
end
end
end[/lua]
but it gives me an error saying it is expecting a ) at the end of the second line, which when added gives me an error about an extra ) at the end. I'm naming it freeze_props.lua and putting it in lua/autorun/server.
What am I doing wrong? Keep in mind that I have little lua knowledge so please go easy on me :3
EDIT: btw thanks to G4MB!T for part of the code.
You never close the parenthesis opened by hook.Add
[QUOTE=Robotboy655;47405910]You never close the parenthesis opened by hook.Add[/QUOTE]
Well I added a ) after (), but then it gives me an error about an extra ) :(
[QUOTE=rikyy;47406052]Well I added a ) after (), but then it gives me an error about an extra ) :([/QUOTE]
No, add it to the second to last end.
[QUOTE=code_gs;47406058]No, add it to the second to last end.[/QUOTE]
[lua]
if SERVER then
hook.Add("InitPostEntity","FreezeProps",function()
for k,v in pairs(ents.GetAll()) do
if (!v:IsWeapon()) then continue; end
v:GetPhysicsObject():EnableMotion(false);
end
end)
end[/lua]
Like that?
EDIT: offtopic but this dude who rated my post dumb, go read the messages on his profile
Yes
[QUOTE=code_gs;47406082]Yes[/QUOTE]
Alright thanks, it fixed the errors but the weapons are not freezing on spawn, what gives?
EnableMotion never worked with weapons as I remember
[editline]28th March 2015[/editline]
[img]http://i.imgur.com/5jIWnEr.png[/img]
Seriously, it doesn't work properly
[video=youtube;xHcwEI8IUSU]http://www.youtube.com/watch?v=xHcwEI8IUSU[/video]
[QUOTE=TheMostUpset;47406428]EnableMotion never worked with weapons as I remember
[editline]28th March 2015[/editline]
[img]http://i.imgur.com/5jIWnEr.png[/img]
Seriously, it doesn't work properly
[video=youtube;xHcwEI8IUSU]http://www.youtube.com/watch?v=xHcwEI8IUSU[/video][/QUOTE]
Are you using the same code they are talking about? Then you are using it wrong... This code is meant for items that are spawned in map, when it loads. For what you are doing now, you would have to use OnEntityCreated hook.
[QUOTE=TheMostUpset;47406428]EnableMotion never worked with weapons as I remember
[editline]28th March 2015[/editline]
[img]http://i.imgur.com/5jIWnEr.png[/img]
Seriously, it doesn't work properly
[video=youtube;xHcwEI8IUSU]http://www.youtube.com/watch?v=xHcwEI8IUSU[/video][/QUOTE]
[img]http://i.imgur.com/zxmtP5M.png[/img]
I guess it checks out (show us your code).
Maybe there's an addon or something, what are other alternatives? What about OnEntityCreate, maybe the gamemode itself creates it and it could work?
[QUOTE=TheMostUpset;47406428]EnableMotion never worked with weapons as I remember
[editline]28th March 2015[/editline]
[img]http://i.imgur.com/5jIWnEr.png[/img]
Seriously, it doesn't work properly
[vI8IUSU]http://www.youtube.com/watch?v=xHcwEI8IUSU[/video][/QUOTE]
All weapons are unfrozen after a certain delay after you spawn the weapon ( Why is beyond me ).
I have already released numerous times my fix I made for my SWEP base:
[code]
function SWEP:AcceptInput( name, activator, caller, data )
if ( name == "ConstraintBroken" && self:HasSpawnFlags( 1 ) ) then
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:EnableMotion( false ) end
local newflags = bit.band( self:GetSpawnFlags(), bit.bnot( 1 ) )
self:SetKeyValue( "spawnflags", newflags )
end
end[/code]
[QUOTE=Robotboy655;47409102]All weapons are unfrozen after a certain delay after you spawn the weapon ( Why is beyond me ).
I have already released numerous times my fix I made for my SWEP base:
[code]
function SWEP:AcceptInput( name, activator, caller, data )
if ( name == "ConstraintBroken" && self:HasSpawnFlags( 1 ) ) then
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:EnableMotion( false ) end
local newflags = bit.band( self:GetSpawnFlags(), bit.bnot( 1 ) )
self:SetKeyValue( "spawnflags", newflags )
end
end[/code][/QUOTE]
Mmmh, I tried that but it gives me an error about indexing global SWEP <a nil value>. I saved that piece of code to freeze_props.lua in autorun/server.
[QUOTE=rikyy;47410811]Mmmh, I tried that but it gives me an error about indexing global SWEP <a nil value>. I saved that piece of code to freeze_props.lua in autorun/server.[/QUOTE]
It's not meant to be used like that, that is added to the SWEP's file itself.
[QUOTE=Robotboy655;47409102]All weapons are unfrozen after a certain delay after you spawn the weapon ( Why is beyond me ).
I have already released numerous times my fix I made for my SWEP base:
[code]
function SWEP:AcceptInput( name, activator, caller, data )
if ( name == "ConstraintBroken" && self:HasSpawnFlags( 1 ) ) then
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:EnableMotion( false ) end
local newflags = bit.band( self:GetSpawnFlags(), bit.bnot( 1 ) )
self:SetKeyValue( "spawnflags", newflags )
end
end[/code][/QUOTE]
You are fucking awesome, it absolutely works!!!
[QUOTE=Newjorciks;47410894]It's not meant to be used like that, that is added to the SWEP's file itself.[/QUOTE]
Yep, that did it. Thank you a lot boys, you can close this or whatever you do with solved threads :D
Sorry, you need to Log In to post a reply to this thread.