 |
|
 |
Main Menu |
|
|
 |
Forums |
|
|
 |
Programming Contest |
| |
 |
Documentation
|
| |
 |
Partner
Sites |
|
 |
Sponsors |
|
|
 |
|
|
|
Register •
FAQ
• Search • Login
|
|
Page 1 of 1
|
[ 3 posts ] |
|
| Author |
Message |
|
dumbwaiters
Junior Member
Joined: Sat Sep 02, 2006 2:48 pm Posts: 4
|
 RPG City Search question
Has anyone here ever written code for an RPG that invloves some sort of search?
Specifically what I am trying to do is write code that will give a player 250 "search moves" per day and allow them the chance of finding money, an object, or nothing. I would like to randomize the money found to $5, $10, $15, or $20, and the objects to 1, 2, or 3.
I've been searching for tutorials or examples but keep coming up short. Any guidance is appreciated.
|
| Sat Sep 02, 2006 2:59 pm |
|
 |
|
Sinzygy
Junior Member
Joined: Sun Sep 03, 2006 2:24 am Posts: 1
|
uhm, i guess i would do it this way:
[PHP]
function random_search($s_moves)
{
if($s_moves >= 1)
{
$rand = round(rand(1,7));
if($rand == 1)
{
//Found nothing
}
else if($rand == 2)
{
//Found $5
}
// go on like this, for every number a special event
//Now you gotta decrease the players search moves by one
//and now return your result
}
}
[/PHP]
If you want to make some events occur with different chances:
Just change [PHP]$rand = round(rand(1,7));[/PHP]
to [PHP]$rand = round(rand(1,100));[/PHP]
and then
[PHP]
if($rand <= 50)
{
//50% chance to find nothing
}
else if($rand > 50 && =<60)
{
//105 chance to find $5
}
[/PHP]
hope that helps.
- Sinzygy
|
| Sun Sep 03, 2006 2:38 am |
|
 |
|
dumbwaiters
Junior Member
Joined: Sat Sep 02, 2006 2:48 pm Posts: 4
|
That looks great, thank you very much!
|
| Sun Sep 03, 2006 6:38 am |
|
 |
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|
|