~Solved
Alright I need just a tad help. and I know it's something simple I'm missing. I'm a complete noobie to LUA.
These are my two scripts one is the actual weapon and one is the ent. I didn't fully write either just messed with them, so that may be a huge reason I don't understand it.
Right now it spawns Kleiner NPCs.
[CODE]if (SERVER) then
AddCSLuaFile ("shared.lua")
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
--net.Receive("give_monster", function(len, ply) ply:Give("pokeball_base") ply:GetWeapon("pokeball_base"):SetSpawn(net.ReadString()) end)
end
if (CLIENT) then
SWEP.PrintName = "Pokeball"
SWEP.Slot = 1
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModelFOV = 65
SWEP.ViewModelFlip = true
SWEP.CSMuzzleFlashes = false
SWEP.BounceWeaponIcon = false
SWEP.WepSelectIcon = surface.GetTextureID("vgui/entities/pokeball_capture")
print("!")
end
function SWEP:SetSpawn(ent)
self.spawn = ent
end
SWEP.ent = "pb_base"
SWEP.spawn = "npc_kleiner"
SWEP.Author = "Chaze007"
SWEP.Category = "Pokeball"
SWEP.Spawnable = true
SWEP.AdminSpawnable = false
SWEP.ViewModel = "models/weapons/v_pokeball.mdl"
SWEP.WorldModel = "models/weapons/w_pokeball.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = 1
SWEP.Secondary.DefaultClip = 1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
function SWEP:Initialize()
self:SetWeaponHoldType("grenade")
end
function SWEP:Deploy()
self.Weapon:SetNextPrimaryFire(CurTime()+1)
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
return true
end
function SWEP:Holster()
self.Proned = false
self.Throwing = false
return true
end
function SWEP:Reload()
end
function SWEP:Think()
if self.Proned and not self.Owner:KeyDown ( IN_ATTACK) and self.Owner:KeyReleased(IN_ATTACK) then
self.Proned = false
self.Throwing = true
self.Weapon:SendWeaponAnim(ACT_VM_THROW)
if self:IsValid() then
timer.Simple( 0.35, function()
self:Throw()
end )
end
end
end
function SWEP:Throw()
if !self.Throwing then return end
self.Owner:SetAnimation( PLAYER_ATTACK1 )
local tr = self.Owner:GetEyeTrace()
if (!SERVER) then return end
local ent = ents.Create (self.ent)
ent.spawn = self.spawn
local v = self.Owner:GetShootPos()
v = v + self.Owner:GetForward() * 1
v = v + self.Owner:GetRight() * 3
v = v + self.Owner:GetUp() * 1
ent:SetPos( v )
ent:SetAngles (Angle(math.random(1,100),math.random(1,100),math.random(1,100)))
-- ent.GrenadeOwner = self.Owner
-- ent:SetOwner(self.Owner)
ent:Spawn()
local phys = ent:GetPhysicsObject()
local shot_length = tr.HitPos:Length()
phys:ApplyForceCenter(self.Owner:GetAimVector() *2500 *1.2 + Vector(0,0,200) )
phys:AddAngleVelocity(Vector(math.random(-500,500),math.random(-500,500),math.random(-500,500)))
self.Weapon:SetNextPrimaryFire( CurTime() + 1.6 )
timer.Simple(0.6,
function()
self.Weapon:Remove()
self.Owner:ConCommand("lastinv")
end)
end
function SWEP:PrimaryAttack()
if self.Throwing then return end
if !self.Proned then
self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN)
self.Proned = true
end
end
function SWEP:Equip(newowner)
--net.Start("gotcha!")
-- net.WriteType()
--net.Send()
end
function SWEP:DoColorstuff(ent) --Hacky way of doing this, but it looks cool so what the hell
if IsValid(ent) and ent:IsNPC() then
local r = 255
ent:SetMaterial( "models/props_combine/prtl_sky_sheet" )
self.Entity:EmitSound(Sound("Pokeballs/capture.wav"))
ent:SetSolid(false)
self:SetSpawn(ent:GetClass())
timer.Simple(0.1, function()
ent:SetColor(r, 0, 0, 255)
end)
timer.Simple(3.0, function()
ent:Remove()
end )
end
end
function SWEP:SecondaryAttack()
end[/CODE]
[CODE]if (SERVER) then
AddCSLuaFile( "shared.lua" )
end
ENT.Type = "anim"
ENT.Author = "Chaze007"
ENT.Base = "base_gmodentity"
ENT.BounceSnd = Sound("Pokeballs/bounce.wav")
function ENT:PhysicsCollide(data,phys)
self:EmitSound(self.BounceSnd)
local impulse = -data.Speed * data.HitNormal * .4 + (data.OurOldVelocity * -.6)
phys:ApplyForceCenter(impulse)
end
function ENT:Initialize()
self:SetModel("models/weapons/w_pokeball.mdl")
self:PhysicsInit( SOLID_CUSTOM)
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:DrawShadow( false )
if self:IsValid() then
timer.Simple(2.5, function() self:Jump(self) end)
self.timer = CurTime() + 3
end
end
ReleaseSnd = Sound("Pokeballs/release.wav")
function ENT:Think()
if self.timer < CurTime() and SERVER then
self:Release()
self:DoEffects()
end
end
function ENT:DoEffects()
local effectdata = EffectData()
effectdata:SetStart( self:GetPos() )
effectdata:SetOrigin( self:GetPos() )
effectdata:SetScale( 10 )
util.Effect( "cball_explode", effectdata )
self:EmitSound(ReleaseSnd)
self:Remove()
end
function ENT:Jump()
self:GetPhysicsObject():ApplyForceCenter(Vector(0, 0, 1000))
end
function ENT:Release()
local makenpc = ents.Create(self.spawn)
makenpc:SetNWBool("garrymon", true)
makenpc:SetOwner( self.GrenadeOwner )
makenpc:SetPos( self:GetPos() )
makenpc:Fire("setrelationship","player d_li 97",0)
for k, v in pairs(ents.FindByClass("npc_*")) do
makenpc:Fire("setrelationship", v:GetClass() .. " D_HT 99" , 0)
end
makenpc:Spawn()
makenpc:Activate()
end
if (CLIENT) then
function ENT:Draw()
self.Entity:DrawModel()
end
function ENT:IsTranslucent()
return true
end
end[/CODE]
In this part of your code:
[CODE]ent:SetPos( v )
ent:SetAngles (Angle(math.random(1,100),math.random(1,100),math.random(1,100)))
-- ent.GrenadeOwner = self.Owner
-- ent:SetOwner(self.Owner)
ent:Spawn()[/CODE]
Try adding ent:Activate() as well. Not sure if this will fix it, I am still new to coding.
Sorry, you need to Log In to post a reply to this thread.