View unanswered posts | View active topics It is currently Sat Oct 25, 2014 5:20 pm



Reply to topic  [ 3 posts ] 
 RPG City Search question 
Author Message
Junior Member

Joined: Sat Sep 02, 2006 2:48 pm
Posts: 4
Post 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
Report this post
Profile
Junior Member

Joined: Sun Sep 03, 2006 2:24 am
Posts: 1
Post 
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
Report this post
Profile
Junior Member

Joined: Sat Sep 02, 2006 2:48 pm
Posts: 4
Post 
That looks great, thank you very much!


Sun Sep 03, 2006 6:38 am
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 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

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.