This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Andrew2060's profile picture

ICBM Mod Help

Started by Andrew2060, 20 July 2016 - 06:20 AM
Andrew2060 #1
Posted 20 July 2016 - 08:20 AM
Hi.

I am trying to create a massive network of slave (silo computers) and a master (launch computer).
The problem is I'd like to know what missile type is in each silo, and list them on my master PC.
I would also like to display if the missile is armed or not on the screen (local custom variable on slave).

–> [Silo] [ID] [MissileType] [Armed/Unarmed]

I can't find a way to implement this and spent a long time trying to transport it via table, but it didnt work out.


Master: (The functions that control the finding, listing and firing of silo data.)

Spoiler
  • local waitDelay = 2
  • rednet.open("top")
  • local silos = {}
  • local function findSilos()
  • rednet.broadcast("ping silo")
  • local timerID = os.startTimer(waitDelay)
  • while true do
  • event, id, msg, distance = os.pullEvent()
  • if event == "rednet_message" and msg == "pong" then
  • table.insert(silos, id)
  • timerID = os.startTimer(waitDelay)
  • elseif event == "timer" and id == timerID then
  • return
  • end
  • end
  • end
  • local curSilo = 1
  • local function launch(count, x, y, z)
  • local msg = {x = x, y = y, z = z}
  • print("launching Missiles At " .. x .. ", " .. y .. ", " .. z)
  • for i = 1, count do
  • rednet.send(silos[curSilo], msg)
  • curSilo = (curSilo == #silos) and 1 or (curSilo + 1)
  • sleep(5)
  • end
  • end
  • local function printSilos()
  • term.clear()
  • term.setCursorPos(1,1)
  • print(" [Detected silos] ")
  • for k, v in ipairs(silos) do
  • print(" silo #" .. k .. " id = "..v)
  • end
  • end

Slave: (Entire Code)
http://pastebin.com/exm7HRhr'


Would appreciate some help :)/>
Edited on 20 July 2016 - 06:21 AM
Lupus590 #2
Posted 20 July 2016 - 12:05 PM
First:
 [./code] tags

What have you managed to get working so far?

You could add a function on the master which takes a silo id and then messages the slave to query the current missile type. You may want to put the responses in a table.

You could do the same for arm status.
Edited on 20 July 2016 - 10:07 AM
Andrew2060 #3
Posted 21 July 2016 - 01:25 PM
I dont know, all my implementations wont work, there are lots of bad possibilities.

This is what I was going to do:

(Client Side):

local armed = true
local masterId
local warhead = peripheral.call("icbm", "getMissile")
local status = {warhead, armed}

if event = rednet.message and msg = "giveStatus" then
rednet.send(masterID, status)


but i dont know how to get it done server side?
Could you share the coded version of your idea?

I mean my idea was to simply make a table like : local silos = {silo#, id, warhead, armed}
and transfer it from the client to the server, via rednet message of tables.

Can i please just see how someone else has done it, ive spent hours trying to figure it out.
Lupus590 #4
Posted 21 July 2016 - 05:44 PM
As I don't have the mod there will be some psudo-code mostly where the program interacts with the peripheral.
The code I'm giving uses a version of the rednet API which was added with CC 1.6 If you have an older version of ComputerCraft installed then my example will not run. It should also be noted that I haven't tested this code and that I haven't used the protocol part of rednet very much, even when running the correct version of CC it may not work.

Master/Server/Controller
--# server/master/controller

--# User config section
local hostName = "Andrew2060_Silo_System"
local protocolName = "Lupus590_Silo_Demo"




--# End of user config section



rednet.host(protocolName, hostName)

local silo = {}

local function printSiloInfo()
  if silo[1] then
	textutils.pagedTabulate({"ID", "Type", "Armed"}, unpack(silo))
  else print("No connected slaves") end
end

local function listenForSilos()
  while true do
	local message = {rednet.recive()}
	if message[3] == protocolName then
	  --# message is expected protocol, continue
	  silo[#silo+1] = message[2]
	end
  end
end

local function fire(ID)
  if silo[ID][3] then
	rednet.send(silo[ID][1],"fire", protocolName )
  else print("Silo not armed, can't fire while not armed") end
end

local function arm(ID)
  silo[ID][3] = "true"
  rednet.send(silo[ID][1],"arm", protocolName )
end

local function disarm(ID)
  silo[ID][3] = "false"
  rednet.send(silo[ID][1],"disarm", protocolName )
end


local function main()
  local command = read()
  --# string manipulation is something I have never done before, so I will leave this to better people
end

parallel.waitForAny(listenForSilos, main)
[namedspoiler='Slave/Silo][code]–# slave/silo

–# User config section
local hostName = "Andrew2060_Silo_System" –# must match master variable
local protocolName = "Lupus590_Silo_Demo" –# must match master variable




–# End of user config section





local silo = peripheral.find("ICBM_Silo") –# you may need to change this

if not silo then error("can't find silo") end

–# peripheral dummy functions (because I don't have the mod)

local function silo.getMissileType()
–# interigate the silo
end

local function silo.geteArmStatus()
–# interigate the silo
end

local function silo.setArmState(newState)
–# peripheral stuff
end

local function silo.fire()
–# peripheral stuff
end

–# end of peripheral dummy functions

local masterServer = rednet.lookup(protocolName, hostName)

if not masterServer then error("can't find master server") end

local function getSiloState()
return {os.getComputerID, silo.getMissileType(), tostring(silo.getMissileArmStatus())}
end

rednet.send(masterServer, getSiloState(), protocolName) –# send first message so that the master server knows about this silo



while true do
local message = {rednet.recive()}
if message[3] == protocolName then
–# message is expected protocol, continue
if message[1] == masterServer then
–# the message if from our master server, continue
if message[2] == "arm" then silo.setArmState(true)
elseif message[2] == "disarm" then silo.setArmState(false)
elseif message[2] == "fire" then silo.fire()
else –# bad message, ignore
end
end
end
end
Edited on 21 July 2016 - 03:47 PM
Andrew2060 #5
Posted 22 July 2016 - 03:09 PM
Well the only issues I had while implementing your code were:
1. Icbm Peripheral only provides these methods (getTarget) (setTarget) (fire) (getFrequency) (getMissile).
–have to use ie peripheral.call("back", "getTarget")
2. Armed Status is a custom toggle I put in, so that as a precaution I can disarm the computer controlling the silo (slave).
3. Implementing the armed status toggle in the client, so that it can change local armStatus to local armStatus = (newState).
Thanks for the help, it gave me an idea but im still working on it.
My basic general idea was to make it so that
After logging in to the masterPC, it would print like a log, for all that are in range:
print("Welcome "..username)
print("===============================")
[Silo#] [Pc ID] [Missile Type] [Arm Status]
[Silo#1] [Pc ID] [Nuclear] [Armed]
[Silo#2] [Pc ID] [Nuclear] [Armed]
[Silo#3] [Pc ID] [Nuclear] [Disarmed]
print("==========================")
print(" [Options] ")
1. Arm Silos.
2. Disarm Silos.
3. Arm Selected Silo.
4. Disarm Selected Silo.
5. Set Target For Selected Silo.
6. Set Target For All Silos.
7. Fire Selected Silo.
8. Fire All Silos.
*Basic code*
*The Entire Idea*
I just want to know how i can get it to do these critical functions:
1. Log the missiles in the format I want without being in a locked loop that i cannot type an option in.
–For example, in my code it detects as many slaves in range, and then lets me fire them if i want to.
2. Be able to arm the missile or disarm it.
3. Be able to set the missiles targets.
4. Fire the missile or missiles.
I basically just need to print the data, but the additonal part of setting arm status and setting coordinates without firing is helpful.
(I play on a server and I dont want to be blown up, I like to code things that help people survive)
(At the same time i dont trust people in my faction either).
Pack: http://www.technicpack.net/modpack/nuclear-revolution.689897/help
ServerIP : Already in the multiplayer tab once you load it up.
Would be appreciated if someone took the time to come down and show me a few pointers with rednet slave/masters.
Edited on 22 July 2016 - 01:40 PM
Andrew2060 #6
Posted 22 July 2016 - 03:40 PM
Also my skype = burnin.aura

can we chat there?

I really would like to learn the rednet api and table functions more.
Lupus590 #7
Posted 22 July 2016 - 04:05 PM
I really would like to learn the rednet api and table functions more.

http://computercraft.info/wiki/Category:APIs
Andrew2060 #8
Posted 22 July 2016 - 07:58 PM
I was hoping for interactive lessons but oh well,

Could you try and work with my system?
Andrew2060 #9
Posted 22 July 2016 - 09:19 PM
Current Code:
Master: http://pastebin.com/HgurSf2F
Slave: http://pastebin.com/exm7HRhr


Tl:dr: To all:

My Goal: (Create a interactive list of functions/logging):
[Silo#] [SiloId] [MissileType] [CurrentCoordinates] [Armed/Disarmed]

ICBM Provides:
getMissile()
getTarget()
setTarget()
launch()

Arm status would be custom.

Anyone else know how to accomplish this in one large table?
Just the logging of that data, and a function to disarm/arm.
Edited on 22 July 2016 - 07:28 PM
Andrew2060 #10
Posted 23 July 2016 - 02:03 PM
Here is what I got so far now.
http://pastebin.com/5d2FV0CF
http://pastebin.com/bVaBVfME
Edited on 23 July 2016 - 12:30 PM
PossieTV #11
Posted 23 July 2016 - 07:39 PM
What version of ICBM are you using? Cause I didn't know that the 1.7.10 ICBM even had support for CC
Andrew2060 #12
Posted 24 July 2016 - 07:03 AM
It's not ICBM.

It's DefenseTech which is the 1.7.10 version of the 1.6.4 ICBM.
The actual ICBM mod is still in alpha phase because the mod author is a dick about it.
(Adding missiles that drop cake, yet hasn't even put in textures on the missiles at all)

DefenseTech is by Mekanism creator Aiden.
PossieTV #13
Posted 24 July 2016 - 09:50 PM
Ohhhh, that's good to know cause the 1.6.4 ICBM is so much better than the 1.7.10.
Lupus590 #14
Posted 25 July 2016 - 08:57 PM

looks ok so far, anything in particular you need help with?
Andrew2060 #15
Posted 25 July 2016 - 11:27 PM

looks ok so far, anything in particular you need help with?

Yeah,

I can't get it to print what I want.. Thats the bare minimum I would Like to see.
I mean if i can't toggle individual parts of a silo, i would appreciate it if someone could guide me to an easier path.
Such as printing the data of those individual parts in a single string.

[Sio#] [Id] [Missile] [Armed/Unarmed] [Current Target]

client:
local missile = peripheral.call("back", "getMissile")
local target = peripheral.call("back", "getTarget")
local armed = status
local status = – true/false – toggleable
local id = os.getComputerId()