• Making entities spawn in a certain place? DARKP
    6 replies, posted
I understand DarkRP isn't something you all love but.. Is there a way to make an entity spawn in a certain place without players having move them/lock them up. Pretty much I have a police gun lab, but I would like it to spawn in a specific place and players unable to move it. I would put the code into one of those things that makes it look like c++, but I don't know how so here: lets use a general gunlab as an example: AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") ENT.SeizeReward = 350 function ENT:Initialize() self:SetModel("models/props_lab/crematorcase.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() phys:Wake() self.sparking = false self.damage = 100 local ply = self:Getowning_ent() self.SID = ply.SID self:Setprice(math.Clamp((GAMEMODE.Config.pricemin ~= 0 and GAMEMODE.Config.pricemin) or 100, (GAMEMODE.Config.pricecap ~= 0 and GAMEMODE.Config.pricecap) or 100)) self.CanUse = true self.ShareGravgun = true end function ENT:OnTakeDamage(dmg) self.damage = self.damage - dmg:GetDamage() if (self.damage <= 0) then self:Remove() end end function ENT:Destruct() local vPoint = self:GetPos() local effectdata = EffectData() effectdata:SetStart(vPoint) effectdata:SetOrigin(vPoint) effectdata:SetScale(1) util.Effect("Explosion", effectdata) end function ENT:Use(activator,caller) if not self.CanUse then return false end self.CanUse = false self.drug_user = activator if activator.maxDrugs and activator.maxDrugs >= GAMEMODE.Config.maxdrugs then DarkRP.notify(activator, 1, 3, DarkRP.getPhrase("limit", string.lower(DarkRP.getPhrase("drugs")))) timer.Simple(0.5, function() self.CanUse = true end) else local productioncost = math.random(math.Round(self:Getprice() / 8), math.Round(self:Getprice() / 4)) if not activator:canAfford(productioncost) then DarkRP.notify(activator, 1, 4, DarkRP.getPhrase("cant_afford", string.lower(DarkRP.getPhrase("drugs")))) timer.Simple(0.5, function() self.CanUse = true end) return false end activator:addMoney(-productioncost) DarkRP.notify(activator, 0, 4, DarkRP.getPhrase("you_bought_x", string.lower(DarkRP.getPhrase("drugs")), GAMEMODE.Config.currency, productioncost)) self.sparking = true timer.Create(self:EntIndex() .. "drug", 1, 1, function() self:createDrug() end) end end function ENT:createDrug() self.CanUse = true local userb = self.drug_user local drugPos = self:GetPos() drug = ents.Create("drug") drug:SetPos(Vector(drugPos.x,drugPos.y,drugPos.z + 35)) drug:Setowning_ent(userb) drug.SID = userb.SID drug.ShareGravgun = true drug.nodupe = true drug:Setprice(self:Getprice() or 100) drug:Spawn() if not userb.maxDrugs then userb.maxDrugs = 0 end userb.maxDrugs = userb.maxDrugs + 1 self.sparking = false end function ENT:Think() if not self.SID then self.SID = self:Getprice() end if self.sparking then local effectdata = EffectData() effectdata:SetOrigin(self:GetPos()) effectdata:SetMagnitude(1) effectdata:SetScale(1) effectdata:SetRadius(2) util.Effect("Sparks", effectdata) end end function ENT:OnRemove() if not IsValid(self) then return end timer.Destroy(self:EntIndex() .. "drug") self:Destruct() end
You don't put the spawning code in the entity itself. You're going to want to make a timer that starts a spawn function after 10 seconds or so. (InitPostEntity can screw up sometimes because of addons which use it wrong and break it so I use a timer instead.) Here's an example: [code] function SpawnEntity() local ent = ents.Create("put_ent_here") -- Entity you are going to spawn ent:SetPos( Vector( 0, 0, 0) ) --Don't forget spawn vectors here! ent:SetAngles( Angle(0, 0, 0) ) --Angle to spawn at ent:Spawn() -- Spawns the Entity ent:SetMoveType(MOVETYPE_NONE) -- Makes the Entity nonmoveable end timer.Create( "SpawnEntity", 10, 1, function() SpawnEntity() end ) [/code] To get the position and angle you want the entity to be at you use getpos in console, which gives your player's position and angle. Just for future notice: you can put your code in the block by typing [ code ] before your code and [ /code ] after your code (had to add spaces so they would show so remove those in the tags when you use them). Also, if you need people to not make the entity moveable by physgun, use Falco's Prop Protection or FPP and add the entity name under the blocked entities list (or blacklist) under Physgun Settings. Or if Garry's permaprop system works for you can just use that.
Where would I put this? Also, thanks a lot.
If an addon stops InitPostEntity from working then get rid of the addon. You should definitely use InitPostEntity
Well there's many ways you can put this into lua. If you want you could make a Darkrp module in the Darkrp modification addon and name the file sv_hcpersist.lua for hard-coded persisting. The easiest way is to make a server-side lua file under lua/autorun/server and name it sv_hcpersist.lua or whatever you want to name it, just make sure you have sv_ in the front so you know its server side. Also for correctness's sake here is the function with initpostentity hook instead of a 10 second timer. If InitPostEntity doesn't work just try the other one. But as Coffeee said, you really should try to see what addon is breaking it instead of using the timer. [code] function SpawnEntity() local ent = ents.Create("put_ent_here") -- Entity you are going to spawn ent:SetPos( Vector( 0, 0, 0) ) --Don't forget spawn vectors here! ent:SetAngles( Angle(0, 0, 0) ) --Angle to spawn at ent:Spawn() -- Spawns the Entity ent:SetMoveType(MOVETYPE_NONE) -- Makes the Entity nonmoveable end hook.Add( "InitPostEntity", "SpawnEntity", SpawnEntity) -- this is called after the initialization of the map and entities [/code]
[QUOTE=Stormtrooper595;43801882]Well there's many ways you can put this into lua. If you want you could make a Darkrp module in the Darkrp modification addon and name the file sv_hcpersist.lua for hard-coded persisting. The easiest way is to make a server-side lua file under lua/autorun/server and name it sv_hcpersist.lua or whatever you want to name it, just make sure you have sv_ in the front so you know its server side. Also for correctness's sake here is the function with initpostentity hook instead of a 10 second timer. If InitPostEntity doesn't work just try the other one. But as Coffeee said, you really should try to see what addon is breaking it instead of using the timer. [code] function SpawnEntity() local ent = ents.Create("put_ent_here") -- Entity you are going to spawn ent:SetPos( Vector( 0, 0, 0) ) --Don't forget spawn vectors here! ent:SetAngles( Angle(0, 0, 0) ) --Angle to spawn at ent:Spawn() -- Spawns the Entity ent:SetMoveType(MOVETYPE_NONE) -- Makes the Entity nonmoveable end hook.Add( "InitPostEntity", "SpawnEntity", SpawnEntity) -- this is called after the initialization of the map and entities [/code][/QUOTE] Well I put this into my autorun and nothing showed up. And to be more descriptive about what I'm trying to do here is a scenario: -Person goes into F4 menu -Goes Police Cheif -Goes to f4 buy menu -Buys "policegunlabmp5" -Spawns in specific place I would like it to spawn -Police can go buy mp5's until chief demoted/leaves -chief leaves/demoted and the next police chief has to re-buy the entity for it to spawn in specific place. Here is the code I made for it. [code]function SpawnEntity() local ent = ents.Create("policegunlabmp5") -- Entity you are going to spawn ent:SetPos( Vector(-1959.959106, 343.129517, -95.968750;) ) --Don't forget spawn vectors here! ent:SetAngles( Angle(0.889947 -1.049526 0.000000) ) --Angle to spawn at ent:Spawn() -- Spawns the Entity ent:SetMoveType(MOVETYPE_NONE) -- Makes the Entity nonmoveable end hook.Add( "InitPostEntity", "SpawnEntity", SpawnEntity) -- this is called after the initialization of the map and entities [/code] Thanks
[QUOTE=Skit.;43804369]Well I put this into my autorun and nothing showed up. And to be more descriptive about what I'm trying to do here is a scenario: -Person goes into F4 menu -Goes Police Cheif -Goes to f4 buy menu -Buys "policegunlabmp5" -Spawns in specific place I would like it to spawn -Police can go buy mp5's until chief demoted/leaves -chief leaves/demoted and the next police chief has to re-buy the entity for it to spawn in specific place. Here is the code I made for it. [code]function SpawnEntity() local ent = ents.Create("policegunlabmp5") -- Entity you are going to spawn ent:SetPos( Vector(-1959.959106, 343.129517, -95.968750;) ) --Don't forget spawn vectors here! ent:SetAngles( Angle(0.889947 -1.049526 0.000000) ) --Angle to spawn at ent:Spawn() -- Spawns the Entity ent:SetMoveType(MOVETYPE_NONE) -- Makes the Entity nonmoveable end hook.Add( "InitPostEntity", "SpawnEntity", SpawnEntity) -- this is called after the initialization of the map and entities [/code] Thanks[/QUOTE] Are you sure 'policegunlabmp5' is the name of the entity? Also, [code]ent:SetPos( Vector(-1959.959106, 343.129517, -95.968750;) )[/code] should be [code]ent:SetPos( Vector(-1959.959106, 343.129517, -95.968750) )[/code]
Sorry, you need to Log In to post a reply to this thread.