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

Program needed

Started by Dog_Plunderhawk, 03 October 2014 - 09:41 PM
Dog_Plunderhawk #1
Posted 03 October 2014 - 11:41 PM
I am a fluent programmer in another language, but I am only just starting to create programs in ComputerCraft. I need a program that enables Villagers to "communicate" with each other and me using Computers. The purpose of this is so that I can create my own, simple Internet, without having to have actual players using it. Human players are unpredictable, they grief, they get bored with the same task, and are hard to get unlike Villagers. Also, I don't have Internet at my house, so I only get to use it at places with wireless-internet, and I must use my laptop computer to get it (in real life, not in ComputerCraft). Below is what I have in mind, but change it to what is possible or easier as you want. I shall be very grateful if you decide to do this.
A "Computer Console" for villagers consists of a Pressure Plate and a Redstone Lamp. The plate and lamp are connected to a Computer on the left and right sides, with a Wired Modem on top of the Computer. The Wired Modem is connected to all other computers on the network. The Player's computer has nothing except a Wired Modem, also connected.
The program for villager computers does nothing until it receives input from the network connection or the pressure plates. If one of the pressure plates is pressed, the computer sends a message to a random computer ID (1-20). The message is a random phrase such as "Yes", "No", "Where are you", "Okay", etc. If input is detected from the modem (a message is received), the computer will send a signal to the Redstone Lamp. It will also display the message on the screen (for human users). The program for player computers is the same except that instead of getting a signal from the pressure plate and sending a random message, it sends the message that was typed by the player, and it does not send a signal to a Redstone Lamp (as it is not in a console like the villager computers).
Again, thank you if you decide to do this.
Cranium #2
Posted 03 October 2014 - 11:47 PM
Moved to General for program requests.
Dragon53535 #3
Posted 04 October 2014 - 12:16 AM
I'm assuming that this is all for a single player world. And i'm also assuming that you should know the computer's ID's (If you don't just type id in the computer when you set it up.As of right now i'm actually making your program, since it sounds easy :P/> However as a question for it, are you using a monitor to show the messages? or are you just going to right click the computer. Also when do you want the lamps to turn off, since you have requested for them to just turn on when they get a message. Do you just want it to happen 3 seconds later?
Dragon53535 #4
Posted 04 October 2014 - 01:07 AM
All right I believe I finished the program for you. The User program is Here. The villager program is Here.

To install the User program while in minecraft make sure that the HTTP API is on, and then type in the computer

pastebin get MjMC6fym internet
If you want it to always be one from when you turn on the computer, just type copy internet startup inside the computer.

To install the villager program while in minecraft, type this

pastebin get QQwfS6Cj intervillage
Now since there are things you might want to edit inside the code for the villager responses and other things, i would install it on one computer, edit the program and then copy the edited program onto a disk, and then just copy the program onto the other computers such as

pastebin get QQwfS6Cj intervillage
--#Install program on first computer
edit intervillage
--#Editing the program and adding responses and such
copy intervillage disk/intervillage
--#Copy the edited program to a disk under the name intervillage
--#To do that you will need a floppy disk, and a disk drive attached to the computer. As soon as you are done with it, you can always remove the drive.

--#Move to another computer
copy disk/intervillage intervillage
--# Now the edited program is on another computer (You still need a disk drive and the same exact floppy from before)
Dog_Plunderhawk #5
Posted 09 October 2014 - 12:40 AM
Because I only get Internet on Wednesdays and Fridays (when I go to places with wireless internet), I got so desperate that I actually taught myself how to make programs on ComputerCraft with nothing but 2 sample programs I downloaded from the Internet, trial and error, 4 days, memory of making programs in the language I usually use, having to rewrite the internet three times, and having to re-install MineCraft once due to corrupting it (this is why I have spare copy of the game). I am willing to bet that your program works 10 times better than mine (there is still a major bug that needs fixing), so I will download it too, but if you want to see mine, I have the programs I designed myself below:
NOTE: Since I usually make programs in a code that is, for the most part, similar to C++, it is somewhat confusing to use Lua, especially when I taught it to myself. If you see any errors, Lua features I didn't use, or similar, please let me know. For the most part, these programs seem to work, though.
There are three programs I designed specifically for a custom village I built, so it will have locations, etc. that are unique to that village. The three programs:
Villager Computers: This program runs on computers for Villagers. The computers have a pressure plate on the front, a wired modem on the right side, and a disk drive on the left. It has 20 "phrase frames" and many more total phrases.
Spoiler

rednet.open ("right")
con = false
while true do
sleep (1)
if redstone.getInput ("front") then
if con == true then
sleep (3)
sleep (math.random (6))
end
ran = math.random (20)
if ran == 10 then
print ("Listening")
os.pullEvent ("rednet_message")
end
ran = math.random (2)
if ran == 1 then
no = ""
elseif ran == 2 then
no = "not "
end
ran = math.random (7)
if ran == 1 then
pla = "Bank"
elseif ran == 2 then
pla = "Park"
elseif ran == 3 then
pla = "Apartment Towers"
elseif ran == 4 then
pla = "Restraunt"
elseif ran == 5 then
pla = "Library"
elseif ran == 6 then
pla = "Museum"
elseif ran == 7 then
pla = "Wilderness"
end
ran = math.random (20)
if ran == 1 then
say = ": Yes."
elseif ran == 2 then
say = ": No."
elseif ran == 3 then
say = ": Possibly."
elseif ran == 4 then
say = ": Meet me at the "..pla.."."
elseif ran == 5 then
say = ": Do you have diamonds?"
elseif ran == 6 then
say = ": Are you skilled at MineCraft?"
elseif ran == 7 then
say = ": The news is "..no.."interesting, you should "..no.."read it."
elseif ran == 8 then
say = ": I do "..no.."like MineCraft."
elseif ran == 9 then
say = ": You should "..no.."go to the "..pla.."."
elseif ran == 10 then
say = ": SPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAM"
elseif ran == 11 then
say = ": I am "..no.."very skilled at MineCraft."
elseif ran == 12 then
say = ": Have you been to the Nether? I have "..no.."been there."
elseif ran == 13 then
say = ": You should see what is happening at the "..pla.."!"
elseif ran == 14 then
say = ": Are you a monster?"
elseif ran == 15 then
say = ": Do you like MineCraft?"
elseif ran == 16 then
say = ": My Experience Level is "..math.random (50).."."
elseif ran == 17 then
say = ": I once battled "..math.random (14).." monsters at the same time."
elseif ran == 18 then
say = ": Do "..no.."talk to me."
elseif ran == 19 then
say = ": Probably."
elseif ran == 20 then
say = ": Probably not."
end
if con == false then
sel = math.random (18)
sel = sel + 23
con = true
elseif con == true then
ran = math.random (2)
if ran == 1 then
con = false
end
end
rednet.send (sel, say, filt)
print (sel.." Me"..say)
end
end
Player Computer: This simple program runs on the Player's computer, enabling said player to communicate with Villagers.

while true do
print ("Send or Listen? (SpaceBar to Listen)")
local ent = read ()
if ent == (" ") then
print ("Listening for 15 seconds...")
print (rednet.receive (filt, 15))
else
print ("Enter message to send")
local ent = read ()
sel = math.random (18)
sel = sel + 23
rednet.send (sel, ent, filt)
print ("Me: "..ent)
end
end
Server Computer: This program runs on a special computer in the network that does not receive messages, but it instead sends advertisments for certain commercial buildings within the village I created the program for. It also broadcasts randomized News, which are phrase frames that are loaded with randomized objects, places, etc.

--Server Networking Program 0.9
rednet.open ("right")
while true do
sleep (10)
while true do
ran = math.random (7)
if ran == 1 then
nmob = "Villager"
elseif ran == 2 then
nmob = "Zombie"
elseif ran == 3 then
nmob = "Skeleton"
elseif ran == 4 then
nmob = "Creeper"
elseif ran == 5 then
nmob = "Spider"
elseif ran == 6 then
nmob = "Slime"
elseif ran == 7 then
nmob = "Enderman"
end
if nbom == true then
mob = nmob
break
else
nbom = true
mob2 = nmob
end
end
ran = math.random (10)
if ran == 1 then
verb = "attacking"
elseif ran == 2 then
verb = "eating"
elseif ran == 3 then
verb = "stealing"
elseif ran == 4 then
verb = "burning"
elseif ran == 5 then
verb = "burying"
elseif ran == 6 then
verb = "selling"
elseif ran == 7 then
verb = "buying"
elseif ran == 8 then
verb = "wielding"
elseif ran == 9 then
verb = "crafting"
elseif ran == 10 then
verb = "cooking"
end
ran = math.random (18)
if ran == 1 then
obj = "tree"
elseif ran == 2 then
obj = "Computer"
elseif ran == 3 then
obj = "Dirt Block"
elseif ran == 4 then
obj = "Iron Block"
elseif ran == 5 then
obj = "sword"
elseif ran == 6 then
obj = "Cake"
elseif ran == 7 then
obj = "TNT Block"
elseif ran == 8 then
obj = "pickaxe"
elseif ran == 9 then
obj = "Ender Pearl"
elseif ran == 10 then
obj = "Obsidian Block"
elseif ran == 11 then
obj = "Chest"
elseif ran == 12 then
obj = "hoe"
elseif ran == 13 then
obj = "axe"
elseif ran == 14 then
obj = "spade"
elseif ran == 15 then
obj = "Fishing Rod"
elseif ran == 16 then
obj = "Gold Block"
elseif ran == 17 then
obj = "Diamond"
elseif ran == 18 then
obj = "Crafting Table"
end
ran = math.random (7)
if ran == 1 then
tim = "a few minutes ago"
elseif ran == 2 then
tim = "last night"
elseif ran == 3 then
tim = "yesterday"
elseif ran == 4 then
tim = "the day before yesterday"
elseif ran == 5 then
tim = "a week ago"
elseif ran == 6 then
tim = "two weeks ago"
elseif ran == 7 then
tim = "a month ago"
end
ran = math.random (7)
if ran == 1 then
pla = "Restraunt"
elseif ran == 2 then
pla = "Park"
elseif ran == 3 then
pla = "Wilderness"
elseif ran == 3 then
pla = "Library"
elseif ran == 4 then
pla = "Museum"
elseif ran == 5 then
pla = "Apartment Towers"
elseif ran == 6 then
pla = "Computer Shop"
elseif ran == 7 then
pla = "Bank"
end
ran = math.random (2)
if ran == 1 then
any = obj
elseif ran == 2 then
any = mob
end
sel = math.random (18)
sel = sel + 23
ran = math.random (17)
if ran == 1 then
say = "Ad: The Village Restraunt has beef, fish, and more! Eat there today!"
elseif ran == 2 then
say = "Ad: Eat at the Village Restraunt! It has many different foods for a low price."
elseif ran == 3 then
say = "Ad: Tired of hunting to get your food? Go to the Restraunt instead!"
elseif ran == 4 then
say = "Ad: The Museum now has the first watch! See it today!"
elseif ran == 5 then
say = "Ad: Sit down and relax at the Library. There are plenty of books and a public computer!"
elseif ran == 6 then
say = "Ad: The Computer Store now has GoldRunner by NitrogenFingers! Buy today!"
elseif ran == 7 then
say = "Ad: The Computer store has all your computing needs, from modems to printers!"
elseif ran == 8 then
say = "Ad: Apartment Towers has wireless computers in each room! Go to the Lobby to get an Apartment."
elseif ran == 9 then
say = "Ad: The rooms in Apartment Towers are a full 5x5 meters! Enjoy living in these rooms today!"
elseif ran == 10 then
say = "Ad: The Doctor's Office will heal you fast. Get a checkup today!"
elseif ran == 11 then
say = "News: A local "..mob2.." was seen "..verb.." a "..any.." "..tim.."."
broad = true
elseif ran == 12 then
say = "News: A local "..mob2.." went missing "..tim..". It's favourite food is "..any.."s."
broad = true
elseif ran == 13 then
say = "News: A "..obj.." was stolen "..tim..". It's owner says that the thief may have been a "..mob.."."
broad = true
elseif ran == 14 then
say = "News: A shortage of "..any.."s has been reported "..tim..". Experts say that "..mob2.."s may be affected the most."
broad = true
elseif ran == 15 then
say = "News: A lost "..obj.." was found "..tim.." near the "..pla..". We think it may have belonged to a "..mob.."."
broad = true
elseif ran == 16 then
say = "Ad: If you fall into lava, chances are you will lose your items. Protect what you have earned at the Bank!"
elseif ran == 17 then
say = "Ad: It could happen to you! Put your items in the Bank today!"
end
if broad == true then
rednet.broadcast (say, filt)
else
rednet.send (sel, say, filt)
end
print (say)
end
Edited by