 # DropToFloor and Array problem

I am trying to make a new NPC script, but it seems i have 2 problems

When I drop the NPC to the floor with this script:

``````

local NPC = ents.Create("npc_scripted")
NPC:SetModel("models/humans/group01/female_01.mdl");

NPC:SetPos(Vector(-1676.157227, -1201.671143, -90))

NPC:SetAngles(Angle(0,90,0))
NPC:InitializeAnimation(5)
NPC:DropToFloor()

``````

there is still a little space between the floor and the NPC

http://puu.sh/7xsHb.jpg

When I have an array with the NPC position and angle like this:

``````

NPC.PositionAngle  = 	{
Vector(-1676.157227, -1201.671143, -131.968750), Angle(0, 0, 0)
}

``````

and try to retrieve the Vector and Angle with v and v

``````

NPC:SetPos(Vector(v))
NPC:SetAngles(Angle(v))

``````

but I get bad argument #2 to ‘Angle’ (number expected, got userdata)

I’m not 100% sure why your NPC does that so I can’t say.

However, both of the values are already a Vector and an Angle for your second question. You’re trying to do Vector( Vector() ) at the moment. Oops.

Providing you’ve already defined v somewhere else:

``````

NPC:SetPos( v )
NPC:SetAngles( v )

``````

It seems like the    returns the value inside the vector instead of sending it back as a Vector

``````

print("POS: " .. v .. "
")
print("POS: " .. v .. "
")
print("POS: " .. v .. "
")

``````
``````

POS: -1676.1572265625

POS: -1201.6711425781

POS: -131.96875

``````

BTW heres the code I use for the pairs

``````

local PositionAngleTable = NPCTable.PositionAngle

for k, v in pairs(PositionAngleTable) do

local NPC = ents.Create("npc_scripted")
NPC:SetModel("models/humans/group01/female_01.mdl");
NPC:SetPos(v)

NPC:SetAngles(v)

NPC:InitializeAnimation(5)
NPC:DropToFloor()

end

``````

Either way, your v is a vector and v is an angle. In other words you are doing this:

``````

NPC:SetPos(Vector(Vector(-1676.157227, -1201.671143, -90)))
NPC:SetAngles( Angle( Angle( 0, 0, 0) ) )

``````

Just parse v and v without trying to make a new Vector object or Angle object.

[editline]16th March 2014[/editline]

k is not a table, it is the identifier for the corresponding value v in the table PositionAngleTable. You really don’t need a loop here, just do this:

``````

NPC:SetPos(NPCTable.PositionAngle)
NPC:SetAngles(NPCTable.PositionAngle)

``````

It works!!

``````

local PositionAngleTable = NPCTable.PositionAngle

for k, v in pairs(PositionAngleTable) do

local NPC = ents.Create("npc_scripted")
NPC:SetModel("models/humans/group01/female_01.mdl");
NPC:SetPos(NPCTable.PositionAngle)

NPC:SetAngles(NPCTable.PositionAngle)

NPC:InitializeAnimation(5)
NPC:DropToFloor()

end

``````

Thanks for the help.

Now I just need to figure out why the NPC is hanging in the air…

As Dingusnin had mentioned, there is no need for the loop you currently have. If you’re wanting multiple NPCs at different locations you would need to use the pairs loop like this

``````

-- Position Data
NPCTable.PositionAngle = {
-- First NPC properties
{
Vector( 0, 0, 0 ),
Angle( 0, 0, 0 )
},
-- Second NPC properties
{
Vector( 1, 2, 50 ),
Angle( 0, 180, 0 )
}
-- Etcetera
}

-- Loop through each positional data and spawn an NPC
for key, TblValues in ipairs(NPCTable.PositionAngle) do

local NPC = ents.Create("npc_scripted")

NPC:SetModel("models/humans/group01/female_01.mdl");
NPC:SetPos( TblValues )
NPC:SetAngles( TblValues )
NPC:InitializeAnimation(5)
NPC:DropToFloor()

end

``````

Wow…that was the problem

It was missing { } at the beginning and the end in the table, and that was why it was returning the value inside Vector

Now the first code works perfect.

Still weird the NPC cant drop to the floor.

If I recall correctly, if you restarted the idle animation, or something to do with just activating the actor, then it would solve the problem. Try physgunning the actor to get what I mean. As soon as you let go, it will drop to the floor. My best guess would be animations.

When I phy. gun it, it stays where I put.
http://puu.sh/7zEz5.jpg

I tried disabling the animation but same result. I might use Spawn instead, but it would be nice if I could use droptofloor.

You aren’t calling Spawn on it?

I meant when it was just inches from the ground, just clicking on it.

I did nothing happens. Seems like it has no gravity…

I was looking through some NPC scripts and noticed this one:

``````

NPC:SetHullSizeNormal( )

``````

Result:

http://puu.sh/7zUt1.jpg

Fixed! ( the NPC beneath it )

Anyway, thanks for the help.