Jump to content

Quick Question


SieRobin

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.

Link to comment
https://forums.phpfreaks.com/topic/10655-quick-question/
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]
Link to comment
https://forums.phpfreaks.com/topic/10655-quick-question/#findComment-39763
Share on other sites

  • 2 months later...
  • 2 weeks later...
[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

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

[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

[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

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.