• World prop Spawn on server
    6 replies, posted
Im kinda wondering how. to add world props to a map. that will spawn when server starts or a script that can spawn em :)
[lua] function SpawnMyProp() local e = ents.Create("prop_physics") e:SetPos(PROP_POS) e:SetModel(PROP_MODEL) e:Spawn() end hook.Add("InitPostEntity","SpawnMyProp",SpawnMyProp)[/lua] PROP_POS is a vector, and PROP_MODEL a string. I have a feeling you'll need a way to get those as well, though. Would a system where you run around the map with the prop(s) already spawned, then you look at them and use a console command, and it'll store that prop model and position for that map work?
thanks alot for the reply Gmod4ever :D im gonna test it out :) [editline]4th February 2012[/editline] how do i getpos of a prop if i place it in the server?
Pos And Angle of prop im currently looking at thanks for the help everyone --- lua_run_cl print( LocalPlayer():GetEyeTrace().Entity:GetAngles() ) --- lua_run_cl print( LocalPlayer():GetEyeTrace().Entity:GetPos() )
Or you could just type getpos in console.
There was an addon somewhere that does this. And I have some code for a STOOL. I'll finish it now. Edit: It's very late [lua]TOOL.Category = "Construction" TOOL.Name = "Show properties" TOOL.Command = nil TOOL.ConfigName = "" if (CLIENT) then language.Add("Tool_tellpos_name", "Position tables") language.Add("Tool_tellpos_desc","Puts object properties to a table") language.Add("Tool_tellpos_0","Primary: Add object to table. Secondary: Output tables in data/props/positions.txt. Reload: Clear tables.") local function noprop() chat.AddText( Color(225,0,0), "No prop targeted!") chat.PlaySound() end usermessage.Hook( "tellpos_noprop", noprop ); local function propselection( data ) chat.AddText( Color(0,225,0), "Added prop:") chat.AddText( Color(0,225,0), "Model : "..data:ReadString() ) chat.AddText( Color(0,225,0), "Vector : "..tostring(data:ReadVector() ) ) chat.AddText( Color(0,225,0), "Angle : "..tostring(data:ReadAngle() ) ) chat.PlaySound() end usermessage.Hook( "tellpos_propadded", propselection ); local function deletedata( ) chat.AddText( Color(0,225,0), "Deleted data file") chat.PlaySound() end usermessage.Hook( "tellpos_deldat", deletedata ); end local vectors = {} local angles = {} local models = {} function TOOL:LeftClick(tr) if tr.Entity:GetClass() != "prop_physics" then umsg.Start("tellpos_noprop") umsg.End() else local vec = tr.Entity:GetPos() local ang = tr.Entity:GetAngles() local mod = tr.Entity:GetModel() if !( table.HasValue( vectors, vec ) and table.HasValue( angles, ang ) and table.HasValue( models, mod ) ) then table.insert( vectors, vec ) table.insert( angles, ang ) table.insert( models, mod ) umsg.Start("tellpos_propadded") umsg.String( tostring(mod) ) umsg.Angle( Angle( math.Round(ang.p), math.Round(ang.y), math.Round(ang.r) ) ) umsg.Vector( Vector( math.Round(vec.x), math.Round(vec.y), math.Round(vec.z) ) ) umsg.End() end end end function TOOL:Reload(tr) umsg.Start("tellpos_deldat") umsg.End() table.Empty(vectors) table.Empty(angles) table.Empty(models) file.Delete("props/positions.txt") end function TOOL:RightClick(tr) file.Delete("props/positions.txt") file.Write( "props/positions.txt" , "" ) local lenghts = math.min( #vectors, #angles, #models ) for i=1,lenghts do local vec = vectors[i] file.Append("props/positions.txt", "vectors["..i.."]=Vector("..vec.x..", "..vec.y..", "..vec.z..")\n") end for i=1,lenghts do local ang = angles[i] file.Append("props/positions.txt", "angles["..i.."]=Angle("..ang.p..", "..ang.y..", "..ang.r..")\n") end for i=1,lenghts do local mod = models[i] file.Append("props/positions.txt", "models["..i.."]=\""..mod.."\"\n") end end[/lua] Outputs tables in data\props I guess you could do the table sorting yourself. It's inefficient because you have to put tables in the .lua file itself and then go through the tables for each prop And yes, I was playing with usermessages. [editline]derp[/editline] Spawning end of code. [lua]local vectors = {} local angles = {} local models = {} // paste tables from data\props\positions.txt here local lenghts = math.min( #vectors, #angles, #models ) function SpawnStartProp() for i=1, lenghts do ent = ents.Create( "prop_physics" ) ent:SetModel( models[i] ) ent:SetPos( vectors[i] ) ent:SetAngles( angles[i] ) ent:Spawn() if ent:GetPhysicsObject():IsValid() then ent:PhysWake() end end end hook.Add( "InitPostEntity", "CreateProps", SpawnStartProp) concommand.Add( "spawn_props" , SpawnStartProp )[/lua]
[QUOTE=DeveloperConsol;34542301]Or you could just type getpos in console.[/QUOTE] that will give the pos of The player (yourself)
Sorry, you need to Log In to post a reply to this thread.