Jump to content
MakeWebGames

Stat potions


Damond

Recommended Posts

Our game is almost ready for beta testing. We have two more mods that really need to be installed/created, then going through each file and making sure to look for security issues. My coding partner is out of the picture for now with a snow causing him to have no power issue so I am going to turn to you guys for help in finishing the next mod.

We are working on stat potions. AKA elixirs in Flight of Dragons.

Veramis was able to create a start to the system which I have in turn been able to make work but not correctly.

This is in the item use file:

 

if($r['effect1_on']){
if ($r['itmid'] == 135) {
	$s = $ir['strength'];
	$d = (.5);
	$text = "strength";
	$stat = $s * $d;
	$statt = $stat + $ir['strength'];
	$db->query("INSERT INTO statsbonus VALUES($userid,$stat,135,30,'$text’,1)”);

	$db->query("UPDATE userstats SET strength=strength+$stat WHERE userid={$userid}");
	print"You used an Elixer of Strength and can feel yourself getting stronger, your strength is now ".number_format($statt)." for the next 30 minutes.";
}
}

 

This is in the new Cron file:

Thank you [MENTION=68774]HauntedDawg[/MENTION]

 

$query_stat 	= sprintf("UPDATE statsbonus SET wait_time=wait_time - %u WHERE wait_time <> 0", $statsbonus);
$db->query($query_stat);
$db->query("UPDATE `statsbonus` SET `wait_time` = 0 WHERE `wait_time` < 0");

$e = $db->query("SELECT * FROM statsbonus WHERE wait_time = 0 and userid=$userid");
$f = $db->fetch_row($e);
if($f['wait_time'] == 0){
	$stat = $f['bonus'];
    $text = $f['stat'];

		if($text == 'strength'){
			$db->query("UPDATE userstats SET strength=strength-$stat WHERE userid=".$f['userid']."");
			event_add($userid, "Your {$text} elixir wore off.", $c);
		}
}

$db->query("DELETE FROM statsbonus WHERE wait_time = 0");

 

My table is set up:

userid

bonus <—— What the bonus amt is.

elixir <—— Item number

wait_time <—— How long it lasts

stat <—— What stat its effecting

stack_atm <—— How many have been used in a row

 

Where my problem come in is if you use more then one at a time. I know it is going to need to be something more like:

 

if ($r['itmid'] == 135) {
	$s = $ir['strength'];
	$d = (.5);
	$text = "strength";
	$stat = $s * $d;
	$statt = $stat + $ir['strength'];
$sb		= $db->query(“SELECT * FROM stats bonus WHERE userid = $userid”);
$bonus 	= $db->fetch_row($sb);
if ($bonus[’stat’] == ‘strength’) {
	$db->query(“UPDATE statsbonus SET bonus = bonus + $stat, stack_amt = stack_amt + 1”);
	$db->query("UPDATE userstats SET strength=strength+$stat WHERE userid={$userid}");
	print"You used an Elixir of Strength and can feel yourself getting stronger, your strength is now ".number_format($statt)." for the next 30 minutes.";
} else {
	$db->query("INSERT INTO statsbonus VALUES($userid,$stat,135,30,'$text’,1)”);
	$db->query("UPDATE userstats SET strength=strength+$stat WHERE userid={$userid}");
	print"You used an Elixir of Strength and can feel yourself getting stronger, your strength is now ".number_format($statt)." for the next 30 minutes.";
}
}

 

I know its wrong but hey I have been coding PHP and SQL for a total of three months now.

Right now as long as you don't use more then one it works exactly as it is supposed too. But we want users to be able to use more then one.

So the idea is:

You use the elixir.

Your strength goes up by 50% for 30 minutes.

You use a second elixir.

Your NEW strength go up by 50% again for 30 minutes.

And so on stacking as many as you want

When the first 30 minutes are up you get an event telling you.

Total strength is now - the first bonus.

Same with the second and so forth until you are again at your normal stat.

I can feel that I am on the right path. I just need a little more direction.

Link to comment
Share on other sites

Right well first thing i can notice is this:

$sb     = $db->query(“SELECT * FROM stats bonus WHERE userid = $userid”);

believe that should be:

$sb     = $db->query(“SELECT * FROM statsbonus WHERE userid = $userid”);

 

next I would set the code up like this:

$sb     = $db->query(“SELECT * FROM statsbonus WHERE userid = $userid”);
   $nr = $db->num_rows($sb);
   if($nr > 0)
   {
       $bonus  = $db->fetch_row($sb);
       if ($bonus['stat'] == 'strength') {
           $db->query("UPDATE statsbonus SET bonus = bonus + $stat, stack_amt = stack_amt + 1 WHERE userid='$userid'");
           $db->query("UPDATE userstats SET strength=strength+$stat WHERE userid='$userid'");
           print "You used an Elixir of Strength and can feel yourself getting stronger, your strength is now ".number_format($statt)." for the next 30 minutes.";
       } else {
           $db->query("INSERT INTO statsbonus VALUES($userid,$stat,135,30,'$text’,1)”);
           $db->query("UPDATE userstats SET strength=strength+$stat WHERE userid='$userid'");
           print "You used an Elixir of Strength and can feel yourself getting stronger, your strength is now ".number_format($statt)." for the next 30 minutes.";
       } 
   }

 

Let us know if that works, I noticed you had forgot the where clause in:

$db->query("UPDATE statsbonus SET bonus = bonus + $stat, stack_amt = stack_amt + 1
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.

×
×
  • Create New...