• Can only spawn 1 of my custom entity
    13 replies, posted
Whenever I try to spawn multiple the rotating doesn't work and it won't give out guns. -snip-
This is the wrong part: [code] function GiveGun() local EntsInRadius = ents.FindInSphere( vPoint, 50 ) for k, v in pairs( EntsInRadius ) do if v:IsPlayer() and !(table.HasValue( AlreadyGotAGun, v )) then v:Give( "weapon_smg1" ) v:GiveAmmo( 200, "smg1", true ) v:SelectWeapon( "weapon_smg1" ) table.insert( AlreadyGotAGun, v ) end end local NewAngle = Angle( 0, CurAngle.y + 1, 0) self:SetAngles( NewAngle ) CurAngle = NewAngle end hook.Add("Think", "GiveGun", GiveGun) self:CallOnRemove( "StopHooks", function() hook.Remove( "Think", "GiveGun" ) hook.Remove( "OnRoundSet", "AlreadyHaveGun" ) end ) hook.Add("OnRoundSet", "AlreadyHaveGun", function( State ) if State == "PREPARING" then table.Empty( AlreadyGotAGun ) end end)[/code] You don't put functions inside functions Use ENT:Think and replace your AlreadyGotAGun nonsense with Player:HasWeapon( class )
[QUOTE=Robotboy655;45404347]This is the wrong part: -snip- You don't put functions inside functions Use ENT:Think and replace your AlreadyGotAGun nonsense with Player:HasWeapon( class )[/QUOTE] Player:HasWeapon won't suit because they are able to drop the weapon and I dont want them getting a second.
Don't let them drop the weapon? [editline]16th July 2014[/editline] Also, you don't need to reset the table because the entity respawns with each round, and the local table will be empty anyway.
I have this now. but the entity is broken. -snip- [editline]16th July 2014[/editline] I want to let them drop the weapon btw
What do you mean "broken"
[QUOTE=crazyscouter;45404444]What do you mean "broken"[/QUOTE] its failing to be created
[code]function ENT:Think() GiveGun() self:NextThink( CurTime() + 1 ) return true // Note: You need to return true to override the default next think time end[/code] You cannot call any code after a return in the same scope. Make sure to remember this. Also you can simply copypaste the GiveGun code directly to ENT:Think.
I have this now but the same problem as in the beginning -snip-
Don't do this. [code] gunspawner = self[/code] Use the Entity itself. By that I mean, copy paste the code from GiveGun() to ENT:Think() and use self instead of gunspawner. Also, AlreadyGotAGun is not defined.
[QUOTE=Robotboy655;45404629]Don't do this. [code] gunspawner = self[/code] Use the Entity itself. By that I mean, copy paste the code from GiveGun() to ENT:Think() and use self instead of gunspawner. Also, AlreadyGotAGun is not defined.[/QUOTE] Isn't it defined in the init? [code] AlreadyGotAGun = {} [/code]
Assign it to the ENT table by doing self.AlreadyGotAGun. Don't use global variables inside entities.
Had to do some stuff with the vectors but seems to be working now thanks. Also if you wouldn't mind snipping the code. I don't really want it public but I was really struggling.
[QUOTE=Declivity;45404739]Had to do some stuff with the vectors but seems to be working now thanks. Also if you wouldn't mind snipping the code. I don't really want it public but I was really struggling.[/QUOTE] There's nothing special about the code you or I posted in this thread. Anyone can write it on their own, with any skill level.
Sorry, you need to Log In to post a reply to this thread.