Jump to content

Couple Questions


Usarjjaco

Recommended Posts

Hello Everyone!First of all thanks in advance for reading and giving your input on the situation!1) I'm designing a text based game, and I'm trying to accomplish something along these lines: When a person goes to "explore.php" they have a random chance of being redirected to "attack.php" ... like they are being attacked by something while they travel. I'm just trying to figure out how I would implement the random factor?2) The game I'm designing has both land based grids and water based grids on a large scale. Is there an optimum way to make it so that water tiles are not travel-able without proper equipment? Just looking for ideas here, I know a couple different directions I'm thinking of but would like the outside opinion. Thanks in advance!

Link to comment
Share on other sites

1) I'm designing a text based game, and I'm trying to accomplish something along these lines: When a person goes to "explore.php" they have a random chance of being redirected to "attack.php" ... like they are being attacked by something while they travel. I'm just trying to figure out how I would implement the random factor?
This will give a user a 75% chance of being attacked:$attack_chance = rand(1, 100);if($attack_chance > 75){ // if '$attack_chance' is greater than '75', player gets attacked... header('Location: attack.php');}
Link to comment
Share on other sites

This will give a user a 75% chance of being attacked:$attack_chance = rand(1, 100);if($attack_chance > 75){ // if '$attack_chance' is greater than '75', player gets attacked... header('Location: attack.php');}
Thanks for the help. But to clarify, the numbers you are showing seem to point to a 25% chance of attack? Since it only redirects if it's greater than 75 and if it's random from 1-100?Also, tried putting that into the "Explore.php" page... and logically I assumed it would run that everytime the page loads, but have loaded about 20 times and haven't been redirected to attack.php... any ideas?
Link to comment
Share on other sites

You are right about the chances, it should be

if($attack_chance <= 75) {}

I also suggest you use mt_rand() instead of rand(). The code is fine, though, but try using this one and see what number is displayed. It is possible there were no numbers above 75 picked up, and so the condition was never true.

$attack_chance = mt_rand(0, 100); # 0% is also possibleif($attack_chance <= 75) { # Raise the chances	header('Location: attack.php');	echo $attack_chance . "\n"; # Display the chances}

As for your other question, I'm not sure I get it, but I think you should be able to store all the equipment in the game in an array. For every player, mark the piece of equipment with either 1 (true) or 0 (false). If all the equipment required for traveling on water is TRUE, let the player pass. Otherwise, display a message.

Link to comment
Share on other sites

Speaking as one who spent literally days in random fights while playing Final Fantasy 7, I think I prefer the 25% chance of being attacked to the 75% chance :)

Link to comment
Share on other sites

Speaking as one who spent literally days in random fights while playing Final Fantasy 7, I think I prefer the 25% chance of being attacked to the 75% chance :)
:)although it would have made leveling up a lot faster...
Link to comment
Share on other sites

Well there was always Lure materia if you wanted more fights.

Link to comment
Share on other sites

You are right about the chances, it should be
if($attack_chance <= 75) {}

I also suggest you use mt_rand() instead of rand(). The code is fine, though, but try using this one and see what number is displayed. It is possible there were no numbers above 75 picked up, and so the condition was never true.

$attack_chance = mt_rand(0, 100); # 0% is also possibleif($attack_chance <= 75) { # Raise the chances	header('Location: attack.php');	echo $attack_chance . "\n"; # Display the chances}

As for your other question, I'm not sure I get it, but I think you should be able to store all the equipment in the game in an array. For every player, mark the piece of equipment with either 1 (true) or 0 (false). If all the equipment required for traveling on water is TRUE, let the player pass. Otherwise, display a message.

Thank you for your suggestions, much appreciated! I'll go ahead and try it with the echo (*face plant*) should've thought of that. Also you are on the right track for what I'm asking. The problem is more of a "optimized" solution. The game is massive (Uses actual 4 digit GPS coordinates), so I have to implement all major bodies of water as being water hexes... what would be the quickest way? My big fear would be having to create a db entry for each grid... right now I have no DB for grids, it only updates the user's position and randomly generates the items they run into...I hope this explains it better and I look forward to your guys' input!Ok here is the error I'm getting, seems to happen no matter where in the scripting I place the code:Warning: Cannot modify header information - headers already sent by (output started at /public_html/zombies/explore.php:20) in /home5/theripti/public_html/zombies/explore.php on line 25Any ideas? Thanks!
Link to comment
Share on other sites

it means you are trying to use headers after headers have already been sent. headers (like redirects) have to be executed before any other code is outputted. HTML, whitespace, anything.http://us2.php.net/manual/en/function.header.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...