Hello I need help with setting a parent i'm not sure how it works :/ This is the code.
function SpawnProps()
SpawnProp(Vector( 897.13, -406.16, -432.97 ), "models/chairs/armchair.mdl")
end
hook.Add("InitPostEntity","SpawnTheProps",timer.Simple(1,SpawnProps))
function SpawnProp(position, model)
local ent1 = ents.Create("prop_physics")
local ang = Vector(0,0,1):Angle();
ang.pitch = ang.pitch + 90;
print("Prop spawned with model: " .. model)
ang:RotateAroundAxis(ang:Up(), math.random(0,360))
ent1:SetAngles(ang)
ent1:SetModel(model)
local pos = position
pos.z = pos.z - ent1:OBBMaxs().z
ent1:SetPos( pos )
ent1:Spawn()
ent1:SetCollisionGroup(COLLISION_GROUP_WORLD)
ent1:SetMoveType( MOVETYPE_NONE )
ent1:SetParent( ent1, 0 )
ent1:Fire("setparentattachment", "eyes", 0.01 )
end
I know it has something to do with ent1:SetParent() but I can't figure out what to put. I'm very bad at coding so any help would be appreciated. :)
[editline]18th July 2016[/editline]
[QUOTE=howdy;50730471]Hello I need help with setting a parent i'm not sure how it works :/ This is the code.
function SpawnProps()
SpawnProp(Vector( 897.13, -406.16, -432.97 ), "models/chairs/armchair.mdl")
end
hook.Add("InitPostEntity","SpawnTheProps",timer.Simple(1,SpawnProps))
function SpawnProp(position, model)
local ent1 = ents.Create("prop_physics")
local ang = Vector(0,0,1):Angle();
ang.pitch = ang.pitch + 90;
print("Prop spawned with model: " .. model)
ang:RotateAroundAxis(ang:Up(), math.random(0,360))
ent1:SetAngles(ang)
ent1:SetModel(model)
local pos = position
pos.z = pos.z - ent1:OBBMaxs().z
ent1:SetPos( pos )
ent1:Spawn()
ent1:SetCollisionGroup(COLLISION_GROUP_WORLD)
ent1:SetMoveType( MOVETYPE_NONE )
ent1:SetParent( ent1, 0 )
ent1:Fire("setparentattachment", "eyes", 0.01 )
end
I know it has something to do with ent1:SetParent() but I can't figure out what to put. I'm very bad at coding so any help would be appreciated. :)[/QUOTE]
I want it connected to me.
You are not attaching it into a player
Would you mind telling me how to do so?
Btw plz use code tags. First of all you're setting the parent of the entity to itself, you can't do that, it doesn't work that way. Second of all you should consider using a different hook for spawning an entity, or you can use, [url=https://wiki.garrysmod.com/page/player/GetAll]player.GetAll[/url].
Do you think you could out it in there to show me?
Are you using a timer for learning?
[QUOTE=RedXVIII;50740124]Are you using a timer for learning?[/QUOTE]
No it was in there when I got the code I know almost nothing about lua. So could you show me how you would code it.
I need to spawn the arm chair then i need to attach it to my body then I need to make it not collide with me that's all I need.
Well the way you have it right now it's spawning the chair as soon as you're loading in so you might want to do it when you press a key or hit a button in a derma menu or something.
I want it connected to me as I move around. How would I do that?
If you know nothing about lua, I would recommend learning the basics [url=http://steamcommunity.com/sharedfiles/filedetails/?id=144938866]here[/url].
To do what you require "correctly", you would need to create a Scripted Entity, and use [url=https://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM:PlayerInitialSpawn[/url] to spawn it, and use [url=https://wiki.garrysmod.com/page/ENTITY/SpawnFunction]ENT:SpawnFunction[/url] to use [url=https://wiki.garrysmod.com/page/Entity/SetOwner]Ent:SetOwner[/url], and [url=https://wiki.garrysmod.com/page/Entity/SetParent]Ent:SetParent[/url] to attatch the entity to the owner. You then want to use [url=https://wiki.garrysmod.com/page/ENTITY/Think]ENT:Think[/url] to then use [url=https://wiki.garrysmod.com/page/Entity/SetNoDraw]Ent:SetNoDraw[/url] if not [url=https://wiki.garrysmod.com/page/Player/Alive]Ply:Alive[/url].