Jump to content

Archived

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

SieRobin

Quick Question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
$result = mysql_fetch_assoc($q);
$race_array = explode(",", $result);

Should do it...

Share this post


Link to post
Share on other sites
try

$result = mysql_fetch_assoc($q);
$race_array = explode(" ", $result);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites

×

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.