SieRobin Posted May 28, 2006 Share Posted May 28, 2006 As many may actually know, I have a browser based MMORPG, but I've run across a problem once again lol.I have weapons/items you can buy and equipped, but some you need set requirments to even equipped or buy. Like here is the problem, there's an item you can only be a Dark Elf to equipped but how do you make it so it can't be utilized by any other race?[code]if ($userstats3[race]==?) {code here }[/code]I'm just kind of confused on what to do. Quote Link to comment Share on other sites More sharing options...
Ferenc Posted May 28, 2006 Share Posted May 28, 2006 You would have to add a list of races that can use the item to the item in question.Then maybe place them in an array, then compare the user race to the array...[code]<?php//$user = "Dark elf";$user = "Human";$item_races = array('Dark elf', 'Dwarf'); // races that can use the item if( in_array($user, $item_races)){ echo "A $user can use this item.";}else{ echo "A $user cannot use this item.";}?>[/code] Quote Link to comment Share on other sites More sharing options...
SieRobin Posted July 30, 2006 Author Share Posted July 30, 2006 Ahha, got it thank you for the help :] Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 [quote author=Ferenc link=topic=94464.msg377887#msg377887 date=1148838319]You would have to add a list of races that can use the item to the item in question.Then maybe place them in an array, then compare the user race to the array...[code]<?php//$user = "Dark elf";$user = "Human";$item_races = array('Dark elf', 'Dwarf'); // races that can use the item if( in_array($user, $item_races)){ echo "A $user can use this item.";}else{ echo "A $user cannot use this item.";}?>[/code][/quote]For this though, say the races are stored in the database for the item and which race can utilize it, how do I make it split into an array? Quote Link to comment Share on other sites More sharing options...
trq Posted August 9, 2006 Share Posted August 9, 2006 depends how they are stored. If there just comma delimetered string you could simply use [url=http://php.net/explode]explode[/url], otherwise... you might need to generate an array from your database queries results. eg;[code=php:0]while ($row = mysql_fetch_assoc($result)) { $item_races[] = $row['race'];}[/code] Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 [quote author=thorpe link=topic=94464.msg412209#msg412209 date=1155089866]depends how they are stored. If there just comma delimetered string you could simply use [url=http://php.net/explode]explode[/url], otherwise... you might need to generate an array from your database queries results. eg;[code=php:0]while ($row = mysql_fetch_assoc($result)) { $item_races[] = $row['race'];}[/code][/quote]I'm seperating them in the database by commas in the same field that is. So I can just use explode, the same way as an array? Quote Link to comment Share on other sites More sharing options...
corbin Posted August 9, 2006 Share Posted August 9, 2006 $result = mysql_fetch_assoc($q);$race_array = explode(",", $result);Should do it... Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 Doesn't work. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 9, 2006 Share Posted August 9, 2006 try$result = mysql_fetch_assoc($q);$race_array = explode(" ", $result); Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 Well I get an error from the assoc.Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/sierobin/public_html/inventory.php on line 76 Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 9, 2006 Share Posted August 9, 2006 post your code then the select query ok. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 [code]$equip=$_GET['equip']; $unequip=$_GET['unequip']; $user=$_GET['user']; $type=$_GET['type']; $race=$_GET['race']; $dmg=$_GET['dmg']; $arm=$_GET['arm']; $agil=$_GET['agil']; $dex=$_GET['dex']; $itemraces=mysql_fetch_assoc($uinventory3['race']); $racearray=explode(",", $itemraces); if (isset($equip)) { if (in_array($userstats3['race'], $racearray)||$race=='All') {[/code]I'm not sure if I'm doing it correctly since I've never used an assoc. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 Any other suggestions? 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.