Spacebuild Forums
Example E2s - Printable Version

+- Spacebuild Forums (http://www.ascendedonline.com)
+-- Forum: Sharing Centre (http://www.ascendedonline.com/forumdisplay.php?fid=4)
+--- Forum: E2 Sharing (http://www.ascendedonline.com/forumdisplay.php?fid=5)
+--- Thread: Example E2s (/showthread.php?tid=3)



Example E2s - ThatGamingWolf - 04-20-2017

These codes are very basic starting E2s for those people that aren't good at E2. They would provide you with the basic needs of your ship such as weapon targeting, Warp cores, Life support and a few other things. These are mostly examples to help learn E2 and how to use them in spacebuild. I will make an "Advanced" thread for some more complex E2s when i'm finished making them


Wolfs Example Weapon Targeting Core:
Code:
@name Wolfs example weapon targeting
@outputs Target:entity Fire:number
@persist Ply:entity Stawp:number Fire:number
runOnChat(1)
interval(20) #This will run every 20 ms which saves lots of OPS without much loss of performance especially on code like this

######
#Vars#
######
if(first()){ #Only run when the code starts for the first time
   Fire = 0
   O = owner()
   Stawp = 0
}
FireDelay = 4000 #If your guns take 8 seconds to reload keep this value at 4000
Last = owner():lastSaid():lower():explode(" ") #If you really need to know about this just message me on steam
E = chatClk(owner())
#####
#End#
#####

###########
#Functions#
###########
function fire(){
   if(Fire == 1){ #Me too lazy to explain and with logic you can figure out
       Fire = 0
   }
   else{Fire = 1}
   timer("Fire Delay", FireDelay)
}

if(clk("Fire Delay") & Stawp != 1){
   fire()
}

#####
#End#
#####

###############
#Chat Commands#
###############

if(Last[1,string] == "/target" & E){ #Use /target <name> to target a player and do NOT use spaces. Btw E is to prevent spam
   hideChat(1)
   Ply = findPlayerByName(Last[2,string])
   if(Ply != O){
       Target = Ply
   }
   if(Ply == owner()){print("Dont target yourself you daft fuck")}
   if(!Ply:isValid()){print("Well fucking done, WELL FUCKING DONE YOU BROKE MY CODE!!!!! LIKE HOW EVEN!?!?!?! SERIOUSLY, oh....spelling mistake. gg")}
}

if(clk("Kill switch")){
   if(Stawp != 0){
       Stawp = 0
   }
   else{print("Warning! weapons failed to stop, Please use the /stawp command again")} #In theory should never happen but just in case
}

if(Last[1,string] == "/stawp" & E){
   hideChat(1)
   Stawp = 1
   timer("Kill switch", FireDelay + 1) #Idk if the +1 is needed but its better to not have guns then have then stuck active
}

if(Last[1,string] == "/fire" & E & Stawp != 1){
   timer("Fire Delay", 1)
}

#####
#Fin#
#####

Wolfs Example Warp Core:
Code:
@name Wolfs example warp core
@outputs Jump:number TargetPos:vector
runOnChat(1)
interval(1000)

Last = owner():lastSaid():lower():explode(" ")
E = chatClk(owner())
if(first()){I = 1}

PlanetList = array("Zarkol", "Freedonia", "Rhodon", "Aincrad", "Cydonia", "Rytak", "Pheles", "Trost", "Space") #List of all planets

if (Last[1,string]:find("/")){
   hideChat(1)

   if (Last[1,string] == "/zarkol" & E){
       TargetPos = vec(0,0,0) #Add a vector here
       if(TargetPos:isInWorld()){ #This is added as a "fail safe" in case some wally decided to feed it an invalid vector which would despawn their ship
           Jump = 1
           timer("jumpReset", 1000)
       }
       else{print("Im affraid that vector is outside of the world, Warping here would destroy the ship...")}
   }
}

if(clk("jumpReset")){
Jump = 0
}

function help(){
   I = 1
   while(I < PlanetList:count()){ #WARNING: Do not overload this command, if this while loop is fed too much OPS will max and spam chat
       print(PlanetList[I,string])
       I++
   }
}

if(Last[1,string] == "/help" & E){
   help()
}

Stargate Resource Transfer:
Code:
@name Wolfs StartGate Transfer
@inputs Gate:wirelink
@outputs
@persist Resource:number
interval(100) # transfer every 0.1 seconds
runOnChat(1)

Last = owner():lastSaid():lower():explode(" ")
E = chatClk(owner())

if(first()){
   hint("Starting transfer of power", 3)
   Resource = 0
}
#--------Power-------#
Gate:stargateTransferEnergy(80000)#Why not transfer power anyway since it doesnt interfere with resource transfer in any way
#WILL DRAIN POWER FAST IF NOT HOOKED UP TO POWERFUL SOURCE!

#--------O2--------#
if(Last[1,string] == "transfer" & Last[2,string] == "o2" & E){
   hideChat(1)
   Resource = 1
   hint("Tranfering O2", 3)
}

#--------H2O--------#
if(Last[1,string] == "transfer" & Last[2,string] == "h2o" & E){
   hideChat(1)
   Resource = 2
   hint("Tranfering H2O", 3)
}

#--------Tranfer area--------#
if(Resource == 1){Gate:stargateTransferResource("oxygen",5000)}
if(Resource == 2){Gate:stargateTransferResource("water",5000)}

#-------------------------Info-------------------------#
#[
Before making edits read info below

At same time we can transfer only ONE resource and energy.
By default you can transfer only once at 0.1 second (cycle)
And max - 80000 energy and 5000 of any resource
#]


Automated lifes support system coming soon
Code:
@name Wolfs example lifesupport
@inputs Cache:wirelink
@outputs O2:number Oxygen
@persist LifeSupport:number O2
runOnChat(1)
interval(100)

S = owner():lastSaid():lower():explode(" ")
E = chatClk(owner())
Oxygen = Cache["Oxygen",number]/Cache["Max Oxygen",number]*100 #Get the percentage
Oxygen = round(Oxygen, 1) #round the percentage

if(first()){O2 = 0}

#--------Chat Commands--------#
if(S:string(1) == "ls" & S:string(2) == "on" & E){
   LifeSupport = 1
}

if(S:string(1) == "ls" & S:string(2) == "off" & E){
   LifeSupport = 0
}


#--------LS--------#
if(LifeSupport == 1){
   if(Oxygen <= 25 & O2 == 0){
       O2 = 1
   }
   
   if(Oxygen > 99){
       O2 = 0
   }
}



RE: Example E2s - ThatGamingWolf - 05-31-2017

Warning: the target core doesn't work, i will fix it when i get the chance