1. Post #1
    I GOT BRAIN DAMAGE BECAUSE I'M AN IDIOT
    luavirusfree's Avatar
    August 2006
    580 Posts
    I am certain that this code is not 100% finished, but I want to know what errors might reside within it. I would also like to know if ALL of the code works as I want it (Like getting an angle for the surface normal).
    This is the fireball's code:
    Init.lua
    -- This code is not complete!
    I need to add the deflection off of surfaces who's Normal is not level to be accurate.
    Code:
    AddCSLuaFile( "cl_init.lua" )AddCSLuaFile( "shared.lua" )
    include("shared.lua")
    
    
    local XVelCur = self.Entity:GetVelocity().x
    local YVelCur = self.Entity:GetVelocity().y
    local ZVelCur = self.Entity:GetVelocity().z
    
    
    function ENT:Initialize()
    	timer.Simple( 0.05, function()
    		XVelCur = self.Entity:GetVelocity().x;
    		YVelCur = self.Entity:GetVelocity().y;
    		end)
    	self.Entity:SetModel( "models/error.mdl" )
    --	self.Entity:PhysicsInit( SOLID_VPHYSICS )
    	self.Entity:PhysicsInitSphere( 15 )
    	self.Entity:SetMoveType( MOVETYPE_FLY )
    	self.Entity:SetSolid( SOLID_VPHYSICS )	-- BBox would not work.
    	self.Entity:SetUseType(SIMPLE_USE)	-- Should hit the user.
    	local phys = self.Entity:GetPhysicsObject()
    	if (phys:IsValid()) then
    		phys:Wake()
    	end
    end
    
    
    local EntHit = nil
    
    
    function ENT:Think()
    	ZVelCur = self.Entity:GetVelocity().z
    ----other functions
    
    
    	if XVelCur != self:GetPhysicsObject():GetVelocity().x then
    		local CurVelX = self:GetPhysicsObject():GetVelocity().x
    		local AddVel = XVelCur - CurVelX
    		self:GetPhysicsObject():AddVelocity(AddVel)
    	end
    
    
    	if self.PlayerUsing != nil then
    		if self.PlayerUsing:Alive() == true then
    			self.PlayerUsing:Kill()
    		end
    	end
    end
    
    
    function ENT:Touch( hitEnt )
    	local dmginfo = DamageInfo()
    		dmginfo:SetDamage( 20 ) -- Almost 1 HP
    		dmginfo:SetDamageType( DMG_BURN ) -- Fire damage... sortof.
    		dmginfo:SetAttacker( self.Owner ) -- The Owner Wins!
    		dmginfo:SetDamageForce( Vector( 0, 0, 0 ) ) --No force!
    	if hitEnt:IsValid() then
    		if hitEnt:IsPlayer() or hitEnt:IsNPC() or hitEnt:Health() > 0 then
    			hitEnt:TakeDamageInfo(dmginfo)
    			hitEnt:Ignite(math.Random(4,20), 0)	-- Catch on fire for anywhere between 4 seconds, and 20 seconds. Will increase damage, and burn after death.
    		end
    	end
    	EntHit = hitEnt
    	self:Remove()
    end
    
    
    function ENT:Remove()
    	EntHit = nil	-- We hit nothing, anymore.
    end
    
    
    
    
    function ENT:SpawnFunction( ply, tr )
    	if ( !tr.Hit ) then
    		return
    	end
    	local SpawnPos = tr.HitPos + tr.HitNormal * 16
    	local ent = ents.Create( "mariofire" )
    	ent:SetPos( SpawnPos )
    	ent:Spawn()
    	ent:Activate()
    	ent.Owner = ply
    end
    
    
    function ENT:PhysicsCollide( data, physobj )
    			ParticleEffect("FireBallHit",data.HitPos,Angle(0,0,0),nil)	-- Hit FX, for whatever it was that we hit... ANYTHING! not air
    --	local z = self.Entity:GetAngles() --(Shouldn't change, ever)
    	local ballphys = self:GetPhysicsObject()
    	local NewVelocityDefault = Angle(45,0,0) * -64	-- 64 unit speed.
    	local SurfNorm = data.HitNormal:GetAngle()
    	local VelCurrent = Vector(XVelCur, YVelCur, ZVelCur)
    	-- Bounce off an irregular surface. ToDo: Figure the equation in New Super Mario Bros. Wii, and apply it.
    	if SurfNorm.p == 0 then
    		-- Regular Bounce
    			ballphys:SetVelocity( NewVelocityDefault+XVelCur+YVelCur )
    	elseif SurfNorm.p != 0 then
    		if SurfNorm.p > 45 or SurfNorm.p < -45 then	-- We can't bounce this much! The angle would make us go up too much.
    			self:Remove()
    			return
    		elseif SurfNorm.p >= -45 && SurfNorm.p < 0 then	-- It is going UP!
    			-- NOT realistic, these physics.
    		--	local VertVel = ballphys:GetVelocity().z
    		--	if VertVel < 0 then	-- We are going down...
    			local NewVelocityDefault2 = (Angle(45,0,0) + SurfNorm.p/3) * -64
    			ballphys:SetVelocity( (VelCurrent)+(NewVelocityDefault) )	-- We go DOWN
    		--	end
    		elseif SurfNorm.p <= 45 && SurfNorm.p > 0 then	-- It are going DOWN!
    			local NewVelocityDefault2 = (Angle(-45,0,0) + SurfNorm.p/3) * -64
    			ballphys:SetVelocity( (VelCurrent)+(NewVelocityDefault) )	-- We go DOWN
    		end
    	end
    end
    Cl_init.lua
    Code:
    include('shared.lua')local IVis = false
    
    
    function ENT:Initialize()
        PrecacheParticleSystem("Fireball")
        PrecacheParticleSystem("FireBallHit")
        local IVis = true
    end
    
    
    function ENT:Draw()
        if not IVis then
            local IVis = false
        end
    --    self.Entity:DrawModel()    -- We don't want a model for the fireballs.
        -- Create a parented particle effect. When we hit, create one there, too.
        if IVis then
            local CPoint0 = {
                ["entity"] = self
                ["attachtype"] = PATTACH_ABSORIGIN_FOLLOW
                }
            self:CreateParticleEffect("Fireball",{CPoint0})
        end
    end
    
    
    function ENT:PhysicsCollide( data, physobj )
        ParticleEffect("FireBallHit",data.HitPos,Angle(0,0,0),nil)
    end
    
    
    function ENT:Remove()
        self:StopParticleEmission( "Fireball" )    -- If it doesn't stop with our death, force it to stop.
    end
    Shared.lua
    Code:
    include('cl_init.lua')include('init.lua')
    
    
    ENT.Type = "anim"
    ENT.PrintName = "Fireball"
    ENT.Author = "LuaVirusFree"
    ENT.Category = "New Super Mario Bros. PC"
    ENT.Spawnable = false
    ENT.AdminSpawnable = false
    ENT.Information = "Hot; It hurts!"
    You rate me dumb, but I hold fear. Also, I don't want to run this, just to get errors... oh, that was just brandonj4, again....
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Dumb Dumb x 4Funny Funny x 1 (list)

  2. Post #2
    Awesome Gmod Servers!
    brandonj4's Avatar
    September 2011
    2,065 Posts
    I am certain that this code is not 100% finished, but I want to know what errors might reside within it. I would also like to know if ALL of the code works as I want it.

    You rate me dumb, but I hold fear. Also, I don't want to run this, just to get errors... oh, that was just brandonj4, again....
    Do you know how fucking stupid you sound?
    Reply With Quote Edit / Delete Reply Windows 7 Canada Show Events Agree Agree x 2Funny Funny x 1 (list)

  3. Post #3
    Gold Member
    LedZepp's Avatar
    June 2012
    233 Posts
    just out of curiosity, why would you ask what errors there are when for 1.) the console will tell you and 2.) test it if its not fully finished?
    Reply With Quote Edit / Delete Reply Windows 8 United States Show Events Funny Funny x 1 (list)

  4. Post #4
    I GOT BRAIN DAMAGE BECAUSE I'M AN IDIOT
    luavirusfree's Avatar
    August 2006
    580 Posts
    Uhm, because the last time I tried to make this, I asked for help on the problems, and the one person who was helping me got BANNED! ... so I don't want that to happen again!
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Dumb Dumb x 4Artistic Artistic x 1 (list)