• SWEP Help
    5 replies, posted
Here is the code to the SWEP I'm making for my gamemode, however it doesn't seem to be working properly, anybody know the problem? shared.lua [code] if SERVER then AddCSLuaFile( "shared.lua" ) end if CLIENT then SWEP.PrintName = "Cry out" SWEP.Author = "Pancakes" SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.IconLetter = "b" end function SWEP:PrimaryAttack() self:EmitSound("ba_helpmeout.wav") resu=math.random(1,10) placeAt = {} placeAt.start = self.Owner:GetShootPos() placeAt.endpos = self.Owner:GetAimVector() * 100 if(resu>=7) then newSurvivor=ents.Create("npc_rebel") newSurvPos:GetPos(placeAt.HitPos) newSurvivor:SetPos(newSurvPos) newSurvivor:Activate() newSurvivor:Spawn() newSurvivor:Use(activator,caller) if(newSurvivor.master==nil) then newSurvivor.master = self.Owner end end if(resu<=3) then newZomb=ents.Create("npc_zombie") newZombPos:GetPos(placeAt.HitPos) newZomb:SetPos(newZombPos) newZomb:Activate() newZomb:Spawn() end end end SWEP.Base = "weapons_base" SWEP.Spawnable = true SWEP.AdminSpawnable = true [/code]
What is it supposed to do
PLay a sound, then make an NPC appear.
Why have you put newZombPos? You have not defined what that is, same for newSurvPos. It should be [lua]newZombPos = GetPos(placeAt.HitPos) newSurvPos = GetPos(placeAt.HitPos)[/lua] That's how to define something. You needed to define them because you called them later on, using a ":" after the name doesn't define it, it looks for the exact name you typed before the ":" and finds whether or not the variable to defined it as in the code. So, to define it, instead of ":", it should have been "=" But, if you are only going to call on those defined variables in that function, than local them.
Yea, sorry I didn't think, but also, what is this whole factory error not found for npc_zombie error or whatever I also get with it?
Apparantly it cannot find all the animations, models and materials for the NPC's if you call them in "ents.Create", I really don't know why. I didn't find a way of fixing it, maybe someone else has a way?
Sorry, you need to Log In to post a reply to this thread.