Jump to content

Random () help please


everton

Recommended Posts

hi guys,

i am trying to make a few things appear random in my game, i thought the below code was good enough, but the random items are appearing far to quickly,

what i want is items to appear at very large intervials, im talking days before anyone see's one's for testing i made the code


[QUOTE]
$randevent=rand(0,1500);
$event="";
if($randevent==0){ $rare1=1; $event="Your villagers have uncovered the eye of evil stone..."; }
if($randevent==250){ $rare2=1; $event="Your villagers have uncovered the jewel of death stone..."; }
if($randevent==350){ $rare3=1; $event="Your villagers have uncovered the stone of fear..."; }
if($randevent==450){ $rare4=1; $event="Your villagers have uncovered the dragons eye stone..."; }
if($randevent==550){ $rare5=1; $event="Your villagers have uncovered the statue of eden..."; }
if($randevent==650){ $rare6=1; $event="Your villagers have uncovered the priest of lier stone..."; }
if($randevent==750){ $rare7=1; $event="Your villagers have uncovered the sphere of sin stone..."; }
if($randevent==850){ $rare8=1; $event="Your villagers have uncovered the knights of satan stone..."; }
if($randevent==950){ $rare9=1; $event="Your villagers have uncovered the weather witch stone..."; }
if($randevent==1500){ $rare10=1; $event="Your villagers have uncovered the gods of war stone..."; }[/QUOTE]



i figured at 1500 it would take a while to find them all, but i had them within 10 mins, can someone point out my mistake?? or give me a little advice on how to lengthen the returns, i really need to nail this its been 2 days lol

as always thanks a mill for the help.
Link to comment
Share on other sites

Maybe, store the last appearance timestamp in a database, and if its been say past 2 hours, then you can spawn another. ?

Eg, When the item appears, store the time() it appeared in a SQL db.
The next time you want an item to appear (using the random system you have), check if its been over 2 hours since the last 'spawn' if it has spawn the new item, if not, don't.
Link to comment
Share on other sites

now... this could work... however switch, is SOOO much faster for stuff like this :-)
[code]
$randevent=rand(0,1500);
$event="";
switch($randevent){
case "0":
  $rare1=1;
  $event="Your villagers have uncovered the eye of evil stone...";
break;
case "250":
  $rare2=1;
  $event="Your villagers have uncovered the jewel of death stone...";
break;
case "350":
  $rare3=1;
  $event="Your villagers have uncovered the stone of fear...";
break;
case "450":
  $rare4=1;
  $event="Your villagers have uncovered the dragons eye stone...";
break;
case "550":
  $rare5=1;
  $event="Your villagers have uncovered the statue of eden...";
break;
case "650":
  $rare6=1;
  $event="Your villagers have uncovered the priest of lier stone...";
break;
case "750":
  $rare7=1;
  $event="Your villagers have uncovered the sphere of sin stone...";
break;
case "850":
  $rare8=1;
  $event="Your villagers have uncovered the knights of satan stone...";
break;
case "950":
  $rare9=1;
  $event="Your villagers have uncovered the weather witch stone...";
break;
case "1500":
  $rare10=1;
  $event="Your villagers have uncovered the gods of war stone...";
break;
}
[/code]
Link to comment
Share on other sites

you can either increase the random number or do something like...

$chars = array('a','b','c','d',...'1','2'...'0'...'A','B'...)
$top = sizeof($chars);
$mystring = $chars[random(0,$top-1)]+$chars[random(0,$top-1)]+$chars[random(0,$top-1)]...... for as many characters as you want

if($mystring == "aA120"){
  //find first item
}
if($mystring == "114BZx"){
  //find second item
}
obviously each addition character in the string will decrese the likely hood a bit.
Link to comment
Share on other sites

[quote]Maybe, store the last appearance timestamp in a database, and if its been say past 2 hours, then you can spawn another. ?

Eg, When the item appears, store the time() it appeared in a SQL db.
The next time you want an item to appear (using the random system you have), check if its been over 2 hours since the last 'spawn' if it has spawn the new item, if not, don't.[/quote]


thanks for the help guys!!

could you point me to a tut on storing the time stamp so i may learn it and try to fit it in that sounds like a great idea!! :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.