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. Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/ 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] Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-39763 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 :] Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-65927 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? Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71537 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] Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71577 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? Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71607 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... Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71628 Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 Doesn't work. Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71630 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); Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71631 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 Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71632 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. Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71634 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. Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71635 Share on other sites More sharing options...
SieRobin Posted August 9, 2006 Author Share Posted August 9, 2006 Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-71875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.