+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

  1. #1
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    Ok, I have spent like exactly 1 weak for doing this (:O) and I know they are not perfect or anything, but here I present to all you holo-lovers out there...

    The Holo Combat System! (HCS for short)

    Basicly, it is 2 different codes cooperating via globals. There is 3 "modes" for firing, and then there is the target code, checking if it got hit, and if so, apply dmg and return hitpos (if attacker want to create a fx). Everything uses 1 globals and then sets a hit-global for hitpos, but this is not surely a good thing, as if there is to many things firing (or a weapon with to high rof), they will start override eachothers.
    Make sure that the variables is not conflicting with anything/eachothers when adding HCS.
    HCS is also made to work without regards to pp, if you dont like that, just remove gShare(1)
    I made sure to make it only use stuff in the regular wire svn (except the tank e2, it uses e2 hud aswell).

    There is a bit of story of why I made this system, it all started here and then went on to here, ending here (as in this thread).

    Credits:
    Wiremod team, especially the ones creating e2.
    Everyone who showed enough enthusiasm to make me finish this, and those who showed enough to make me upgrade it.
    Everyone and anyone who tested my beta (even if they didnt know they were testing a beta) and gave feedback.
    Anyone I forgot.

    Special thanks to:
    Rynox and his little turtle for always being at server to give me feedback.
    Myself, for not buying ME2 immediately and getting stuck in it instead.


    HCS - Shooter

    This is the attacking code, made so a owner can just walk around using his mouse and use keys to fire. The ID is to make an individual global that returns hitpos. The flag is if it shall hit every target on a row, or only one (if false, it only hit the target with the youngest e2).
    Code:
    @name HCS-Shooter
    @inputs 
    @outputs 
    @persist ID:string Range Time
    @trigger 
    
    interval(100)
    
    if (first() | duped()) {
        gShare(1)
        
        Range = 1000
        ID = entity():id():toString()
        
        holoCreate(1)
        holoScaleUnits(1,vec(10,10,10))
        holoModel(1,"hqsphere")
        holoMaterial(1,"models/effects/splode_sheet")
        holoAlpha(1,0)
    }
    
    signalSetGroup("HCS")
    if (owner():keyAttack1()) {
        Mode = 1
        Time = curtime()
        Damage = 25*$Time
        Origin = owner():shootPos()
        OriginDirVec = owner():eye()
        
        DamageArray = array(Mode,Time,""+Damage,Origin,OriginDirVec,Range,ID,0)
        
        gSetStr("Damage",glonEncode(DamageArray))
        signalSend("Damage",1)
        
        holoScaleUnits(1,vec(10,10,10))
    }
    
    if (owner():keyAttack2()) {
        Mode = 2
        Time = curtime()
        ExplosionDamage = 100*$Time
        Radius = 100
        Falloff = 0.1
        Pos = owner():aimPos()
        
        DamageArray = array(Mode,Time,""+ExplosionDamage,Radius,Falloff,Pos,ID,0)
        
        gSetStr("Damage",glonEncode(DamageArray))
        signalSend("Damage",1)
        
        holoScaleUnits(1,vec(Radius,Radius,Radius)/2*1.04)
    }
    
    if (owner():keyUse()) {
        Mode = 3
        Time = curtime()
        Damage = 10*$Time
        ExplosionDamage = 25*$Time
        Radius = 100
        Falloff = 0.01
        Origin = owner():shootPos()
        OriginDirVec = owner():eye()
        
        DamageArray = array(Mode,Time,""+Damage,""+ExplosionDamage,Radius,Falloff,Origin,OriginDirVec,Range,ID,0)
        
        gSetStr("Damage",glonEncode(DamageArray))
        signalSend("Damage",1)
        
        holoScaleUnits(1,vec(Radius,Radius,Radius)/2*1.04)
    }
    
    #Effect
    HitArray = glonDecode(gGetStr(ID+"Hit"))
    if (HitArray:count()) {
        for (I=1,HitArray:count()) {
            HitPos = HitArray[I,vector]
            holoAlpha(1,100)
            holoPos(1,HitPos)
        }
        gSetStr(ID+"Hit","")
    } else {
        #holoAlpha(1,0)
    }
    HCS - Dummy

    It is kind of easy to copypasta to bottom of e2, just make code for what shall happen on death and make sure variables dont collide with your variables.
    Code:
    @name HCS-Dummy
    @inputs 
    @outputs Health
    @persist E:entity HoloID Scale DamageArray2:array
    @trigger 
    
    if (first() | duped()) {
        gSetStr("Damage","")
        signalSetGroup("HCS")
        runOnSignal("Damage",1,1)
        gShare(1)
        
        Health = 100
        Scale = 25
        
        holoCreate(1)
        holoScaleUnits(1,vec(Scale,Scale,Scale)*1.04)
        holoModel(1,"hqsphere")
        holoAlpha(1,100)
        holoParent(1,entity())
        
        holoCreate(2)
        holoScaleUnits(2,vec(2,2,2))
        holoParent(2,entity())
        
        E = holoEntity(1)
        HoloID = E:id()
    }
    
    #Damage-taking
    if (signalClk("HCS","Damage",1)) { 
        DamageArray = glonDecode(gGetStr("Damage"))
        
        Mode = DamageArray[1,number]
        Time = DamageArray[2,number]
        
        if (Mode == 1) {
            # getting the variables I need to use #
            Damage = DamageArray[3,string]:toNumber()
            Origin = DamageArray[4,vector]
            OriginDirVec = DamageArray[5,vector]:normalized()
            Range = DamageArray[6,number]
            ID = DamageArray[7,string]
            Flag = DamageArray[8,number]
            
            Plane = E:pos() #Get the planes center
            P1 = Origin #Get a point on the line
            P2 = Origin+OriginDirVec #Get a point on the line "after" point 1
            Normal = -OriginDirVec #Get the normal (a vector pointin straight out of the surface) of the plane
            X = Normal:dot(Plane-P1)/Normal:dot(P2-P1) #Not really sure how, but it returns how many times the distance from point 1 to point 2 you need to go from point 1 to reach the intersection
            HitPos = P1+X*(P2-P1) #Get the intersections position
            
            if(HitPos & X > 0) {
                A = Plane:distance(HitPos)
                C = Scale/2
                if (A < C) {
                    B = sqrt(C^2-A^2)
                    HitPos = HitPos+Normal:normalized()*B
                    
                    Distance = HitPos:distance(Origin)
                    if (Distance < Range) {
                        HitArray = glonDecode(gGetStr(ID+"Hit"))
                        
                        if (Flag | !HitArray[1,vector]) {
                            HitArray:pushVector(HitPos)
                            gSetStr(ID+"Hit",glonEncode(HitArray))
                            
                            Hit = 1
                        }
                    }
                }
            }
        } elseif (Mode == 2) {
            ExplosionDamage = DamageArray[3,string]:toNumber()
            Radius = DamageArray[4,number]
            Falloff = DamageArray[5,number]
            Origin = DamageArray[6,vector]
            ID = DamageArray[7,string]
            Flag = DamageArray[8,number]
            
            Target = E:pos()
            Distance = Origin:distance(Target)
            if (Distance <= Radius) {
                Hit = 1
                
                Damage = ExplosionDamage/(Distance*Falloff+1)
                
                HitArray = glonDecode(gGetStr(ID+"Hit"))
                
                if (Flag | !HitArray[1,vector]) {
                    HitArray:pushVector(Origin)
                    gSetStr(ID+"Hit",glonEncode(HitArray))
                }
            }
        } elseif (Mode == 3) {
            Damage = DamageArray[3,string]:toNumber()
            ExplosionDamage = DamageArray[4,number]
            Radius = DamageArray[5,number]
            Falloff = DamageArray[6,number]
            Origin = DamageArray[7,vector]
            OriginDirVec = DamageArray[8,vector]:normalized()
            Range = DamageArray[9,number]
            ID = DamageArray[10,string]
            Flag = DamageArray[11,number]
            
            Plane = E:pos() #Get the planes center
            P1 = Origin #Get a point on the line
            P2 = Origin+OriginDirVec #Get a point on the line "after" point 1
            Normal = -OriginDirVec #Get the normal (a vector pointin straight out of the surface) of the plane
            X = Normal:dot(Plane-P1)/Normal:dot(P2-P1) #Not really sure how, but it returns how many times the distance from point 1 to point 2 you need to go from point 1 to reach the intersection
            HitPos = P1+X*(P2-P1) #Get the intersections position
            
            if(HitPos & X > 0) {
                A = Plane:distance(HitPos)
                C = Scale/2
                if (A < C) {
                    B = sqrt(C^2-A^2)
                    HitPos = HitPos+Normal:normalized()*B
                    
                    Distance = HitPos:distance(Origin)
                    if (Distance < Range) {
                        HitArray = glonDecode(gGetStr(ID+"Hit"))
                        
                        if (Flag | !HitArray[1,vector]) {
                            HitArray:pushVector(HitPos)
                            gSetStr(ID+"Hit",glonEncode(HitArray))
                            
                            Hit = 1
                            
                            DamageArray2 = array(2,curtime(),ExplosionDamage,Radius,Falloff,HitPos,ID,0)
                            if (A <= Radius) {
                                Hit = 1
                                
                                Damage+= ExplosionDamage/(Distance*Falloff+1)
                            }
                            timer("explosion",0)
                        }
                    }
                }
            }
        }
    } elseif (clk("explosion")) {
        gSetStr("Damage",glonEncode(DamageArray2))
        signalSetGroup("HCS")
        signalSend("Damage",1)
    }
    
    if (Hit) {
        Health-=Damage
    }
    
    if (Health <= 0) {
        holoColor(1,vec(255,0,0))
    }

    The holo tank example!

    I know many people would get quite confused if I didnt post an example, so here it is. I made this for debugging, improving and whatnot to the HCS, aswell as to let you get a fun holo game, that you also can read to see how to sucesfully implement HCS.
    Now, I know this is half-assed in some aspects, such as I skipped adding a ranger forward to make you not go into walls, but this e2 is mostly made for the joy of playing, and I must say going trough walls in a interesting tactic.

    Ctrls
    Code:
    W/S - Forward/Backward.
    A/D - Turn left/right.
    Shift - Go faster.
    Alt - Go slower.
    Space - Hold to get turret view, and have ability to aim on the z axis aswell.
    
    F - Toggles the turret follow tank or not (as in, if you turn, you still aim same dir, but if you press f then turn 90 degrees, your aim does to).
    Mouse - Aim turret (not in height, interesting for game mechanics, and not as annoying when aiming)
    LMB - Shoots a laser, dmg = 1 and rof = 10, so quite weak.
    RMB - Shoots an explosive bullet in an arc, uses V = V0+a*t (just like tanks gravity).
    The tank

    Here is the code for the tank, it is simple to wire, just make a pod, an adv pod ctrl (linked to pod) and wire the wirelink, cam ctrlr (linked to pod) and wire activate to pod ctrlrs active, position to e2s view and angle to e2s angle.
    If you want another color then white, there is a variable in the first().
    It can also pass gaps that is less then 10 units wide. as I also made the rangers responsible for angling tank right work for checking if it hit ground (10 units between them).
    Code:
    @name Holo-Tank
    @inputs XWL:wirelink
    @outputs View:vector Angle:angle
    @persist [Pod E Turret]:entity
    @outputs [BulletArray BulletGravArray ModeArray DamageArray2]:array
    @persist Speed SavedTime Fixed
    @persist ShootCount HoloID HoloIDLength Scale Radius DealDamage DealExplosionDamage DealRadius DealFalloff Health
    @persist G V Mass IfDef
    @trigger 
    
    #First
    if (duped() | inputClk()) {
        reset()
    }
    
    if (first()) {
        runOnTick(1)
        runOnChat(1)
        
        gSetStr("Damage","")
        signalSetGroup("HCS")
        runOnSignal("Damage",1,1)
        gShare(1)
        
        Pod = XWL["Entity",entity]
        
        Scale = 1
        Color = vec(255,255,255)
        
        G = 9.82*2
        Mass = 100
        
        ShootCount = 19
        Radius = 5
        DealDamage = 10
        DealExplosionDamage = 42
        DealRadius = 25
        DealFalloff = 0.1
        Health = 100
        
        
        holoCreate(1)
        holoScaleUnits(1,vec(1,1,1))  
        E = holoEntity(1)
        HoloID = E:id()
        HoloIDLength = HoloID:toString():length()
        
        holoCreate(2)
        holoModel(2,"hqcylinder")
        holoColor(2,Color)
        holoScaleUnits(2,vec(12.5,4,7.5))
        holoPos(2,E:toWorld(vec(0,0,0)))
        holoAng(2,E:toWorld(ang(0,0,90)))
        holoParent(2,E)
        
        holoCreate(3)
        holoModel(3,"hqcylinder")
        holoColor(3,vec(0,0,0))
        holoScaleUnits(3,vec(15,4,2.5))   
        holoPos(3,E:toWorld(vec(-2.5,5,-1.5)))
        holoAng(3,E:toWorld(ang(0,0,90)))
        holoParent(3,E)
        holoCreate(4)
        holoModel(4,"hqcylinder")
        holoColor(4,vec(0,0,0))
        holoScaleUnits(4,vec(15,4,2.5))   
        holoPos(4,E:toWorld(vec(-2.5,-5,-1.5)))
        holoAng(4,E:toWorld(ang(0,0,90)))
        holoParent(4,E)
        
        holoCreate(5)
        holoModel(5,"hqcylinder")
        holoColor(5,Color)
        holoScaleUnits(5,vec(16,3,3))   
        holoPos(5,E:toWorld(vec(-2.5,5,-0.5)))
        holoAng(5,E:toWorld(ang(0,0,90)))
        holoParent(5,E)
        holoCreate(6)
        holoModel(6,"hqcylinder")
        holoColor(6,Color)
        holoScaleUnits(6,vec(16,3,3))   
        holoPos(6,E:toWorld(vec(-2.5,-5,-0.5)))
        holoAng(6,E:toWorld(ang(0,0,90)))
        holoParent(6,E)
        
        holoCreate(7)
        holoModel(7,"hqcylinder")
        holoColor(7,Color)
        holoScaleUnits(7,vec(5,5,1))   
        holoPos(7,E:toWorld(vec(0,0,2)))
        holoAng(7,ang(0,0,0))
        holoParent(7,E)
        Turret = holoEntity(7)
        
        holoCreate(8)
        holoModel(8,"dome")
        holoColor(8,Color)
        holoScaleUnits(8,vec(10,7.5,3.5))   
        holoPos(8,Turret:toWorld(vec(0,0,0)))
        holoAng(8,ang(0,0,0))
        holoParent(8,Turret)
        
        holoCreate(9)
        holoModel(9,"cube")
        holoColor(9,Color)
        holoScaleUnits(9,vec(3,5,1))   
        holoPos(9,Turret:toWorld(vec(-4,0,0.5)))
        holoAng(9,ang(10,0,0))
        holoParent(9,Turret)
        
        holoCreate(10)
        holoModel(10,"dome")
        holoColor(10,Color)
        holoScaleUnits(10,vec(3,3,2))   
        holoPos(10,Turret:toWorld(vec(-1,0,1)))
        holoAng(10,ang(0,0,0))
        holoParent(10,Turret)
        
        holoCreate(11)
        holoModel(11,"prism")
        holoColor(11,Color)
        holoScaleUnits(11,vec(2,1,1))   
        holoPos(11,Turret:toWorld(vec(2,0,1.4)))
        holoAng(11,ang(25,0,0))
        holoParent(11,Turret)
        
        holoCreate(12)
        holoModel(12,"hqcylinder")
        holoColor(12,Color)
        holoScaleUnits(12,vec(1.5,1.5,2))   
        holoPos(12,Turret:toWorld(vec(4,0,0.5)))
        holoAng(12,ang(90,0,0))
        holoParent(12,Turret)
        
        holoCreate(13)
        holoModel(13,"hqcylinder")
        holoColor(13,Color)
        holoScaleUnits(13,vec(1,1,5))   
        holoPos(13,Turret:toWorld(vec(7,0,0.5)))
        holoAng(13,ang(90,0,0))
        holoParent(13,Turret)
        
        holoCreate(18)
        holoModel(18,"hqcylinder")
        holoMaterial(18,"models/effects/splode_sheet")
        holoAlpha(18,0)
        holoScaleUnits(18,vec(1,1,1000))
        holoPos(18,Turret:toWorld(vec(300,0,0.5)))
        holoAng(18,ang(90,0,0))
        holoParent(18,Turret)
        
        holoCreate(19)
        holoModel(19,"hqsphere")
        holoMaterial(19,"models/effects/splode_sheet")
        holoAlpha(19,0)
        holoScaleUnits(19,vec(100,100,100))
    }
    
    #Stuff
    Time = curtime()
    DeltaTime = Time-SavedTime
    Driver = Pod:driver()
    
    if (changed(Driver) & Driver) {
        timer("physics",0)
        timer("bullets",0)
        Health = 100
    } elseif (changed(Driver)) {
        Angle = entity():angles()
        Pos = entity():pos()
        holoPos(1,Pos)
        holoAng(1,Angle)
        #Pod:setView(0,E:pos(),E:angles())
    }
    
    if (Driver) {
        #Wirelinks
        W = XWL["W",number]
        S = XWL["S",number]
        A = XWL["A",number]
        D = XWL["D",number]
        Space = XWL["Space",number]
        Shift = XWL["Shift",number]
        Alt = XWL["Alt",number]
        F = XWL["Light",number]
        LMB = XWL["Mouse1",number]
        RMB = XWL["Mouse2",number]
        
        if (changed(F) & F) {
            Fixed = !Fixed
        }
        
        #Steer
        Pi = pi()
        Pos = E:pos()
        Forward = E:forward()
        Right = E:right()
        Up = E:up()
        
        Speed = ((1+Shift/2)/(1+Alt))/2
        Pos+= Forward*Speed*(W-S/2)
        Yaw = Speed/2*(A-D)
        
        #Collision detection for forward and backward, will enable when they can drive on slopes.
    #    RD = rangerOffset(Speed+10,Pos,Forward)
    #    if (RD:hit()) {
    #        Pos = E:pos()
    #    }
    #    RD = rangerOffset(Speed+15,Pos,-Forward)
    #    if (RD:hit()) {
    #        Pos = E:pos()
    #    }
       
        if (changed(LMB) & LMB) {
            timer("laser",0)
        }
        if (changed(RMB) & RMB) {
            timer("Cannon",0)
        }
        
        #Physics
        if (clk("physics")) {
            PhysicTime = 0.01
            Ek = 0.5*Mass*V
            V+= G*PhysicTime
            
            RD = rangerOffset(V+3,Pos,vec(0,0,-1))
            RD1 = rangerOffset(15,Pos+Forward*5,vec(0,0,-1))
            RD2 = rangerOffset(15,Pos-Forward*5,vec(0,0,-1))
            RD3 = rangerOffset(15,Pos+Right*5,vec(0,0,-1))
            RD4 = rangerOffset(15,Pos-Right*5,vec(0,0,-1))
            if (!RD:hit() & !RD1:hit() & !RD2:hit() & !RD3:hit() & !RD4:hit()) {
                Pos-= vec(0,0,V)
            } else {
                Health-= clamp(Ek/5,42,150)-42
                V = 0
                Pos = Pos:setZ((RD:position():z()+3))
                
                if (RD1:hit() & RD2:hit()) {
                    TankPitch = (RD1:position()-RD2:position()):toAngle():pitch()
                } else {
                    TankPitch = E:angles():pitch()
                }
                if (RD3:hit() & RD4:hit()) {
                    TankRoll = (RD3:position()-RD4:position()):toAngle():pitch()
                } else {
                    TankRoll = E:angles():roll()
                }
                
                TankAng = ang(TankPitch,E:angles():yaw()+Yaw,TankRoll)
                holoAng(1,TankAng)
                #holoAng(1,(RD:hitNormal()):toAngle()+ang(90,E:angles():yaw(),0))
            }
            timer("physics",1000*PhysicTime)
        }
        
        #Get Aim-stuff
        RD = rangerOffset(1337,Pos,E:forward())
        AimEntity = RD:entity()
        Owner = AimEntity:owner()
        AimPos = RD:position()
        
        #Shoot/Use
        if (changed(LMB)) {
            holoEntity(13):soundPlay(2,99,"synth/white_noise.wav")
            soundVolume(2,0.4) 
        }
        
        if (clk("laser") & LMB) {
            ID = HoloID:toString()
            
            DamageArray = array(1,Time,""+1,Pos,Turret:forward(),1000,ID,1)
        
            gSetStr("Damage",glonEncode(DamageArray))
            
            signalSetGroup("HCS")
            signalSend("Damage",1)
            
            holoAlpha(18,150)
            timer("laser",100)
        } elseif (!LMB) {
            soundStop(2)
            holoAlpha(18,0)
        }
        
        if (clk("Cannon") & RMB) {
            if (BulletArray:count() < 10) {
                if (ShootCount < 29) {
                    ShootCount++
                } else {
                    ShootCount = 20
                }
                if (ModeArray[BulletArray[ShootCount,number],number] != 1) {
                    holoCreate(ShootCount)
                    holoModel(ShootCount,"hqsphere")
                    holoScaleUnits(ShootCount,vec(1,1,1))
                    holoMaterial(ShootCount,"")
                    holoAlpha(ShootCount,255)
                    holoPos(ShootCount,Turret:toWorld(vec(10,0,0)))
                    holoAng(ShootCount,Turret:angles())
                    Count = BulletArray:count()+1
                    BulletArray[Count,number]=ShootCount
                    BulletGravArray[Count,number]=-pi()
                    ModeArray[Count,number]=1
                    
                    holoEntity(13):soundPlay(1,0.1,"synth/brown_noise.wav") 
                }
                timer("Cannon",1000)
            }
        }
        
        #Set holoPos, holoAng and view
        holoPos(1,Pos)
        holoAng(1,E:toWorld(ang(0,Yaw,0)))
        
        Eye = Driver:eye()
        if (!Fixed) {
            View = E:pos()-Eye*25*(1-Space)
        } else {
            View = E:toWorld(-Eye*25*(1-Space))
        }
        ViewRD = rangerOffset(50,View+vec(0,0,50),vec(0,0,-1))
        if (ViewRD:hit()) {
            View = View:setZ(ViewRD:position():z()+5)
        }
        
        if (Space) {
            Angle = Driver:eyeAngles()
            View = View+Turret:up()*4*Space+Turret:forward()*3*Space
        } else {
            Angle = (Turret:pos()-View):toAngle()
        }
        #Pod:setView(1,View,Angle)
        
        if (Space) {
            holoAng(7,Angle)
        } else {
            holoAng(7,E:toWorld(ang(0,Angle:yaw()-E:angles():yaw(),0)))
        }
        
        #ifdef entity:hudRemoveElement(number)
            #Hud
            if (AimEntity:isPlayer()) {
                Driver:hudDrawText(1,AimEntity:name(),50,50,vec(100,200,50),255,1,pi())
            } elseif (AimEntity) {
                Driver:hudDrawText(1,"Owner: "+AimEntity:owner():name(),50,50,vec(100,200,50),255,1,pi())
            } else {
                Driver:hudRemoveElement(1)
            }
            IfDef = 1
            Driver:hudDrawRBox(2,1,40,85,20,3,vec(255,0,0),255)
            Driver:hudDrawRBox(3,1,40,85,(Health/100)*20,3,vec(0,255,0),255)
        #else
            if (IfDef & IfDef != 2) {
                Pod:printDriver("Cant use huds on this srv, so you wont see a healthbar.")
                IfDef = 2
            } elseif (IfDef != 2) {
                IfDef = 1
            }
        #endif
    }
    
    
    
    #########
    #Bullets#
    #########
    
    if (clk("bullets")) {
        BulletTime = 0.05
        BulletSpeed = 1500*BulletTime
        for (I=1,BulletArray:count()){
            BulletMode = ModeArray[I,number]
            if (BulletMode == 1) {
                BulletGravity = BulletGravArray[I,number]+G*BulletTime
                BulletGravArray[I,number] = BulletGravity
                Bullet = BulletArray[I,number]
                BulletEnt = holoEntity(Bullet)
                Origin = BulletEnt:pos()
                DirVec = BulletEnt:toWorld(vec(BulletSpeed,0,0))-vec(0,0,BulletGravity)
                DirVec = DirVec-BulletEnt:pos()
                
                
                #Damage
                ID = HoloID:toString()+"-"+BulletEnt:id():toString()
                
                HitArray = glonDecode(gGetStr(ID+"Hit"))
                HitVec = HitArray[1,vector]
                
                RD = rangerOffset(BulletSpeed,Origin,DirVec)
                
                if (HitVec | RD:hit()) {
                    if (HitVec) {
                        gSetStr(ID+"Hit","")
                    } elseif (RD:hit()) {
                        DamageArray = array(2,Time,DealExplosionDamage,DealRadius,DealFalloff,RD:position(),ID)
                        gSetStr("Damage",glonEncode(DamageArray))
                        
                        HitVec = RD:position()
                        HitEnt = RD:entity()
                        if (HitEnt) {
                            HitEnt:applyOffsetForce(DirVec:normalized()*250,HitVec)
                        }
                    }
                    
                    #Effect
                    #fx("explosion",RD:position(),10)
                    holoScaleUnits(Bullet,vec(DealRadius,DealRadius,DealRadius))
                    holoMaterial(Bullet,"models/effects/splode_sheet")
                    holoAlpha(Bullet,100)
                    holoPos(Bullet,HitVec)
                    
                    #Bullet
                    ModeArray[I,number]=Time
                } else {
                    holoPos(Bullet,BulletEnt:toWorld(vec(BulletSpeed,0,0))-vec(0,0,BulletGravity))
                    
                    DamageArray = array(3,Time,""+DealDamage,""+DealExplosionDamage,DealRadius,DealFalloff,Origin,DirVec,BulletSpeed,ID,0)
                    
                    gSetStr("Damage",glonEncode(DamageArray))
                    
                    signalSetGroup("HCS")
                    signalSend("Damage",1)
                }
            }
        }
        
        RemoveTime = ModeArray[1,number]
        if (RemoveTime != 1 & Time-5 > RemoveTime) {
            holoDelete(BulletArray[1,number])
            BulletArray:remove(1)
            ModeArray:remove(1)
        }
        timer("bullets",1000*BulletTime)
    }
    
    
    
    
    ###############
    #Damage-taking#
    ###############
    
    if (signalClk("HCS","Damage",1)) { 
        DamageArray = glonDecode(gGetStr("Damage"))
        
        Mode = DamageArray[1,number]
        Time = DamageArray[2,number]
        
        if (Mode == 1) {
            # getting the variables I need to use #
            Damage = DamageArray[3,string]:toNumber()
            Origin = DamageArray[4,vector]
            OriginDirVec = DamageArray[5,vector]:normalized()
            Range = DamageArray[6,number]
            ID = DamageArray[7,string]
            Flag = DamageArray[8,number]
            
            Plane = E:pos() #Get the planes center
            P1 = Origin #Get a point on the line
            P2 = Origin+OriginDirVec #Get a point on the line "after" point 1
            Normal = -OriginDirVec #Get the normal (a vector pointin straight out of the surface) of the plane
            X = Normal:dot(Plane-P1)/Normal:dot(P2-P1) #Not really sure how, but it returns how many times the distance from point 1 to point 2 you need to go from point 1 to reach the intersection
            HitPos = P1+X*(P2-P1) #Get the intersections position
            
            if(HitPos & X > 0) {
                A = Plane:distance(HitPos)
                C = Radius
                if (A < C) {
                    B = sqrt(C^2-A^2)
                    HitPos = HitPos+Normal:normalized()*B
                    
                    Distance = HitPos:distance(Origin)
                    if (Distance < Range) {
                        HitArray = glonDecode(gGetStr(ID+"Hit"))
                        
                        if (Flag | !HitArray[1,vector]) {
                            HitArray:pushVector(HitPos)
                            gSetStr(ID+"Hit",glonEncode(HitArray))
                            
                            Hit = 1
                        }
                    }
                }
            }
        } elseif (Mode == 2) {
            ExplosionDamage = DamageArray[3,string]:toNumber()
            ExplosionRadius = DamageArray[4,number]
            Falloff = DamageArray[5,number]
            Origin = DamageArray[6,vector]
            ID = DamageArray[7,string]
            Flag = DamageArray[8,number]
            
            Target = E:pos()
            Distance = Origin:distance(Target)
            if (Distance <= ExplosionRadius) {
                Hit = 1
                
                Damage = ExplosionDamage/(Distance*Falloff+1)
                
                HitArray = glonDecode(gGetStr(ID+"Hit"))
                
                if (Flag | !HitArray[1,vector]) {
                    HitArray:pushVector(Origin)
                    gSetStr(ID+"Hit",glonEncode(HitArray))
                }
            }
        } elseif (Mode == 3) {
            Damage = DamageArray[3,string]:toNumber()
            ExplosionDamage = DamageArray[4,number]
            ExplosionRadius = DamageArray[5,number]
            Falloff = DamageArray[6,number]
            Origin = DamageArray[7,vector]
            OriginDirVec = DamageArray[8,vector]:normalized()
            Range = DamageArray[9,number]
            ID = DamageArray[10,string]
            Flag = DamageArray[11,number]
            
            Plane = E:pos() #Get the planes center
            P1 = Origin #Get a point on the line
            P2 = Origin+OriginDirVec #Get a point on the line "after" point 1
            Normal = -OriginDirVec #Get the normal (a vector pointin straight out of the surface) of the plane
            X = Normal:dot(Plane-P1)/Normal:dot(P2-P1) #Not really sure how, but it returns how many times the distance from point 1 to point 2 you need to go from point 1 to reach the intersection
            HitPos = P1+X*(P2-P1) #Get the intersections position
            
            if(HitPos & X > 0) {
                A = Plane:distance(HitPos)
                C = Radius/2
                if (A < C) {
                    B = sqrt(C^2-A^2)
                    HitPos = HitPos+Normal:normalized()*B
                    
                    Distance = HitPos:distance(Origin)
                    if (Distance < Range) {
                        HitArray = glonDecode(gGetStr(ID+"Hit"))
                        
                        if (Flag | !HitArray[1,vector]) {
                            HitArray:pushVector(HitPos)
                            gSetStr(ID+"Hit",glonEncode(HitArray))
                            
                            Hit = 1
                            
                            DamageArray2 = array(2,curtime(),ExplosionDamage,ExplosionRadius,Falloff,HitPos,ID,0)
                            if (A <= ExplosionRadius) {
                                Hit = 1
                                
                                Damage+= ExplosionDamage/(Distance*Falloff+1)
                            }
                            timer("explosion",0)
                        }
                    }
                }
            }
        }
    } elseif (clk("explosion")) {
        gSetStr("Damage",glonEncode(DamageArray2))
        signalSetGroup("HCS")
        signalSend("Damage",1)
    }
    
    if (Hit) {
        Health-=Damage
    }
    
    if (Health <= 0) {
        #Boom-Code goes here.
        DamageArray = array(2,curtime(),100,100,Falloff,E:pos(),ID)
        
        signalSetGroup("HCS")
        signalSend("Damage",1)
        
        Pod:killPod()
        
        holoAlpha(18,0)
        holoPos(19,E:pos())
        holoAlpha(19,100)
        
        soundStop(1)
        soundStop(2)
        
        Health = 100
        
        timer("boom",5000)
    }
    
    if (clk("boom")) {
        holoAlpha(19,0)
    }
    
    
    SavedTime = curtime()

    Media
    No, I wont record it, I would appreciate if someone else could do that for me tho.


    Other
    Now! Enjoy and make some holo combat games. I noticed helicopters were a very popular suggestion during testing, and I will actually add one soon.
    I would love some feedback, questions, and suggestions!

    If you had not figured it out yet though, this post is about the HCS, with a tank game as an example, so dont expect that I will put any more work into the tank game (yes I might, but it is nothing to be expected), as it is just a example :P.

    If you know a better way to do anything, please tell me!


    tl;dr
    I made a holo comabt system (HCS) that work with globals. Very easy to implement, and very usefull in holo games.
    I also made a example game with holo-tanks using HCS.


    Update!
    Ok, I updated hcs to use signals (dmg is dealt in same tick), return real hitpos (before it was nearest point), use line-plane intersection, have a flag for if it should hit all in a row and such.

    In other words, it is improved.

    I also added a little to the tank.
    Last edited by feha; 05-02-2010 at 03:15 PM. Reason: UPDATE!

  2. #2
    Wire Sofaking Vbitz's Avatar
    Join Date
    Feb 2009
    Location
    NZ
    Posts
    685

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    I love the idea that the e2 work using a common framework, that makes addons easy to do, Good Job +rep.
    Questions, Comments and Concerns about any of
    my posts can be directed to my website which is at
    http://vbitz.wordpress.com on the comments post

    Quote Originally Posted by Bull View Post
    As example Jat Goodwin is "the official bastard of wiremod", but that isn't true.. He's very cute and huggable like a little puppy.

  3. #3
    Wiremod Helper Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,659

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    Nice idea, but the holo-spawning implementation is very poor, you could easily loop it.

    The Olympus Technologies drones, totally not SkyNet in Gmod form.
    Cronus: The Ultimate Drone, definitely SkyNet in Gmod form.
    The gBrain Project, the drone controls system that thinks it's better than you

  4. #4
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    Lol lying, the hcs was main point of thread, I mostly just threwed the tank together from old code (a flying holo cam that could shoot bullets with very inefficient code).

    And what part of holo creation? Cause if you mean in the first(), I see no way to loop create it.

  5. #5
    Wirererer Elmo the Emo Emperor's Avatar
    Join Date
    Feb 2008
    Location
    Lagville(Austrlia)
    Posts
    278

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    if(first(){
    holoCreate(1)
    holoCreate(2)
    }
    Could be done by
    if(first()){for(I = 1,2){holoCreate(I)}}
    Note, I'm not sure if that will work actually, but It's to demonstrate the point.

  6. #6
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    All that would do is saving lines. I actually think it would drain more ops if it is done in loops... It is if you can loop everything (materials, models, pos, angle) that it gets usefull.

  7. #7
    billywitchdoctor.com Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    2,006

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    tl;dr.

    Summary plox.


    [19:16:47]Client "rcdraco" spawned in server
    [19:17:10]rcdraco: hamburgertime
    [19:18:04]rcdraco was killed by worldspawn
    [19:21:50]Dropped "rcdraco" from server

  8. #8
    Wirererer Blob 92's Avatar
    Join Date
    Dec 2009
    Location
    vec( √ -1, √ -1, √ -1 )
    Posts
    222

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    I Cant get the tank to damage anything, do i need an E2 addon/other peice of code for this to work?

  9. #9
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    Say you test this out at my server. Poor Rynos turtle >:D. Looks good, Ill try and add it to my pedobear for the lulz.
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  10. #10
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-holo] Holo Combat System (HCS) and a little holo tank using it.

    Blob, this combat system is not holo to prop, or holo to player, it is holo to another holo using same system (or same globals to be exact).

    So make 2 tanks and they can hit eachothers.

+ Reply to Thread
Page 1 of 2 12 LastLast

LinkBacks (?)

  1. 02-17-2010, 08:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots