Jump to content


Photo

Quick Question


  • Please log in to reply
12 replies to this topic

#1 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 28 May 2006 - 05:17 PM

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?

if ($userstats3[race]==?) {
code here }

I'm just kind of confused on what to do.



#2 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 28 May 2006 - 05:45 PM

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

<?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.";
}

?>

Everything you want to know is here.

#3 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 30 July 2006 - 03:44 PM

Ahha, got it thank you for the help :]

#4 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 09 August 2006 - 12:59 AM

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

<?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.";
}

?>


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?

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 09 August 2006 - 02:17 AM

depends how they are stored. If there just comma delimetered string you could simply use explode, otherwise... you might need to generate an array from your database queries results. eg;

while ($row = mysql_fetch_assoc($result)) {
  $item_races[] = $row['race'];
}


#6 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 09 August 2006 - 03:44 AM

depends how they are stored. If there just comma delimetered string you could simply use explode, otherwise... you might need to generate an array from your database queries results. eg;

while ($row = mysql_fetch_assoc($result)) {
  $item_races[] = $row['race'];
}


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?

#7 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 09 August 2006 - 05:55 AM

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

Should do it...
Why doesn't anyone ever say hi, hey, or whad up world?

#8 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 09 August 2006 - 06:10 AM

Doesn't work.

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 August 2006 - 06:14 AM

try

$result = mysql_fetch_assoc($q);
$race_array = explode(" ", $result);
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 09 August 2006 - 06:17 AM

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

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 August 2006 - 06:21 AM

post your code then the select query ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 09 August 2006 - 06:24 AM

$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') {

I'm not sure if I'm doing it correctly since I've never used an assoc.

#13 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 09 August 2006 - 03:58 PM

Any other suggestions?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users