• White ball-shooting gun.
    8 replies, posted
I would like to hear if anyone could provide me with a swep that shoots small white balls that disappears after a few seconds (so it doesn't cause lag). I need it for my simple gamemode where I will try to emulate airsoft weapons. :) There will be full credit for the weapon and base to the person who is able to complete the request. :)
Hey i have made a rough weapon for what you wanted, some information on how you can change the code where you download it. In the zip there is air_ball which is the Entity file and weapon_whiteball the weapon file [url]http://www.garrysmod.org/downloads/?a=view&id=97997[/url] Say what you think or if you want me to try and improve it
That was exactly what I needed! Thank you! :D You will be credited! :) But is there anyway to make the ball give damage based on the weapon? Like a pistol would be 25 damage, rifle 35 etc? And is there a way to just drop on the ground when it hits something instead of doing too much richochet?
Change the code in the ent file to this [lua]function ENT:Initialize() self.Entity:SetModel ("models/dav0r/hoverball.mdl") self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.PhysObj=self.Entity:GetPhysicsObject() if(self.PhysObj:IsValid()) then self.PhysObj:EnableGravity(true) self.PhysObj:SetMass(1) self.PhysObj:Wake() end self.life = 0 self.Addone = 0 end function ENT:PhysicsCollide(data,physobj) local vel = data.OurOldVelocity local norm = data.HitNormal local ang = vel:Angle() ang:RotateAroundAxis(norm, 180) local newvel = ang:Forward()*-0.5*vel:Length() physobj:SetVelocity(newvel) end function ENT:Think() if (CurTime() >= self.Addone) then self.life = self.life + 1 Addone = CurTime() + 1 end if self.life > 70 then self.Entity:Remove() end end[/lua] Make the bounce less and makes teh ball seem more "airy"
Thanks WhiTAkeR, it's perfect! :D Does it also include damage set from weapon?
im kinda working on that now not sure if its going to be dependant on the model fired from because im not sure if you can do that, but once i get the ball doing a set amount of damage you will be able to change the data and save seperate Ents for seperate guns and use them.
Oh I think you misunderstood. What I was saying was that if I script a swep and make it fire these balls. Can I then say that the swep when shooting gives 35 damage and then the ball will give 35 damage when hitting someone.
Here is the ent doing damage jus replace all the code [lua]AddCSLuaFile ("cl_init.lua") AddCSLuaFile ("shared.lua") include ("shared.lua") function ENT:Initialize() self.Entity:SetModel ("models/dav0r/hoverball.mdl") local r = 1.5 self.Entity:PhysicsInitSphere(r) self.Entity:SetCollisionBounds(Vector(-r,-r,-r),Vector(r,r,r)) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.PhysObj=self.Entity:GetPhysicsObject() if(self.PhysObj:IsValid()) then self.PhysObj:EnableGravity(true) self.PhysObj:SetMass(1) self.PhysObj:Wake() end self.life = 0 self.Addone = 0 end function ENT:StartTouch(targ) if targ~=self.Target then if (targ:IsValid() and targ:IsPlayer() or targ:IsNPC()) then targ:TakeDamage(10,self.Target) end end end function ENT:Think() if (CurTime() >= self.Addone) then self.life = self.life + 1 Addone = CurTime() + 1 end if self.life > 70 then self.Entity:Remove() end end[/lua] Change the number in here [lua]targ:TakeDamage(10,self.Target)[/lua] for more or less damage depending on what you want, And not sure on how you would do what you said ^^
Works perfectly! :D Thanks WhiTaKeR, It really helped me a lot :)
Sorry, you need to Log In to post a reply to this thread.