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

(Openperipherals For Mc 1.6.2) Robot / Mech Target Program

Started by darkrising, 30 September 2013 - 12:29 AM
darkrising #1
Posted 30 September 2013 - 02:29 AM
Hi all, this is just a simple program I wrote which allows the newly added robots from OpenPeripherals to shoot at a specific player.

I also added a yaw fix so the robot hits the player.

I'm working on a predictive movement program too but thought you might be interesting in what I have so far. :)/>/>/>

Code:
Spoiler

function run()
target = m.getPlayerData(id,player)
tarx = target.position.x
tary = target.position.y
tarz = target.position.z
ourx,oury,ourz = m.getLocation(id)
fix = ourx + tarx
fiy = oury + tary
fiz = ourz + tarz
m.aimAt(id,fix,fiy,fiz)
fp = cp - 5
m.fireLight(id)
print("Target X  "..tarx)
print("Target Y  "..tary)
print("Target Z  "..tarz)
print("Our X     "..ourx)
print("Our Y     "..oury)
print("Our Z     "..ourz)
print("Fixed X   "..fix)
print("Fixed Y   "..fiy)
print("Fixed Z   "..fiz)
print("Yaw     "..cp)
end
arg = {...}
if #arg == 0 then
  print("Usage: <amount> <time> <player> <robot id> <side>")
  return
end
player = arg[3]
id = tonumber(arg[4])
m = peripheral.wrap(arg[5])
for i = 1, arg[1] do
run()
sleep(tonumber(arg[2]))
end

If you don't know how to use OpenPeripheral Mechs, just place down a robot contoller next to a computer, right click to open it and place your robot inside, this will give it an ID.

You then wrap the peripheral and use the robot ID in each function you want to execute.

Screenshot:


Pretty cool huh? :P/>/>/>


Note: If you want an API list for the mechs I made one on my wiki!
Edited on 02 January 2014 - 03:27 PM
TechMasterGeneral #2
Posted 11 November 2013 - 10:18 PM
Do you have a pastebin code?
kelevra.1337 #3
Posted 02 January 2014 - 04:11 PM
Hey darkrising,

I also made some mech Utils lately, including a basic prefire system, getting and sorting a list of mobs nearby and such.
If youre interested in using/improving it i could post the pastebin here
darkrising #4
Posted 02 January 2014 - 04:14 PM
Hey darkrising,

I also made some mech Utils lately, including a basic prefire system, getting and sorting a list of mobs nearby and such.
If youre interested in using/improving it i could post the pastebin here

Sounds interesting, ye sure drop me a pastebin link :)/>
kelevra.1337 #5
Posted 02 January 2014 - 04:32 PM
http://pastebin.com/3CYg39b1

its pretty messy but it should work…..

getMobsByType(id,type) adds "id" to the content of the table so you can easily get mob IDs by doing


local mobs = getMobsByType(0,"Chicken")
local id = mobs[1]["id"]

The prefire (fixedIterations(id, mobID,projectileVel)) isnt really reliable but works technically:

http://www.youtube.com/watch?v=RmWBTpcrG3s