• Weapon Respawn
    4 replies, posted
So I have a problem. I'm making a gamemode for this map. And I want weapons on the map to respawn after someone takes them. I don't respawn for some odd reason, even though the mapper made it so they do. So, I made this script so that they would respawn. [lua]function RespawnWeapon(weapon,class,pos,angles) timer.Create("TheTimer",2,1,function(class,pos,angles) local w = ents.Create(class) w:SetPos(pos) w:SetAngles(angles) w:Spawn() w:CallOnRemove("Respawn", RespawnWeapon, class, pos, angles) end,class,pos,angles) end hook.Add("InitPostEntity", "Respawns", function() --[[for _, ent in pairs(ents.FindByClass("weapon_*")) do ent:CallOnRemove("Respawn", RespawnWeapon, ent:GetClass(), ent:GetPos(), ent:GetAngles()) end]] end) function CheckForPickup(player,weapon) RespawnWeapon(weapon,weapon:GetClass(),weapon:GetPos(),weapon:GetAngles()) end hook.Add("PlayerCanPickupWeapon","CheckForPickup",CheckForPickup)[/lua] So basically, if someone touches the weapon it will spawn another one of it. The problem is that I also made a script so that if the player already has a weapon, they can't pick it up. So, when someone touches a weapon they already have, they don't pick it up, and it spawns another one of it. EX: The map has a crowbar. The player already has a crowbar. When the player touches the crowbar, the crowbar duplicates. So then there's 2 crowbars now. Is there a way to fix this?
before spawning another use the same check you use to stop them picking up something they already have
And as a bit of friendly advice, post your code in [lua] tags next time. It makes it so much easier to read.
[QUOTE=BlackMagic;29879311]And as a bit of friendly advice, post your code in [lua] tags next time. It makes it so much easier to read.[/QUOTE] Ah I did, but it didn't go through or something, lemme fix it real quick.
Sorry for responding so late, but I was busy the last 2 days. This is what I have: [lua]function CheckForPickup(player,weapon) if player:HasWeapon(weapon:GetClass())== true then return false else RespawnWeapon(weapon,weapon:GetClass(),weapon:GetPos(),weapon:GetAngles()) end end hook.Add("PlayerCanPickupWeapon","CheckForPickup",CheckForPickup)[/lua] EDIT: Actually the problem is that I can't pick up other weapons after picking one up SOMETIMES
Sorry, you need to Log In to post a reply to this thread.