xnowandtheworldx Posted May 9, 2008 Share Posted May 9, 2008 Basically I need help for looping arrays(?) for a game i'm making..actually i've had one for a quite a while but want to amp up the raiding and stuff. Items are done, etc. etc. (11k items to be exact ) but i'm just stuck on how to get this effect...i've tried looping the arrays using there keys and if the $_ARRAY[$KEY] for example(a user) hp is equal to or below zero i unset the array, and well i'm just stumped because i'm not sure how to really do this..anyways to better explain heres some screenshots of the effect i'm trying to get. Attack #1 Attack #2 Attack #3 So as you can tell basically what it does is it loops through however many people are in the raid, they attack, then the boss/mob attacks, and it calculates the damage given to the users and if their hp falls below 0 a skull is shown, and it loops through until either the boss/mob is dead, or all the users are dead..any help would be awesome, i'll try and post my earlier code up, it's on the other computer at the moment. If you need a more thorough explanation i will try my best to do so. Quote Link to comment Share on other sites More sharing options...
mraiur Posted May 9, 2008 Share Posted May 9, 2008 I did not understand you what you need to do . i understant that a raid ( party ) is attacking a boss : 1. they hit the boss 2. the boss strikes back hitting a random raid players ... so ... Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted May 9, 2008 Author Share Posted May 9, 2008 Alright, basically it goes like this.... There are 5 players in the party attacking the boss.. Player 1 attacks Player 2 attacks Player 3 attacks Player 4 Attacks Player 5 attacks Combine total damage... Minus that damage from the boss check to see if boss is dead...if not...continue on for the boss to attack back boss attacks.. minus the boss's attack from the hp of the players see if any of the players died...if so..display a skull check to see if they all died..if so the raid was lost everyone(players) died if not..repeat... Basically that's as down to the point as I can get unfortunately. Hope that clears a little more confusion? I just need to know how I would set something like this up...getting the players attack/hp is no problem but once I get that..how do I loop through and get those results...arggh..i'm pulling my hair out with this one. Quote Link to comment Share on other sites More sharing options...
mlin Posted May 9, 2008 Share Posted May 9, 2008 show us what your array looks like and we'll show you how to loop through it. most of the it's something like this: $players = array( 1 => array('name' => 'buddhasmak', 'hp' = 1200), 2 => array('name' => 'bobafrost', 'hp' = 1324), 3 => array('name' => 'tool', 'hp' = 0) ); //count players $cnt = count($players); //the loop for ($i = 0; $i < $cnt; $i++) { $player = $players[$i]; $hp = $player['hp']; if ($hp <= 0) show_skull(); $name = $player['name']; } Does that help? Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted May 9, 2008 Author Share Posted May 9, 2008 I'd be storing the users in a database and it will just be a list of the users separated by commas, and another row for their hp, stored relevant to the usernames position for example.. $usernames = "xnowandtheworldx,beer,phpfreaks,master,guardian"; $hp = "100,324,987,1039,1948"; $array_user = explode(",", $usernames); $array_hp = explode(",", $hp); //loop here EDIT: I'll try that out mlin! Thanks for the help i'll let you know if it works! Quote Link to comment Share on other sites More sharing options...
mraiur Posted May 9, 2008 Share Posted May 9, 2008 show us what your array looks like and we'll show you how to loop through it. most of the it's something like this: $players = array( 1 => array('name' => 'buddhasmak', 'hp' = 1200), 2 => array('name' => 'bobafrost', 'hp' = 1324), 3 => array('name' => 'tool', 'hp' = 0) ); //count players $cnt = count($players); //the loop for ($i = 0; $i < $cnt; $i++) { $player = $players[$i]; $hp = $player['hp']; if ($hp <= 0) show_skull(); $name = $player['name']; } Does that help? thats a good idia but its better to store the results somewhere in a Database or a file . for each round so that the game can be made more dinamic for every one ... not only for the server But mlin gave a god idia i mean each round you sa.dir.bg take away the lost HP from the specific user arrray. But make a some kind of a statistics for each round to make a "Top DMG " or "Top score" Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted May 9, 2008 Author Share Posted May 9, 2008 Alright, one more thing..with the code you supplied theres an error in it, and I can't seem to find it lol. Parse error: syntax error, unexpected '=', expecting ')' line 4 $players = array( 1 => array('name' => 'buddhasmak', 'hp' = 1200), 2 => array('name' => 'bobafrost', 'hp' = 1324), 3 => array('name' => 'tool', 'hp' = 0) ); //count players $cnt = count($players); //the loop for ($i = 0; $i < $cnt; $i++) { $player = $players[$i]; $hp = $player['hp']; if ($hp <= 0) echo "DEAD!"; $name = $player['name']; } Quote Link to comment Share on other sites More sharing options...
mlin Posted May 10, 2008 Share Posted May 10, 2008 my bad. the hp need > signs like the other values...ie. $players = array( 1 => array('name' => 'buddhasmak', 'hp' => 1200), 2 => array('name' => 'bobafrost', 'hp' => 1324), 3 => array('name' => 'tool', 'hp' => 0) ); see the difference right? Sorry again, that was my bad. Let us know how it goes. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 But use the database to fill that array. Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted May 11, 2008 Author Share Posted May 11, 2008 Alright gonna try it now! Thanks for all the help. Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted May 11, 2008 Author Share Posted May 11, 2008 Awsome! Works man. Just had to change it to a zero based counting with the array unless I wanted to add +1 to the end of the count(*) part. But it works just gotta figure out how to loop it until everyone attacks, then have the boss attack, then have the players attack again, until someone wins. Joy. Haha. Thanks again though! 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.