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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.