Mario Fireballs Errors

1: WHY was my thread closes? 2: I fixed the damage types, and still got an error. My threads keep getting closed >_<

If there’s already an active thread, please link me and I will stop this madness!


 [ERROR] lua/entities/mariofire/init.lua:18: attempt to call global 'curtime' (a nil value)  1. unknown - lua/entities/mariofire/init.lua:18   2. Spawn - [C]:-1    3. unknown - lua/weapons/mario_fireballs/shared.lua:77
I have yet to investigate, though. I will update the code above. 


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




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


	-- Use the doll model
	self.Entity:SetModel( "models/props_c17/doll01.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
	-- 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 )


	local	tr
	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( tr.HitPos )
		pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr.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( tr.HitPos )
		pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr.HitPos )
		pOther:Ignite(30, 0)
		timer.Simple(30, pOther.Extinguish() )
	end


	self.Entity:Remove()


	-- 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 = tr.HitPos + tr.HitNormal
	local Pos2 = tr.HitPos - tr.HitNormal
--	util.Decal( "Blood", Pos1, Pos2 )	-- Scorch!


	if pOther:IsNPC() or pOther:IsPlayer() then 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
	timer.Simple(5, function() 
			local vPoint = self:GetPos()
			local effectdata = EffectData()
			effectdata:SetStart( vPoint )
			effectdata:SetOrigin( vPoint )
			effectdata:SetScale( 1 )
			util.Effect( "Explosion", effectdata )
			if IsValid(self) then
				self:Remove() 
			end
		end)
    end
	
	local LastSpeed = math.max( data.OurOldVelocity:Length(), data.Speed )
        local NewVelocity = physobj:GetVelocity()
        NewVelocity:Normalize()
        
        LastSpeed = math.max( NewVelocity:Length(), LastSpeed )
        
        local TargetVelocity = NewVelocity * LastSpeed
        
        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]]


	SafeRemoveEntityDelayed( self.Entity, 0.1 )


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


]


It wasn’t doing damage, but that’s likely because of the new error.


[ERROR] lua/entities/mariofire/init.lua:50: ')' expected near '|'  1. unknown - lua/entities/mariofire/init.lua:0

^ Fixed…


dmgInfo:SetDamageType( bit.bor( DMG_BURN, DMG_PREVENT_PHYSICS_FORCE ) )

… Next error:


[ERROR] lua/entities/mariofire/init.lua:18: attempt to call global 'curtime' (a nil value)  1. unknown - lua/entities/mariofire/init.lua:18
   2. Spawn - [C]:-1
    3. unknown - lua/weapons/mario_fireballs/shared.lua:77








[ERROR] lua/entities/mariofire/init.lua:132: attempt to perform arithmetic on field 'CrTime' (a nil value)
  1. unknown - lua/entities/mariofire/init.lua:132








[ERROR] lua/entities/mariofire/init.lua:105: attempt to index global 'tr' (a nil value)
  1. unknown - lua/entities/mariofire/init.lua:105


Post in what do you need help with, Post all of it with mario fireballs in a .zip file and I’ll fix it up for you.

sigh I posted the last one there… But the thread got deleted, and that forum is a PITA to keep up with!!

CurTime(), not curtime()


[ERROR] lua/entities/mariofire/init.lua:105: attempt to index global 'tr' (a nil value)  1. unknown - lua/entities/mariofire/init.lua:10


Called when the weapon is fired. Not for the first shot, last test.
curtime() == CurTime() now.

[lua]AddCSLuaFile()

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

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

-- Use the doll model
self.Entity:SetModel( "models/props_c17/doll01.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS );
self:SetSolid( SOLID_VPHYSICS )

self.Entity:SetGravity( 0.5 );

-- Use the model's physics
//self.Entity:PhysicsInitSphere(7, "metal");

-- Wake the physics object up. It's time to have babies!
local phys = self.Entity:GetPhysicsObject();
if (phys:IsValid()) then
    phys:Wake()
end

end


– Purpose:
– Input : *pOther -

function ENT:Touch( pOther )

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();

if( self.Entity:GetOwner() && self.Entity:GetOwner():IsPlayer() ) then
    local dmgInfo = DamageInfo();
    dmgInfo:SetInflictor( self.Entity );
    dmgInfo:SetAttacker( pOther );
    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( pOther );
    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, function() if pOther:Health() &gt; 0 then pOther:Extinguish() end end)
end

SafeRemoveEntity( self.Entity );

end

/---------------------------------------------------------
Name: PhysicsCollide
---------------------------------------------------------
/
function ENT:PhysicsCollide( data, physobj )
if data.Speed <= 12 then
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 1 )
util.Effect( “Explosion”, effectdata )
if IsValid(self) then
self:Remove()
end
end
end

function ENT:Think()

end

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

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

end[/lua]

Fixed and tested in singleplayer

Does what you want spawn code:
[lua]local ply = Entity(1)
local ent = ents.Create(“mariofire”)
ent:SetPos(ply:GetEyeTrace().HitPos + ply:GetEyeTrace().HitNormal * 16 )
ent:Spawn()
ent:Activate()
[/lua]

Change ply to what ever is in the weapon code local ply = self.Owner

Ignites the player when it touches them
Explodes when touches the ground

I don’t want them to explode immediately, only after about 5 seconds (Like in Mario). I still want the effect at every hit.

change it to [lua]function ENT:PhysicsCollide( data, physobj )
if data.Speed <= 12 then
timer.Simple(5, function()
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 1 )
util.Effect( “Explosion”, effectdata )
if IsValid(self) then
self:Remove()
end
end)
end
end
[/lua]

and if you want it to ignite in Initialize [lua]self:Ignite(5, 0)[/lua]

1: Why ignite it? I plan to use particle effects. 2: Explode isn’t a particle effect, except in the source code.



function ENT:Think()
    self.LifeLeft = 3-self.CrTime
    if self.LifeLeft <= 0 then self:Remove() end
       <to be added: Particle Function, or code>
end

…I will rate you dumb, ninjas.

Why are you even using it in think, When you can do it in PhysicsCollide, util.Effect( “Explosion”, …) was just an example you can replace it with an particle effect and you’re doing self.LifeLeft wrong… and that would error since you’re removing the entity before even adding the particle effect, unless you’re getting the last position of the entity!

My dumb rating was to what you just said in your post no need to be offended, I’m not saying you’re dumb, just what you typed…

Bah. I can figure that out if it doesn’t work. I don’t want it to wait until it collides, but I haven’t fully observed its behavior in New Super Mario Wii… If it disappears when it hits, then I will code it that way.

[SUP]Edited:[/SUP]


function SWEP:PrimaryAttack()    local Player = self.Owner

Current code.

If you want something like this more understanding way in a think hook

Also it’s best to slow the Think hook down so
[lua]
self.SlowDown = 0
self.CrTime = CurTime() + 3

if CurTime() >= self.SlowDown then
if math.Round(self.CrTime - CurTime()) == 0 then
self:Remove()
//… particle effect at last position
end
self.SlowDown = CurTime() + 1
end
[/lua]

Initialize
[lua]self.CrTime = CurTime() + 3 // set the timer to 3 seconds
[/lua]

Think
[lua]
if math.Round(self.CrTime - CurTime()) == 0 then // If our timer goes to 0

end
[/lua]

Every time you spawn another entity timer is reset already.


timer.Simple( 3, SafeRemoveEntity( self.Entity ) )

No more think.

Did my test in a think hook
[lua]
//lua_run local ply = Entity(1) local ent = ents.Create(“mariofireball”) ent:SetPos(ply:GetEyeTrace().HitPos + ply:GetEyeTrace().HitNormal * 16 ) ent:Spawn() ent:Activate()

AddCSLuaFile()

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

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

-- Use the doll model
self.Entity:SetModel( "models/props_c17/doll01.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS );
self:SetSolid( SOLID_VPHYSICS )
self.Entity:SetGravity( 0.5 );

-- Use the model's physics
//self.Entity:PhysicsInitSphere(7, "metal");
self.Touched = 0
self.SlowDown = 0
self.CrTime = CurTime() + 3
-- Wake the physics object up. It's time to have babies!
local phys = self.Entity:GetPhysicsObject();
if (phys:IsValid()) then
    phys:Wake()
end

end


– Purpose:
– Input : *pOther -

function ENT:Touch( pOther )

self.Touched = 1

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();

if( self.Entity:GetOwner() && self.Entity:GetOwner():IsPlayer() ) then
    local dmgInfo = DamageInfo();
    dmgInfo:SetInflictor( self.Entity );
    dmgInfo:SetAttacker( pOther );
    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( pOther );
    dmgInfo:SetDamage( 0 );
    dmgInfo:SetDamageType( bit.bor( DMG_BURN, DMG_PREVENT_PHYSICS_FORCE ) );
    dmgInfo:SetDamagePosition( tr2.HitPos );
	//print(dmgInfo, vecNormalizedVel, tr2.HitPos)
    pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr2.HitPos );
    pOther:Ignite(30, 0)
    timer.Simple(30, function() if pOther:Health() &gt; 0 then pOther:Extinguish() end end)
end

SafeRemoveEntityDelayed( self.Entity, 0.1 );

end

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

end

function ENT:Think()
if CurTime() >= self.SlowDown then
if math.Round(self.CrTime - CurTime()) == 0 and self.Touched ~= 1 then
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 1 )
util.Effect( “Explosion”, effectdata )
SafeRemoveEntityDelayed( self.Entity, 0.1 )
end
self.SlowDown = CurTime() + 1
end
end

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

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

end[/lua]

ENT:Touch( pOther ) // SafeRemoveEntityDelayed( self.Entity, 0.1 ); The entity will only get removed when it touches something and not the world only works on Entitys / Players

Added self.Touched check, or it’ll crash you.

Works perfectly now, Only problem is timer.Simple stops working when you remove the entity if removed to early so you may want to delay the remove to another 0.2 or 0.3 seconds.

If I did that, it would also have to check the health. If health is 0, ignite it and stay alive. If it’s -1, do nothing except bounce.
I still need to program the bounce logic.

[editline]13th December 2012[/editline]



[ERROR] lua/entities/mariofire/init.lua:29: bad argument #2 to 'Simple' (function expected, got no value)
  1. Simple - [C]:-1
   2. unknown - lua/entities/mariofire/init.lua:29
    3. Spawn - [C]:-1
     4. unknown - lua/weapons/mario_fireballs/shared.lua:77



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


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

	-- Use the doll model
	self.Entity:SetModel( "models/props_c17/doll01.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, metal);
	self.CrTime = CurTime() + 3;
	self.LifeLeft = 1;
	-- 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, SafeRemoveEntity( self.Entity ) )

end


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

	local	tr;
	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( tr.HitPos );
		pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr.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( tr.HitPos );
		pOther:DispatchTraceAttack( dmgInfo, vecNormalizedVel, tr.HitPos );
		pOther:Ignite(30, 0)
		timer.Simple(30, pOther.Extinguish() )
	end

	self.Entity:Remove();

	-- 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 = tr.HitPos + tr.HitNormal
	local Pos2 = tr.HitPos - tr.HitNormal
--	util.Decal( "Blood", Pos1, Pos2 )	-- Scorch!

	if pOther:IsNPC() or pOther:IsPlayer() then 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
	timer.Simple(5, function() 
			local vPoint = self:GetPos()
			local effectdata = EffectData()
			effectdata:SetStart( vPoint )
			effectdata:SetOrigin( vPoint )
			effectdata:SetScale( 1 )
			util.Effect( "Explosion", effectdata )
			if IsValid(self) then
				self:Remove() 
			end
	end)
    end
end

	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]]

	SafeRemoveEntityDelayed( self.Entity, 0.1 );

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






[editline]13th December 2012[/editline]

I’d prefer to be told what to change, not be given a whole block of code.

[lua][ERROR] lua/entities/mariofire/init.lua:29: bad argument #2 to ‘Simple’ (function expected, got no value)

  1. Simple - [C]:-1
  2. unknown - lua/entities/mariofire/init.lua:29
    3. Spawn - [C]:-1
    4. unknown - lua/weapons/mario_fireballs/shared.lua:77

timer.Simple(30, pOther.Extinguish() )
[/lua]
It’s saying you need a function now in timer.Simple

[lua]timer.Simple(30, function() pOther.Extinguish() end)[/lua]

For bouncing you can look at sent_ball.lua source code

Change:
[lua]self.Entity:PhysicsInitSphere(7, metal);[/lua]
to
[lua]self:PhysicsInitSphere( 16, “metal_bouncy” )[/lua] Default is 16 I think

Read the wiki and learn what each bit does, then you’ll understand what my code does, it does the exact same thing what yours does.

Isn’t that inches, though??

It’s in a Sphere so basically like a circle how big the ball is, or prop.

Yes, but the wiki says it’s radius, not diameter. Radius = 1/2, Diameter = 100%, in total width.


self.Entity:PhysicsInitSphere(7, foliage);

I think the 2nd argument should be a string, like garry has his in sent_ball.lua.