Home Showcase
Welcome to the new Diaspora forums, please let us know if you see anything broken! Notice: Some users may need to reupload their avatars due to an issue during forum setup!

Spartan gunner

StarkkzStarkkz Registered Posts: 17
edited October 2014 in Showcase #1
@name Spartan Gunner by Starkkz

@inputs Seat:entity TargetFaction TargetCore TargetExclude:array TargetOwner TargetOwnerProps DisableFire

@persist Anim:string LAnim:string
@persist Pose:string LPose:string PoseAng LPoseAng
@persist AIModel:string AIName:string AIColor:vector

@persist FactionPlayers:array
@persist Bot:entity Chip:entity
@persist Moving TargetPosition:vector TargetAngle:angle
@persist FallVelocity
@persist UpdatingTarget TargetUpdated UpdateI LowestHeading:array
@persist Targets:array

@outputs Fire AimPos:vector Target:entity

if (first()){
    #Model of your AI
    AIModel = "models/voxelzero/player/voxelspartan.mdl"
    
    #Name of your AI
    AIName = "Spartan Gunner by Starkkz"
    
    #The color of your AI
    AIColor = vec(50, 50, 25)
    
    #Enable light effect
    AILight = 0
    
    #Enable material effect
    AIMaterial = 0
    
    Chip = entity()
    timer("updateFactionPlayers", 1)
    timer("updateTargetList", 1)
    timer("updateTarget", 1)
    timer("update", 1)
    
    function say(Text:string){
        local Players = players()
        foreach (I, Player:entity = Players){
            Player:plyPrintSimpleColor(AIName+": "+Text, AIColor)
        }
    }
    
    function entity coreEntity(){
        if (Seat:isValid()){return Seat}
        local Core = Chip:getCoreEnt()
        return Core:isValid() ? Core : Chip
    }
    
    function parentAI(){
        if (Seat:isValid()){
            holoPos(1, Seat:pos())
            holoAng(1, Seat:toWorld(ang(0, 90, 0)))
            holoParent(1, Seat)
        }else{
            holoPos(1, Chip:pos())
            holoParent(1, Chip)
        }
    }
    
    function deparentAI(){
        holoUnparent(1)
    }
    
    function updateFactionPlayers(){
        if (!TargetFaction){
            FactionPlayers = array()
            local Players = players()
            local OwnerFaction = owner():getFaction()
            if (OwnerFaction != "Civilian"){
                foreach (I, Player:entity = Players){
                    if (Player:getFaction() == OwnerFaction){
                        FactionPlayers:pushEntity(Player)
                    }
                }
            }
        }
        timer("updateFactionPlayers", 5000)
    }
    
    function updateTargetList(){
        local Owner = owner()
        findClearWhiteList()
        findClearBlackList()
        findExcludeEntities(TargetExclude)
        if (!TargetFaction){
            findExcludeEntities(FactionPlayers)
            foreach (I, Player:entity = FactionPlayers){
                findExcludePlayerProps(Player)
            }
        }
        if (!TargetOwner){findExcludePlayer(Owner)}
        if (!TargetOwnerProps){findExcludePlayerProps(Owner)}
        if (TargetCore){findIncludeClass("ship_core")}
        findIncludeClass("player")
        findInSphere(Bot:pos(), 9999999999999999999)
        Targets = findToArray()
        timer("updateTargetList", 5000)
    }
    
    function updateTarget(){
        if (UpdatingTarget){
            while (perf()){
                if (UpdateI <= Targets:count()){
                    local Entity = Targets[UpdateI, entity]
                    UpdateI = UpdateI + 1
                    if (Entity:isValid() & Entity:lsName() == "Space"){
                        local HeadingLength = vec(-Bot:heading(Entity:pos())):length()
                        if (!LowestHeading[1, entity]:isValid() | HeadingLength < LowestHeading[2, normal]){
                            LowestHeading = array(Entity, HeadingLength)
                        }
                    }
                }else{
                    Target = LowestHeading[1, entity]
                    LowestHeading = array()
                    UpdateI = 0
                    timer("updateTarget", 1000)
                    exit()
                }
            }
        }else{
            UpdatingTarget = 1
            TargetUpdated = 0
        }
        timer("updateTarget", 1)
    }
    
    function update(){
        if (Target:isValid() & coreEntity():lsName() == "Space" & Target:lsName() == "Space"){
            Fire = !DisableFire
            AimPos = Target:pos()
        }else{
            Fire = 0
            AimPos = vec()
        }
        timer("update", 150)
    }
    
    function updateAI(){
        local ParentEntity = Bot:parent()
        if (!ParentEntity:isValid()){
            local BotPosition = Bot:pos()
            local MovementHeading = -heading(BotPosition, ang(), TargetPosition):setPitch(0)
            local RotationVector = MovementHeading:forward()
            local MiddlePosition = BotPosition + vec(0, 0, 48)
            local TempTargetPosition = TargetPosition:setZ(BotPosition:z())
            
            local ForwardPosition = MiddlePosition + RotationVector * 20
            local R = rangerOffsetHull(ForwardPosition, ForwardPosition, vec(20, 20, 10))
            local R2 = rangerOffset(50, BotPosition + vec(0, 0, 30), vec(0, 0, -1))
            if (R:hit() & TargetPosition != vec()){
                Anim = "act_idle"
                Pose = ""
                PoseAng = 0
            }elseif (R2:hit()){
                local Distance = BotPosition:distance(TempTargetPosition)
                if (Distance > 300 & TargetPosition != vec()){
                    Anim = "run_all"
                    Pose = "move_yaw"
                    PoseAng = Bot:toLocal(MovementHeading):yaw()
                    holoPos(1, R2:pos() + RotationVector * 25)
                }elseif (Distance > 40 & TargetPosition != vec()){
                    Anim = "walk_all"
                    Pose = "move_yaw"
                    PoseAng = Bot:toLocal(MovementHeading):yaw()
                    holoPos(1, R2:pos() + RotationVector * 9)
                }else{
                    Anim = "act_hl2mp_idle_passive"
                    Pose = ""
                    PoseAng = 0
                }
            }else{
                Anim = "act_jump"
                Pose = ""
                PoseAng = 0
                FallVelocity = FallVelocity ? FallVelocity + 5 : 10
                local R3 = rangerOffset(FallVelocity, BotPosition, vec(0, 0, -1))
                if (R3:hit()){
                    FallVelocity = 0
                    holoPos(1, R3:pos())
                }else{
                    holoPos(1, BotPosition - vec(0, 0, 1) * FallVelocity)
                }
            }
            holoAng(1, ang(0, TargetAngle:yaw(), 0))
        }else{
            if (ParentEntity:isVehicle()){
                Anim = "act_hl2mp_sit_passive"
                Pose = ""
                PoseAng = 0
            }else{
                Anim = "act_hl2mp_idle_passive"
                Pose = ""
                PoseAng = 0
            }
        }
        
        if (LAnim != Anim){
            LAnim = Anim
            holoAnim(1, Anim)
        }
        if (LPose != Pose | LPoseAng != PoseAng){
            LPose = Pose
            LPoseAng = PoseAng
            holoSetPose(1, Pose, PoseAng)
        }
        timer("updateAI", 100)
    }
    
    Bot = holoCreate(1)
    holoModel(1, AIModel)
    if (AIMaterial){
        holoMaterial(1, "models/wireframe")
    }
    holoColor(1, AIColor)
    
    if (AILight){
        lightCreate(1)
        lightColor(1, AIColor)
        lightParent(1, Bot)
    }
    
    parentAI()
    updateAI()
    setName(AIName)
}elseif (~Seat){
    reset()
}else{
    ClkName = clkName()
    if (ClkName:length() > 0){ClkName()}
}
Simply a Spartan gunner made in E2, it targets automatically and fires while in space. I just would like to note that I made this for server #2.

Comments

  • NinjrKillrNinjrKillr Registered Posts: 175
    Code not nearly long enough. I contest the 'AI' label in your comments.

    "We fear that which we cannot see... we respect that which we cannot see... thus the blade will be wielded."

    Urahara_Bleach_Signature_by_Harty73.png
  • Lambda217Lambda217 Registered, Moderator Posts: 534
    NinjrKillr wrote:
    Code not nearly long enough. I contest the 'AI' label in your comments.

    we're not doing this AI/VI thing again are we


    "I want you to show this world what it means to fear the sky."
  • StarkkzStarkkz Registered Posts: 17
    Actually I made an AI base E2 from which I make all my different kind of "AI helpers" for my ships. That's why the "AI" as a prefix.
  • NinjrKillrNinjrKillr Registered Posts: 175
    Lambda217 wrote:
    we're not doing this AI/VI thing again are we
    It needs to be said. Often, it seems. :D.
    Starkkz wrote:
    Actually I made an AI base E2 from which I make all my different kind of "AI helpers" for my ships. That's why the "AI" as a prefix.
    ... but are they ACTUALLY AI?

    "We fear that which we cannot see... we respect that which we cannot see... thus the blade will be wielded."

    Urahara_Bleach_Signature_by_Harty73.png
  • StarkkzStarkkz Registered Posts: 17
    They're just spartan gunners, they automatically target. If you consider it's an AI, then yes, it's an AI.
  • Lambda217Lambda217 Registered, Moderator Posts: 534
    ahem i believe they would be considered a virtual intelligence as they are non-sentient and sapient black-box quantum AIs are forbidden in citadel space


    "I want you to show this world what it means to fear the sky."
  • DerpyDerpy Registered Posts: 33
    Starkkz wrote:
    Actually I made an AI base E2 from which I make all my different kind of "AI helpers" for my ships. That's why the "AI" as a prefix.
    Wouldnt That need Global Values?
    "A hero is someone who has given his or her life to something bigger than oneself."
  • LtBrandonLtBrandon Registered, Administrator Posts: 507
    Derpy wrote:
    Starkkz wrote:
    Actually I made an AI base E2 from which I make all my different kind of "AI helpers" for my ships. That's why the "AI" as a prefix.
    Wouldnt That need Global Values?
    Please check the dates before posting in a dead thread. To answer you anyways, you don't need to use global values to do what he was suggesting. You could simply use normal wire outputs or even data signals.
    This is a block of text that can be added to posts you make. There is a 255 character limit.

    Lλmbdλ: donations for coding the space future of diaspora :>

    Get your extra long EVE trial here!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file