Jump to content

% Random & Table / Session (for a php game)


Norin

Recommended Posts

Greetings everybody, first of all, I am sorry for posting multiple questions in one topic, but I thought it'd be better to make one topic rather than having many topics.

 

I am actually working on a php-based game and I've encoutered some problems.

 

First of all, I've got some problem while trying to make a function that would allow me to get a random item as a drop from a monster. The problem is, each item has a % chance to be dropped. I made a function that allowed me to do this:

function randomPrc($itemSQL)
   {
      $drop = array();
      foreach($itemSQL as $item)
      {
         for($i=0;$i<($item['prc']*10);$i++)
         {
            array_push($drop, $item['item']);
         }
      }
      $randDrop = rand(0,count($drop));
      $currDrop = $drop[$randDrop];
      echo $currDrop;
   }

But as you can see, the 'No drop' is impossible with this function and it has to make an array of around 1000 values which is actually really big. So I was wondering if there was a way to do this in a way that'd be more effective.

 

 

Table & Session:

 

Another problem I have is more a "Which is the best way to go" problem.

Let's say for exemple that a player go fight a monster. I have the base information concerning that monster in a table. Should I create a table which would contain temporary informations like, how much HP/MP that monster have left or should I try to get my way through SESSION array containing those informations?

 

When the player dies, he can go to the hospital. So I was thinking to use tables with a date, then compare the date where he went to the hospital with now [saying he cant go to the hospital more than once by 10minutes] But it would require lot of information in my player table... Anyone know a more effective way to get this done?

 

Finally, my last question, which way would be the best. If for exemple my player has parts (Head, right/left arms...) where he can use some items. Should all my items be in one big table, or should I separate all of them?

Actually, most items have the same stats but the armors gives def and weapons gives attack.

 

Sorry if it was long,

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/50027-random-table-session-for-a-php-game/
Share on other sites

Archived

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

×
×
  • 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.