Skip to content

Commit 031b4b9

Browse files
authored
Fix setpos_methods example (#2233)
* Update setpos_methods.lua
1 parent 4a84517 commit 031b4b9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lua/starfall/examples/setpos_methods.lua

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--@author Neatro
33
--@server
44

5-
if not hasPermission( "entities.setPos", owner() ) then
5+
if not hasPermission( "entities.setPos", chip() ) then
66
throw( "You need Entities permission to see this example code! Enable permission entities.setpos" )
77
end
88

@@ -25,7 +25,7 @@ The greenbox has setPos on the physicsObject.
2525

2626
-- Ignore this bit, it's for creating the prop
2727
local function create( c )
28-
p = prop.create( Vector(0), Angle(0), "models/props_junk/wood_crate001a.mdl", 1 )
28+
p = prop.create( Vector(0), Angle(0), "models/props_junk/wood_crate001a.mdl", true )
2929
p:setColor( c )
3030
return p
3131
end
@@ -41,27 +41,23 @@ hook.add( "tick", "runtime", function()
4141
-- Spawns prop when it doesn't exist
4242

4343
-- If the prop exists, setPos to the movement else try and respawn it
44-
if normal and normal:isValid() then
44+
if isValid( normal ) then
4545
-- This is setpos WITHOUT getting the entities getPhysicsObject()
4646
-- There is NO interpolation!
4747
normal:setPos( motion )
48-
else
49-
if prop.canSpawn() then
50-
normal = create( Color( 255, 0, 0, 255) )
51-
end
48+
elseif prop.canSpawn() then
49+
normal = create( Color( 255, 0, 0, 255) )
5250
end
5351

5452
-- Movement code
5553
motion = motion + Vector( 0, 0, 48 )
5654

5755
-- If the prop exists, set the physobj position to the movement else try and respawn it
58-
if smooth and smooth:isValid() and smooth:isValidPhys() then
56+
if isValid( smooth ) and smooth:isValidPhys() then
5957
-- This is setpos With getting the entities getPhysicsObject()
6058
-- Interpolation will work!
6159
smooth:getPhysicsObject():setPos( motion )
62-
else
63-
if prop.canSpawn() then
64-
smooth = create( Color( 0, 255, 0, 255) )
65-
end
60+
elseif prop.canSpawn() then
61+
smooth = create( Color( 0, 255, 0, 255) )
6662
end
6763
end)

0 commit comments

Comments
 (0)