everton Posted November 18, 2006 Share Posted November 18, 2006 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 lolas always thanks a mill for the help. Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted November 18, 2006 Share Posted November 18, 2006 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 Link to comment Share on other sites More sharing options...
taith Posted November 18, 2006 Share Posted November 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted November 18, 2006 Share Posted November 18, 2006 Thats the same code, put another way... Quote Link to comment Share on other sites More sharing options...
taith Posted November 18, 2006 Share Posted November 18, 2006 well... if you think about it... they got a 10/1500 chance of getting one of them... thats 1/150, so if you load 150 times, so if you load the page every few seconds... you could very easily find one in 10 minutes... Quote Link to comment Share on other sites More sharing options...
spelltwister Posted November 18, 2006 Share Posted November 18, 2006 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 wantif($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. Quote Link to comment Share on other sites More sharing options...
everton Posted November 18, 2006 Author Share Posted November 18, 2006 [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!! :) Quote Link to comment Share on other sites More sharing options...
spelltwister Posted November 18, 2006 Share Posted November 18, 2006 I just have a column int he database with timestamp and then for the upload, $timestamp = time();Then it's just a simple SQL query mysql_query("update `rare_items` set last_occurance = $timestamp"); or something like that Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.