Jump to content
MakeWebGames

[help V2] Edit Item


Canjucks
 Share

Recommended Posts

I have been working on the Edit Item (staff_items.php) and whats happening is that the item will Edit no problem but if a user has this item in there inventory, it will lose its value/details when edited. I have been testing this out with a test item to see if my code edits work or just make ithe problem worse...lol. What I can do however, is manually edit the item in the database and the item will still be valid in the users inventory.

Can anyone help on this? My thinking is for this to update correctly there should be maybe a line directing it to the inventory. Or could be the itempics because that doesn't always show up.

Here s the Edit Item Code as that is where my issue is

print "<h3>Editing Item</h3>
You can edit any aspect of this item.

<form action='staff_items.php?action=edititemform' method='post'>
Item: ".item_dropdown($c,'item')."

<input type='submit' value='Edit Item' /></form>";
}
function edit_item_form()
{
global $db,$ir,$c,$h;
if($ir['user_level'] > 2)
{
die("403");
}
$d=$db->query("SELECT * FROM items WHERE itmid={$_POST['item']}");
$itemi=$db->fetch_row($d);
print "<h3>Editing Item</h3>
<form action='staff_items.php?action=edititemsub' method='post'>
<input type='hidden' name='itmid' value='{$_POST['item']}' />
Item Name: <input type='text' name='itmname' value='{$itemi['itmname']}' />

Item Desc.: <input type='text' name='itmdesc' value='{$itemi['itmdesc']}' />

Item Type: ".itemtype_dropdown($c,'itmtype',$itemi['itmtype'])."

Item Buyable: <input type='checkbox' name='itmbuyable'";
if ($itemi['itmbuyable']) { print " checked='checked'"; }
print " />
Item Price: <input type='text' name='itmbuyprice' value='{$itemi['itmbuyprice']}' />

Item Sell Value: <input type='text' name='itmsellprice' value='{$itemi['itmsellprice']}' /><hr />[b]Usage Form[/b]<hr />";
$stats=array(
"energy" => "Energy",
"will" => "Will",
"brave" => "Brave",
"hp" => "Health",
"strength" => "Strength",
"agility" => "Agility",
"guard" => "Guard",
"labour" => "Labour",
"IQ" => "IQ",
"hospital" => "Hospital Time",
"jail" => "Jail Time",
"money" => "Money",
"crystals" => "Crystals",
"cdays" => "Education Days Left",
"bankmoney" => "Bank money",
"cybermoney" => "Cyber money",
"crimexp" => "Crime XP");
for($i=1;$i<=3;$i++)
{
 if($itemi["effect".$i])
 {
   $efx=unserialize($itemi["effect".$i]);
 }
 else
 {
   $efx=array("inc_amount" => 0);
 }
 $switch1=($itemi['effect'.$i.'_on'] > 0) ? " checked='checked'" : "";
 $switch2=($itemi['effect'.$i.'_on'] > 0) ? "" : " checked='checked'";
 print "[b]<u>Effect {$i}</u>[/b]

On? <input type='radio' name='effect{$i}on' value='1'$switch1 /> Yes <input type='radio' name='effect{$i}on' value='0'$switch2 /> No

Stat: <select name='effect{$i}stat' type='dropdown'>";
 foreach($stats as $k => $v)
 {
   if($k==$efx['stat'])
   {
     print "<option value='{$k}' selected='selected'>{$v}</option>\n";
   }
   else
   {
     print "<option value='$k'>{$v}</option>\n";
   }
 }
 if($efx['dir']=="neg")
 {
   $str="<option value='pos'>Increase</option><option value='neg' selected='selected'>Decrease</option>";
 }
 else
 {
   $str="<option value='pos' selected='selected'>Increase</option><option value='neg'>Decrease</option>";
 }
 if($efx['inc_type']=="percent")
 {
   $str2="<option value='figure'>Value</option><option value='percent' selected='selected'>Percent</option>";
 }
 else
 {
   $str2="<option value='figure' selected='selected'>Value</option><option value='percent'>Percent</option>";
 }
 print "</select> Direction: <select name='effect{$i}dir' type='dropdown'>{$str}
 </select>

 Amount: <input type='text' name='effect{$i}amount' value='{$efx['inc_amount']}' /> <select name='effect{$i}type' type='dropdown'>{$str2}</select><hr />";
}

print "[b]Combat Usage[/b]

Weapon Power: <input type='text' name='weapon' value='{$itemi['weapon']}' />

Weapon/Armour Level: <input type='text' name='level' value='{$itemi['level']}' />

Armor Defense: <input type='text' name='armor' value='{$itemi['armor']}' /><hr />
[b]Item Pics[/b]

<input type='text' name='itmpic' value='{$itemi['itmpic']}' /><hr />
<input type='submit' value='Edit Item' /></form>";
}
function edit_item_sub()
{
global $db,$ir,$c,$h,$userid;
if($ir['user_level'] > 2)
{
die("403");
}

if(!isset($_POST['itmname']) || !isset($_POST['itmdesc']) || !isset($_POST['itmtype'])  || !isset($_POST['itmbuyprice']) || !isset($_POST['itmsellprice']))
{
print "You missed one or more of the fields. Please go back and try again.

[url='staff_items.php?action=edititem']> Back[/url]";
$h->endpage();
exit;
}
$itmname=$_POST['itmname'];
$itmdesc=$_POST['itmdesc'];
$weapon=abs((int) $_POST['weapon']);
$level=abs((int) $_POST['level']);
$armor=abs((int) $_POST['armor']);
if($_POST['itmbuyable'] == 'on') { $itmbuy=1; } else { $itmbuy=0; }
$db->query("DELETE FROM items WHERE itmid={$_POST['itmid']}",$c);
$efx1=$db->escape(serialize(array("stat" => $_POST['effect1stat'], "dir" => $_POST['effect1dir'], "inc_type" => $_POST['effect1type'], "inc_amount" => abs((int) $_POST['effect1amount']))));
$efx2=$db->escape(serialize(array("stat" => $_POST['effect2stat'], "dir" => $_POST['effect2dir'], "inc_type" => $_POST['effect2type'], "inc_amount" => abs((int) $_POST['effect2amount']))));
$efx3=$db->escape(serialize(array("stat" => $_POST['effect3stat'], "dir" => $_POST['effect3dir'], "inc_type" => $_POST['effect3type'], "inc_amount" => abs((int) $_POST['effect3amount']))));
$m=$db->query("INSERT INTO items VALUES('',{$_POST['itmtype']},'$itmname','$itmdesc',{$_POST['itmbuyprice']},{$_POST['itmsellprice']},$itmbuy, '{$_POST['effect1on']}', '$efx1', '{$_POST['effect2on']}', '$efx2', '{$_POST['effect3on']}', '$efx3', $weapon, $armor, '{$_POST['itmpics']}' ,'$level')");
print "The {$_POST['itmname']} Item was edited successfully.";
stafflog_add("Edited item {$_POST['itmname']}");
}

 

Cheers in advance :mrgreen:

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...