Mario Fireballs : They don't move propperly

More detail: They just roll on the ground, now. They were working fine, until I tried to fix an error: [ERROR] lua/entities/mariofire/init.lua:115: attempt to call method ‘Length’ (a nil value)

  1. unknown - lua/entities/mariofire/init.lua:115

Here are the codes:

Fireball:
Init:


AddCSLuaFile( "shared.lua" )include( 'shared.lua' )




/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()


	-- Use the doll model
	self.Entity:SetModel( "models/XQM/Rails/gumball_1.mdl" )
	self.Entity:SetMoveType( MOVETYPE_FLYGRAVITY )
	self.Entity:SetMoveCollide( MOVECOLLIDE_FLY_CUSTOM )
	self:PhysicsInit( SOLID_VPHYSICS )
    self:SetSolid( SOLID_VPHYSICS )
	
	self.Entity:SetGravity( 1 )


	-- Use the model's physics
	self.Entity:PhysicsInitSphere(7, "foliage")
	self.CrTime = CurTime() + 3
	self.LifeLeft = 1
	self.AngTr = Angle(0,0,0)
	self.AngTr2 = Angle(0,0,0)
	self.bounces = 0
	-- Wake the physics object up. It's time to have babies!
	local phys = self.Entity:GetPhysicsObject()
	if phys:IsValid() then
		phys:Wake()
	end
	
	timer.Simple( 3, function() SafeRemoveEntity( self.Entity ) end )


end




-------------------------------------------------------------------------------
-- Purpose:
-- Input  : *pOther -
-------------------------------------------------------------------------------
function ENT:Touch( pOther )


if pOther:IsNPC() or pOther:IsPlayer() then 


	local	tr = {}
	tr.startpos = self.Entity:NearestPoint( pOther:OBBCenter() )
	tr.endpos = pOther:NearestPoint( self.Entity:OBBCenter() )
	tr.filter = self.Entity
	tr2 = util.TraceLine( tr )
	local	vecNormalizedVel = self.Entity:GetVelocity()


	vecNormalizedVel = ( vecNormalizedVel ):GetNormalized()


	if( self.Entity:GetOwner() && self.Entity:GetOwner():IsPlayer() ) then
		local	dmgInfo = DamageInfo()
		dmgInfo:SetInflictor( self.Entity )
		dmgInfo:SetAttacker( self.Entity:GetOwner() )
		dmgInfo:SetDamage( 25 )
		dmgInfo:SetDamageType( bit.bor( DMG_BURN, DMG_PREVENT_PHYSICS_FORCE ) )
		dmgInfo:SetDamagePosition( tr2.HitPos )
		pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr2.HitPos )
		pOther:Ignite(3, 0)
	else
		local	dmgInfo = DamageInfo()
		dmgInfo:SetInflictor( self.Entity )
		dmgInfo:SetAttacker( self.Entity:GetOwner() )
		dmgInfo:SetDamage( 0 )
		dmgInfo:SetDamageType( bit.bor( DMG_BURN, DMG_PREVENT_PHYSICS_FORCE ) )
		dmgInfo:SetDamagePosition( tr2.HitPos )
		pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr2.HitPos )
		pOther:Ignite(30, 0)
		timer.Simple(30, pOther.Extinguish() )
	end


	SafeRemoveEntity(self.Entity)


	-- play body "thwack" sound
--	self.Entity:EmitSound( "Weapon_Crossbow.BoltHitBody" )	-- Fireballs don't thwack.


	local vForward


	vForward = self.Entity:GetUp()
	vForward = ( vForward ):GetNormalized()


	self.Touch = function( ... ) return end
	self.Think = function( ... ) return end


	local Pos1 = tr2.HitPos + tr2.HitNormal
	local Pos2 = tr2.HitPos - tr2.HitNormal
--	util.Decal( "Blood", Pos1, Pos2 )	-- Scorch!


	SafeRemoveEntity( self.Entity ) end


end




/*---------------------------------------------------------
   Name: PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide( data, physobj )


	-- Shoot some blood
--	local effectdata = EffectData()
--	effectdata:SetOrigin( self.Entity:GetPos() )
--	util.Effect( "BloodImpact", effectdata )


--	function ENT:PhysicsCollide( data, physobj )
		if data.Speed <= 12 then
		
	local LastSpeed = math.max( data.OurOldVelocity:Length(), data.Speed )
     --   local NewVelocity = physobj:GetVelocity()
        if self.bounces == 0 then
			local NewVelocity = self.AngTr2
			local NewVel = NewVelocity*32
			self.bounces = 1
		else
			local NewVelocity = self.AngTr
			local NewVel = NewVelocity*32
			self.bounces = 0
        end
		
        LastSpeed = math.max( 32, LastSpeed )
        
        local TargetVelocity = NewVelocity * 32
        physobj:SetVelocity( Vector(0,0,0) )
        physobj:SetVelocity( TargetVelocity )


--	local Pos1 = data.HitPos + data.HitNormal
--	local Pos2 = data.HitPos - data.HitNormal
	
--	util.Decal( "Blood", Pos1, Pos2 )	-- Scorch


	-- Play sound on death
--[[	if (data.Speed > 80 && data.DeltaTime > 0.2 ) then
		self.Entity:EmitSound( "Weapon_Crossbow.BoltHitBody" )
	end]]
--	if data.Entity():IsPlayer() or data.Entity():IsNPC() then
--		SafeRemoveEntity( self.Entity )
	end
		
end


--function ENT:Think()
--	if math.Round(self.CrTime - CurTime()) == 0 then SafeRemoveEntity( self.Entity ) end
--end


/*---------------------------------------------------------
   Name: OnTakeDamage
---------------------------------------------------------*/
--[[function ENT:OnTakeDamage( dmginfo )


	-- React physically when shot/getting blown
	self.Entity:TakePhysicsDamage( dmginfo )


end


]]








Shared:






ENT.Type 			= "anim"
ENT.Base 			= "base_anim"
ENT.PrintName		= "Mario Fire Ball"
ENT.Author			= "Luavirusfree"
ENT.Information		= "It burns... A lot!"
ENT.Category		= "Mario"


ENT.Spawnable			= false
ENT.AdminSpawnable		= true




Weapon (Shared):






if ( SERVER ) then


	AddCSLuaFile( "shared.lua" )
	
	SWEP.HoldType			= "grenade"
	
end


if ( CLIENT ) then


	SWEP.PrintName			= "Fire"
	SWEP.Author				= "LuaVirusFree..."
	SWEP.Slot				= 0
	SWEP.Slotpos        	= 0
    SWEP.DrawAmmo 			= false
	SWEP.DrawCrosshair 		= false
	SWEP.SlotPos			= 0
    SWEP.Contact 			= "facepunch.com user:Luavirusfree"
    SWEP.Purpose 			= "FireBalls!"
    SWEP.Instructions 		= "Shoot with primary fire. They bounce, so try not to hurt yourself!"
		
end


SWEP.ViewModel			= "models/Weapons/v_hands.mdl"
SWEP.WorldModel			= "models/Weapons/w_grenade.mdl"


SWEP.ViewModelFOV   	= 64
SWEP.Category			= "Mario Powers"


SWEP.Weight				= 0
SWEP.AutoSwitchTo		= true
SWEP.AutoSwitchFrom		= false


SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true


SWEP.Primary.Recoil			= 0
SWEP.Primary.Delay 			= 0
SWEP.Primary.Damage			= 0
SWEP.Primary.ClipSize		= 2
SWEP.Primary.DefaultClip	= 2
SWEP.Primary.Reload 		= 0
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "Thumper"


SWEP.Secondary.Delay		= 0
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"


SWEP.STime = CurTime()




/*-----DO NOT DO ANYTHING UNDER THIS LINE EXCEPTING YOU KNOW WHAT YOU ARE DOING!!! -----*/	


function SWEP:Initialize()
--	self.Owner:DrawWorldModel(false)
	util.PrecacheSound( "mario/fire" )
end


function SWEP:Think()
	if self.STime - CurTime() >= 1 then
		self.Owner:GiveAmmo( 1.3, "Thumper", true )
	end
end


function SWEP:PrimaryAttack()
	local Player = self.Owner
	Player:GiveAmmo( -1, "Thumper", false )
	local Fireball = {}
	if SERVER then
	Fireball = ents.Create( "mariofire" )
		Fireball:SetOwner( Player )
		Fireball:SetPos( Player:GetShootPos() )
	--	Fireball:SetAngles( Angle(30, 30, Player:GetAimVector().z) )
		Fireball:Spawn()


		local mPhys = Fireball:GetPhysicsObject()
	--	local Force = Angle:__add(Player:GetAimVector(), Angle(-30, 0, 0) )*256
		
		mPhys:SetVelocity((self.Owner:GetAngles()+ Angle(45, 0, 0)):Forward() * 32 * CurTime() * 1)
	--	mPhys:SetVelocity((self.Owner:GetAimVector()+ Angle(45, 0, 0)):Forward() * 64 * CurTime() * 1)
	end
		Fireball.AngTr = Angle(self.Owner:GetAngles()+ Angle(45, 0, 0))--:Forward()
		Fireball.AngTr2 = Angle(self.Owner:GetAngles()+Angle(-45, 0, 0))--:Forward()
			
		self.Weapon:EmitSound( "mario/fire" )
	--	self.Weapon:SendWeaponAnim( ACT_VM_THROW )
	--	timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
		self.STime = CurTime()
	
		self.Weapon:SetNextPrimaryFire( CurTime() )
		self.Weapon:SetNextSecondaryFire( CurTime() )
end


function SWEP:Deploy()
	self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
	self.Owner:DrawWorldModel(false)
end


function SWEP:Reload()
	return false
end




Length takes angle not vector
[lua] lua_run_cl print(Angle(54,0,0):Forward():Length())
1.0000000367936
[/lua]

[lua]local LastSpeed = math.max( data.OurOldVelocity:Length(), data.Speed )[/lua]
To
[lua]local LastSpeed = math.max( physobj:GetVelocity(), data.Speed )[/lua]

Well, it also doesn’t move propperly. It just rolls.

[editline]16th December 2012[/editline]

[ERROR] lua/entities/mariofire/init.lua:122: bad argument #1 to ‘max’ (number expected, got userdata)

  1. max - [C]:-1
  2. unknown - lua/entities/mariofire/init.lua:122

Can I have some of the drugs that you are on?

Before Ninja’s “fix”, what line was 115?

U want some weed, or some LCD?

Yea I used all the drugs in garrysmod durgz_mod it helps me code LUA alot better :downs:

[lua]local LastSpeed = math.max( 0, data.Speed)[/lua]

It still reports errors like that ^

Make sure your code is back to normal and ->

[lua]self.Entity:PhysicsInitSphere(16, “metal_bouncy”)[/lua] Use this

and add this

[lua] self:PhysicsInit( SOLID_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
//self:SetMoveCollide( MOVECOLLIDE_FLY_BOUNCE )[/lua]

should look like

[lua]function ENT:Initialize()

-- Use the doll model
self.Entity:SetModel( "models/XQM/Rails/gumball_1.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
//self:SetMoveCollide( MOVECOLLIDE_FLY_BOUNCE )

//self.Entity:SetGravity( 1 )


-- Use the model's physics
self.Entity:PhysicsInitSphere(16, "metal_bouncy")
self.CrTime = CurTime() + 3
self.LifeLeft = 1
self.AngTr = Vector(0,0,0)
self.AngTr2 = Vector(0,0,0)
self.bounces = 0
-- Wake the physics object up. It's time to have babies!
local phys = self.Entity:GetPhysicsObject()
if phys:IsValid() then
	phys:Wake()
end

timer.Simple( 3, function() SafeRemoveEntity( self ) end )

end[/lua]

List to disabled ->
[lua]
//self.Touch = function( … ) return end
//self.Think = function( … ) return end
//self:SetMoveCollide( MOVECOLLIDE_FLY_BOUNCE )
[/lua]
The errors when you fire the ball is based on where you look

Mario weapon replace old code with new and it works how you want it
[lua]
Fireball.Fire = ents.Create( “mariofire” )
Fireball.Fire:SetPos( Player:GetShootPos() )
– Fireball:SetAngles( Angle(30, 30, Player:GetAimVector().z) )
Fireball.Fire:Spawn()
Fireball.Fire:Activate()
Fireball.Fire:SetOwner( Player )

	local mPhys = Fireball.Fire:GetPhysicsObject()
	mPhys:SetVelocity(Angle(90,0,0).p * self.Owner:GetAngles():Forward() * 16 * CurTime() * 1) 

[/lua]

Here is the code…

Mariowep.lua
[lua]if ( SERVER ) then

AddCSLuaFile( )

SWEP.HoldType			= "grenade"

end

if ( CLIENT ) then

SWEP.PrintName			= "Fire"
SWEP.Author				= "LuaVirusFree..."
SWEP.Slot				= 0
SWEP.Slotpos        	= 0
SWEP.DrawAmmo 			= false
SWEP.DrawCrosshair 		= false
SWEP.SlotPos			= 0
SWEP.Contact 			= "facepunch.com user:Luavirusfree"
SWEP.Purpose 			= "FireBalls!"
SWEP.Instructions 		= "Shoot with primary fire. They bounce, so try not to hurt yourself!"

end

SWEP.ViewModel = “models/Weapons/v_hands.mdl”
SWEP.WorldModel = “models/Weapons/w_grenade.mdl”

SWEP.ViewModelFOV = 64
SWEP.Category = “Mario Powers”

SWEP.Weight = 0
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = false

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.Primary.Recoil = 0
SWEP.Primary.Delay = 0
SWEP.Primary.Damage = 0
SWEP.Primary.ClipSize = 2
SWEP.Primary.DefaultClip = 2
SWEP.Primary.Reload = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “Thumper”

SWEP.Secondary.Delay = 0
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”

SWEP.STime = CurTime()

/-----DO NOT DO ANYTHING UNDER THIS LINE EXCEPTING YOU KNOW WHAT YOU ARE DOING!!! -----/

function SWEP:Initialize()
– self.Owner:DrawWorldModel(false)
util.PrecacheSound( “mario/fire” )
end

function SWEP:Think()
if self.STime - CurTime() >= 1 then
self.Owner:GiveAmmo( 1.3, “Thumper”, true )
end
end

function SWEP:PrimaryAttack()
local Player = self.Owner
Player:GiveAmmo( -1, “Thumper”, false )
local Fireball = {}
if SERVER then
Fireball.Fire = ents.Create( “mariofire” )
Fireball.Fire:SetPos( Player:GetShootPos() )
– Fireball:SetAngles( Angle(30, 30, Player:GetAimVector().z) )
Fireball.Fire:Spawn()
Fireball.Fire:Activate()
Fireball.Fire:SetOwner( Player )

	local mPhys = Fireball.Fire:GetPhysicsObject()
	mPhys:SetVelocity(Angle(90,0,0).p * self.Owner:GetAngles():Forward() * 16 * CurTime() * 1) 
--	local Force = Angle:__add(Player:GetAimVector(), Angle(-30, 0, 0) )*256
	
	//Fireball:SetVelocity(self.Owner:GetEyeTrace().StartPos + (self.Owner:GetAngles() + Angle(-20, 0, 0)):Forward() * 15 * CurTime() * 32)
	//timer.Simple(0.5, function()
	mPhys:SetVelocity(Angle(90,0,0).p * self.Owner:GetAngles():Forward() * 16 * CurTime() * 1) 
	//print(Fireball.Fire,mPhys)
	//end)
--	mPhys:SetVelocity((self.Owner:GetAimVector()+ Angle(45, 0, 0)):Forward() * 64 * CurTime() * 1)
end
	Fireball.AngTr = Angle(self.Owner:GetAngles()+ Angle(45, 0, 0))--:Forward()
	Fireball.AngTr2 = Angle(self.Owner:GetAngles()+Angle(-45, 0, 0))--:Forward()
		
	self.Weapon:EmitSound( "mario/fire" )
--	self.Weapon:SendWeaponAnim( ACT_VM_THROW )
--	timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
	self.STime = CurTime()

	self.Weapon:SetNextPrimaryFire( CurTime() )
	self.Weapon:SetNextSecondaryFire( CurTime() )

end

function SWEP:Deploy()
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
self.Owner:DrawWorldModel(false)
end

function SWEP:Reload()
return false
end[/lua]

init.lua
[lua]AddCSLuaFile( “shared.lua” )
include( ‘shared.lua’ )

ENT.Type = “anim”
ENT.Base = “base_anim”

/---------------------------------------------------------
Name: Initialize
---------------------------------------------------------
/

function ENT:Initialize()

-- Use the doll model
self.Entity:SetModel( "models/XQM/Rails/gumball_1.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
//self:SetMoveCollide( MOVECOLLIDE_FLY_BOUNCE )

self.Entity:SetGravity( 1 )


-- Use the model's physics
self.Entity:PhysicsInitSphere(16, "metal_bouncy") 
self.CrTime = CurTime() + 3
self.LifeLeft = 1
self.AngTr = Angle(0,0,0)
self.AngTr2 = Angle(0,0,0)
self.bounces = 0
-- Wake the physics object up. It's time to have babies!
local phys = self.Entity:GetPhysicsObject()
if phys:IsValid() then
	phys:Wake()
end

//timer.Simple( 3, function() SafeRemoveEntity( self ) end )

end


– Purpose:
– Input : *pOther -

function ENT:Touch( pOther )

if pOther:IsNPC() or pOther:IsPlayer() then

local	tr = {}
tr.startpos = self.Entity:NearestPoint( pOther:OBBCenter() )
tr.endpos = pOther:NearestPoint( self.Entity:OBBCenter() )
tr.filter = self.Entity
tr2 = util.TraceLine( tr )
local	vecNormalizedVel = self.Entity:GetVelocity()


vecNormalizedVel = ( vecNormalizedVel ):GetNormalized()


if( self.Entity:GetOwner() && self.Entity:GetOwner():IsPlayer() ) then
	local	dmgInfo = DamageInfo()
	dmgInfo:SetInflictor( self.Entity )
	dmgInfo:SetAttacker( self.Entity:GetOwner() )
	dmgInfo:SetDamage( 25 )
	dmgInfo:SetDamageType( bit.bor( DMG_BURN, DMG_PREVENT_PHYSICS_FORCE ) )
	dmgInfo:SetDamagePosition( tr2.HitPos )
	pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr2.HitPos )
	pOther:Ignite(3, 0)
else
	local	dmgInfo = DamageInfo()
	dmgInfo:SetInflictor( self.Entity )
	dmgInfo:SetAttacker( self.Entity:GetOwner() )
	dmgInfo:SetDamage( 0 )
	dmgInfo:SetDamageType( bit.bor( DMG_BURN, DMG_PREVENT_PHYSICS_FORCE ) )
	dmgInfo:SetDamagePosition( tr2.HitPos )
	pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr2.HitPos )
	pOther:Ignite(30, 0)
	timer.Simple(30, pOther.Extinguish() )
end


SafeRemoveEntity(self.Entity)


-- play body "thwack" sound

– self.Entity:EmitSound( “Weapon_Crossbow.BoltHitBody” ) – Fireballs don’t thwack.

local vForward


vForward = self.Entity:GetUp()
vForward = ( vForward ):GetNormalized()


//self.Touch = function( ... ) return end
//self.Think = function( ... ) return end


local Pos1 = tr2.HitPos + tr2.HitNormal
local Pos2 = tr2.HitPos - tr2.HitNormal

– util.Decal( “Blood”, Pos1, Pos2 ) – Scorch!

SafeRemoveEntity( self.Entity ) end

end

/---------------------------------------------------------
Name: PhysicsCollide
---------------------------------------------------------
/
function ENT:PhysicsCollide( data, physobj )

-- Shoot some blood

– local effectdata = EffectData()
– effectdata:SetOrigin( self.Entity:GetPos() )
– util.Effect( “BloodImpact”, effectdata )

– function ENT:PhysicsCollide( data, physobj )
if data.Speed <= 12 then

local LastSpeed = math.max( data.OurOldVelocity:Length(), data.Speed )
 --   local NewVelocity = physobj:GetVelocity()
    if self.bounces == 0 then
		local NewVelocity = self.AngTr2
		local NewVel = NewVelocity*32
		self.bounces = 1
	else
		local NewVelocity = self.AngTr
		local NewVel = NewVelocity*32
		self.bounces = 0
    end
	
    LastSpeed = math.max( 32, LastSpeed )
    
    local TargetVelocity = NewVelocity * 32
    //physobj:SetVelocity( Vector(0,0,0) )
    physobj:SetVelocity( TargetVelocity )

– local Pos1 = data.HitPos + data.HitNormal
– local Pos2 = data.HitPos - data.HitNormal

– util.Decal( “Blood”, Pos1, Pos2 ) – Scorch

-- Play sound on death

–[[ if (data.Speed > 80 && data.DeltaTime > 0.2 ) then
self.Entity:EmitSound( “Weapon_Crossbow.BoltHitBody” )
end]]
– if data.Entity():IsPlayer() or data.Entity():IsNPC() then
– SafeRemoveEntity( self.Entity )
//end

end
end
–function ENT:Think()
– if math.Round(self.CrTime - CurTime()) == 0 then SafeRemoveEntity( self.Entity ) end
–end

/---------------------------------------------------------
Name: OnTakeDamage
---------------------------------------------------------
/
–[[function ENT:OnTakeDamage( dmginfo )

-- React physically when shot/getting blown
self.Entity:TakePhysicsDamage( dmginfo )

end

]][/lua]

I can’t get it to remove without errors…

[editline]17th December 2012[/editline]

And Ninja, why aren’t you allowing me to send PMs?

[editline]22th December 2012[/editline]

It’s funny that I keep getting rated dumb, because I recently almost died from a traumatic brain injury… .