Jump to content




Could Use A Hand With Some Code


4 replies to this topic

#1 elfin8er

  • Members
  • 133 posts

Posted 18 April 2013 - 03:12 AM

So, I'm trying to make a rednet text based adventure game. I have a couple of questions about my code that I was wondering it you guys could help out with? Currently, the login just uses the minecraft servers. I wanted to get right to the point without having to mess around with encryption.

Client
Spoiler

Server
Spoiler

I realize the server would probably be pretty easy to hack, and most of my code can be optimized (I didn't understand rednet fully when I started xD). What I do need help with however is getting random HP rolls (Info in client line: 151). I know of ways I could do it, but just wondering the easiest.

Also, what would you guys suggest for doing inventory? I was sorta thinking that each players inventory could be saved in a table, and then written to a file on the server. In the table, would be the item ID, and the amount of that item. Then I guess there would be a table for each item? Each table would contain info like the items ID, name, HP/mp/atk gain, worth, etc. Not exactly sure how the server would know what information to send to the player at which point though. I could also just save all of the info to a file like I did with the player, and then turn them info variables. That may be easier considering I already know how to do it.

As for the actual map bit, I wanted to sorta do the same thing as the inventory. Each part of the map would have it's own table. (Should I worry about saving them to a file?) The table's would include the location name, the location ID, X and Z coords, as well as places the player could travel, etc. Any thoughts on this? Again, should I just do what I did with the players, and save them to a file instead?

One last thing. For the help commands, I want to have arguments for it. For an example, the player could type "/help inventory" and it would give the help screen for the inventory. Would you suggest doing /help inventory as a separate command then /help, or is there a way to carry arguments over?

I hope I'm not asking too much outa you guys. I just want to be sure I have everything right before moving on. Oh, and btw, I do want to add color someday ;)

#2 Hawk777

  • Members
  • 162 posts

Posted 18 April 2013 - 03:37 PM

For randomization, I suggest the math.random function. It returns a value from 0 to 1, so multiply and add to give it whatever range you want.

For inventory, a table is the right way to store it. Same for the rooms. Pretty much anything that isn’t obviously something else in Lua is a table.

As for saving to a file, I would probably use textutils.serialize on the tables.

#3 elfin8er

  • Members
  • 133 posts

Posted 18 April 2013 - 03:57 PM

View PostHawk777, on 18 April 2013 - 03:37 PM, said:

For randomization, I suggest the math.random function. It returns a value from 0 to 1, so multiply and add to give it whatever range you want.
Yeah, but what if I want it to be a multiple of ten, that is between two numbers?

#4 Hawk777

  • Members
  • 162 posts

Posted 18 April 2013 - 05:47 PM

If you want a number between 30 and 70 that is a multiple of ten, then call math.random(3, 7). This gives you a number between 3 and 7 inclusive. I forgot that it did this in my previous post (even had that been the case, there is a way to solve it, but this way is easier). Multiply it by ten.

#5 elfin8er

  • Members
  • 133 posts

Posted 18 April 2013 - 07:42 PM

View PostHawk777, on 18 April 2013 - 05:47 PM, said:

If you want a number between 30 and 70 that is a multiple of ten, then call math.random(3, 7). This gives you a number between 3 and 7 inclusive. I forgot that it did this in my previous post (even had that been the case, there is a way to solve it, but this way is easier). Multiply it by ten.
Oh yeah. I'm an idiot! Thanks for your help!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users