havenphillip Posted December 24, 2017 Share Posted December 24, 2017 I have this item spawner script attached to a pivot but I want to figure out how to make the spawner wait to drop another item until the one it has already dropped has been picked up. How do I reference the spawned item? Script.spawnrate = 3--float Script.spawncount = 1--int Script.item ={} Script.item[0]= "Prefabs/Ammo Prefabs/9 ammo Hover.pfb" --path Script.item[1] = "Prefabs/Ammo Prefabs/Shotgun Shells Hover(3).pfb" --path Script.item[2]= "Prefabs/Ammo Prefabs/mp5 ammo Hover (4).pfb" --path Script.item[3] = "Prefabs/Ammo Prefabs/Combat Rifle Hover (5).pfb" --path Script.item[4]= "Prefabs/Health Kit/Health Kit.pfb" --path function Script:Start() self.spawntime = Time:Millisecs() self.counter = 0 end function Script:UpdateWorld() if Time:Millisecs() > self.spawntime + (self.spawnrate * 1000) then self.counter = self.counter + 1 math.random(Time:GetCurrent()) local rand = math.random(0,4) self:Spawn(rand) self.counter = 0 end --end end function Script:Spawn(rand) self.spawn = Prefab:Load(self.item[rand]) local entpos = self.entity:GetPosition(true) self.spawn:SetPosition(self.entity:GetPosition()) self.spawntime = Time:Millisecs() end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 2, 2018 Share Posted January 2, 2018 The item you are spawning is stored in self.spawn. You could attach a script and check if a boolean has been set to this spawned item. You can than access it like this: Quote self.spawn.script.pickedUp Your If statement has to be extended as well. Something like Quote if Time:Millisecs() > self.spawntime + (self.spawnrate * 1000) then if self.spawn ~= nil and self.spawn.script.pickedUp then Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 7, 2018 Author Share Posted January 7, 2018 Ok so my item is a health kit. It has the "enabled" boolean. I tried your advice and added the line: if self.spawn~= nil and self.spawn.script.enabled then But now the spawner is doing nothing. Am I going to have to add a new boolean? I Here's my script (it's got the float up and down script in it from the workshop and it's a bit of a mess):floating.lua Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 8, 2018 Share Posted January 8, 2018 Your item script is fine, although I would set the enabled/pickedup boolean to false. Because now, everytime you spawn the entity, it is emmidiatly 'picked up'. I would also rename this boolean to 'pickedUp' or something similar. Calling it 'enabled' could mean anything. I might have forgot the starting possibility. You want to spawn an item when: A: there is no entity spawned yet. B: an entity is spawned but not yet picked up. Try this line instead of the previous one: if self.spawn == nil or self.spawn.script.pickedUp then Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.