Home Help and Tutorials
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!

wired keybored

spectorspector Registered Posts: 11
edited August 2011 in Help and Tutorials #1
hello was wondering if anyone could give a tut on how to use a wired key bored to control a ship as i have the ASCII but i don't know how to do E2 or where to start now.Any help would be appreciated

Comments

  • KanzukeKanzuke Registered, Moderator Posts: 181
    Here, this'll get you started:
    @name Keyboard
    @inputs  Keyboard:wirelink Memory      #Memory is added here as another input 
                                             #so that the E2 runs everytime the keyboard is used
    @persist  Pushed                                #Persisted so the Delta can be used to see
                                             #if a the keyboard is outputting a new ASCII Number
    @trigger  Memory                               #So that the E2 runs when Memory Changes, 
                                             #and only when Memory Changes.
                                                           #You can remove that part if you want
    
    
    Active = Keyboard["InUse",number]        #Find out if the keyboard is in use
    Pushed = sign(Memory)                        #Find out if a key is being held
    Key = toChar(Memory)                         #Translate the ASCII Number to a String for the key
    
    #I use the keyboard to switch targets and enable/disable certain weapons
    #The following is and example of the code used to determine 
    #if it should switch target class/enable a weapon
    #It will not work with just the code above, as it uses a lot of persisted variables
    #For refrences:
    # Index1 = Targeting Type, Clamped between 5 Modes, for example, Cores, Nodes, Vehicles, Players, etc
    # Index2 = Target Number, the Index used to retrieve the target from the found array
    # Beam/Pulse/Proton/Torp Index = The Index used to toggle the weapons on and off. 
    #All of the Indexes (Indexi?) are persisted
    
    
    if(Active){
        
        
        if(Key == "/" & $Pushed) {
            Index1++
            Index2 = 1
            }
        if(Index1 >= 5) {Index1 = 1}
        
        if(Key == "," & $Pushed) {Index2--}
        if(Key == "." & $Pushed) {Index2++}
        
        if(Key == "1" & $Pushed) {BeamIndex++}
        if(Key == "2" & $Pushed) {PulseIndex++}
        if(Key == "3" & $Pushed) {ProtonIndex++}
        if(Key == "4" & $Pushed) {TorpIndex++}
        if(Key == "5" & $Pushed) {MjolIndex++}
        if(Key == "6" & $Pushed) {MatterIndex++}
        if(Key == "7" & $Pushed) {AsgardFire = 1} else{AsgardFire = 0}
        
        if(BeamIndex > 1) {BeamIndex = 0}
        if(BeamIndex==1) {BeamArm = 1} else {BeamArm = 0}
        
        if(PulseIndex > 1) {PulseIndex = 0}
        if(PulseIndex==1) {PulseArm = 1} else {PulseArm = 0}
        
        if(ProtonIndex > 1) {ProtonIndex = 0}
        if(ProtonIndex==1) {ProtonArm = 1} else {ProtonArm = 0}
        
        if(TorpIndex > 1) {TorpIndex = 0}
        if(TorpIndex==1) {TorpArm = 1} else {TorpArm = 0}
        
        if(MjolIndex > 1) {MjolIndex = 0}
        if(MjolIndex==1) {MjolArm = 1} else {MjolArm = 0}    
        
        if(MatterIndex > 1) {MatterIndex = 0}
        if(MatterIndex==1) {MatterArm = 1} else {MatterArm = 0}  
    
        if(Mouse1 & PulseArm) {PulseFire = 1} else {PulseFire= 0}
        if(Mouse2 & ProtonArm) {ProtonFire = 1} else {ProtonFire= 0}
        if(Mouse2 & TorpArm) {TorpFire = 1} else {TorpFire= 0}
        if(Mouse2 & MjolArm) {MjolFire = 1} else {MjolFire= 0}
        if(Mouse2 & MatterArm) {MatterFire = 1} else {MatterFire= 0}
    
    
    #A chunk of code later...
    
    TargetArray = findToArray()
    Count = TargetArray:count()
    
    if(Index2 > Count) {Index2 = 1}
    if(Index2 < 1) {Index2 = Count}
    Selected = clamp(Index2,1,Count)
    
    Target = TargetArray[Selected,entity]
    
    
    }
    

    Damn Code function wrapping my text....


    Anyway, hope that helps, but Pro Tip, if you want to use a letter as a key, remember that in ASCII, "A" is the result of Shift+A, and "a" is just from pressing A. So in place of "/" or "1" above, you could use a letter, but make sure its lowercase.

    Lambda217: oh oh i am kanzuke and i love my little pony and now i'll make all the brandonphysics myself cause i know fuckin everything because now i'll make a big pony fighter drone squad and a big fuckin portal ship and i am a fuckin idiot
  • spectorspector Registered Posts: 11
    thanks
  • spectorspector Registered Posts: 11
    i got another question how do you wire the weapons to be auto locking? thanks again for any help
  • SteeveeoSteeveeo Registered, Administrator Posts: 849
    spector wrote:
    i got another question how do you wire the weapons to be auto locking? thanks again for any help
    Most of the weapons have an Entity input, which will fire toward that specific enemy you give it.

    Try something along these lines (though my E2 is rusty, so this might be a little mistyped):
    @name Target Finder
    @inputs 
    @outputs Target:entity
    
    interval(250)
    
    if(target == noentity())
    {
         findByClass("CHANGE_THIS_TO_TARGET_ENTITY_TYPE")
         findSortByDistance(entity():pos())
         if(find())
         {
              Target = find()
         }
    }
    

Leave a Comment

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