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

"CreditCard" need help

Started by lixowurm, 01 September 2012 - 04:50 PM
lixowurm #1
Posted 01 September 2012 - 06:50 PM
hello guys somebody has an idea how i can make a counter where you put in the creditcard (FloppyDisk) in and it shows you how much money is on it? and you can enter a command and add money from counter to card or add money from card to counter? thx for helping :-) sry if my english is wrong :)/>/> im from germany
Tiin57 #2
Posted 01 September 2012 - 07:25 PM
Should this be in Ask A Pro? Oh, well.
Yes and no.
Yes, it's possible, but no, you can't do it. Why? Because I'm doing it first. :)/>/>
cant_delete_account #3
Posted 01 September 2012 - 07:45 PM
but no, you can't do it.
Anyone can do it. Especially if they make it faster than you.
Tiin57 #4
Posted 01 September 2012 - 08:52 PM
Sorry, didn't quite realize that that would be taken seriously. My above post was a joke.
CapturetheBomb #5
Posted 01 September 2012 - 09:51 PM
I would suggest having a secure server to store the credit information rather than my initial idea of hosting the amount directly on the card. The accounts should also have a PIN to prevent theft and fraud, as anyone who has the most basic knowledge of LUA would be able to do (changing the card registered name/number to match other accounts).

I could help more, but I am afraid I know very little about programming in this language. If I can be directed to a list of commands, I can help set it up.
Leonardoas111 #6
Posted 02 September 2012 - 03:49 PM
Already did It :D/>/>

But then my friend destroyed the server…
TheOutcast5 #7
Posted 03 September 2012 - 11:01 PM
then this guy is unucky ^^^^^^
xD
Khento #8
Posted 15 September 2012 - 11:05 PM
This is Team Econ's project :)/>/>
Tiin57 #9
Posted 16 September 2012 - 12:47 PM
Indeed.
KillaVanilla #10
Posted 17 September 2012 - 12:56 AM

local function getMoney()
local creditCard = fs.open("disk/creditCard", "r")
local money = creditCard.readAll()
creditCard.close()
return money
end
local function addMoney(toAdd)
local creditCard = fs.open("disk/creditCard", "w")
local newMoney = getMoney() + toAdd
if newMoney < 0 then
  creditCard.close()
  return false
else
  creditCard.write(newMoney)
  creditCard.close()
  return true
end
end

Copy and paste this into any program you want to use a credit card inside of. Congrats, you now have the base of a working credit card system. Do note that this offers no protection whatsoever from people stealing your (fake) money.

getMoney returns the amount of money on the first credit card inserted into the drive.
addMoney returns true/false depending on if the transfer went through.

For example, if I wanted to make a shop:


if getMoney() < 50 then
print("You don't have enough money!")
else
addMoney(-50) --negative values take money away
redstone.setOutput("right", true) -- this can be changed
os.sleep(1)
redstone.setOutput("right", false)
end
disk.eject(side) -- change side to the side that your drive is on
-- this gives them their credit card back.
Khento #11
Posted 17 September 2012 - 02:50 AM

local function getMoney()
local creditCard = fs.open("disk/creditCard", "r")
local money = creditCard.readAll()
creditCard.close()
return money
end
local function addMoney(toAdd)
local creditCard = fs.open("disk/creditCard", "w")
local newMoney = getMoney() + toAdd
if newMoney < 0 then
  creditCard.close()
  return false
else
  creditCard.write(newMoney)
  creditCard.close()
  return true
end
end

Copy and paste this into any program you want to use a credit card inside of. Congrats, you now have the base of a working credit card system. Do note that this offers no protection whatsoever from people stealing your (fake) money.

getMoney returns the amount of money on the first credit card inserted into the drive.
addMoney returns true/false depending on if the transfer went through.

For example, if I wanted to make a shop:


if getMoney() < 50 then
print("You don't have enough money!")
else
addMoney(-50) --negative values take money away
redstone.setOutput("right", true) -- this can be changed
os.sleep(1)
redstone.setOutput("right", false)
end
disk.eject(side) -- change side to the side that your drive is on
-- this gives them their credit card back.
This is an excellent example of a bad economy system.
Anyone can do "edit disk/creditCard" and become a billionaire.
KillaVanilla #12
Posted 17 September 2012 - 09:48 PM
–code snip–
This is an excellent example of a bad economy system.
Anyone can do "edit disk/creditCard" and become a billionaire.

Which is why I said that it was the BASIS of an economy system. This was a quick job, to demonstrate how to do something. I see your point, though.

To OP:
Perhaps, instead of having the amount of credits be stored on the credit card, have each register send a rednet/http request to a server that authorizes the transaction and modifies the amount stored. The credit card could only have it's ID attached, and something identifying it as a credit card.
Mr. Fang #13
Posted 20 September 2012 - 04:06 AM
Sounds like an awesome idea, however I would like it to be amateurish so I could hack myself moneys…lol >8)
lixowurm #14
Posted 20 September 2012 - 06:15 PM
yes the code is a bad economy :)/>/>.
i made an internet which everybody can use, cause its on a server.
i thinked about it to make an "CreditCard-InGame-Server". My only problem is, that if i would set the worth of a creditcard
to zero, and somebody earns money and i reboot the server or ingame-server the money will be gone. so i ask you
my idea is SOMETHING LIKE this so pls no posts like "this would not work…"

CreditCard1234 = 0
id, name = rednet.receive()
if name == "CreditCard1234" then
id, password = rednet.receive()
if password == "1234" then
CreditCard1234 = CreditCard1234+10
print(CreditCard1234)
10
else
end
end

os.reboot() or something else… so i want to make online banking that works like this:
everybody have a card.
somebody puts in a card in the counter.
the program on the card is called "startup".
the program sends(CreditCard1234) to the server located somewhere else.
the server waits for password and (i dont write it down but you can select want you want to + or -) + money or - money.
so this is my basic idea.
but i dont know how to do this:
the worth must be the same after rebooting ingame- or minecraftserver.

thx for replies :D/>/>
bb lixowurm
IceCream #15
Posted 20 September 2012 - 10:34 PM
lixowurm. could i see the internet? :)/>/>


tell me the ip.


tekkit or 1.4.1 on minecraft?
lixowurm #16
Posted 21 September 2012 - 01:48 PM
yes IceCream, join hamachi network : 082-242-487
i have CC1.41 no tekkit
bb :)/>/>
lixowurm #17
Posted 21 September 2012 - 01:55 PM
I would suggest having a secure server to store the credit information rather than my initial idea of hosting the amount directly on the card. The accounts should also have a PIN to prevent theft and fraud, as anyone who has the most basic knowledge of LUA would be able to do (changing the card registered name/number to match other accounts).

I could help more, but I am afraid I know very little about programming in this language. If I can be directed to a list of commands, I can help set it up.


yes thats how i want to make it. there is a wiki http://computercraft...aft_Wiki_-_Home here are informations about API
commands… it helped me a lot
SNWLeader #18
Posted 12 February 2013 - 01:34 AM
I think for the post about how you were to do it, you should instead of it being variable to save the account info set it up to open a desperate file and to read it to a variable…kinda like this

Handle = fs.open(username, "r")
Bal = to number(handle.read all())

That
Kingdaro #19
Posted 12 February 2013 - 02:11 AM
Topic's a little old, bro.
Cranium #20
Posted 12 February 2013 - 02:44 AM
Indeed. The amount of black magic here is a little dangerous. Locked to prevent further necromancy.