Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Not letting me get get certain column values

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
Bloodmorphed
Smarty Rookie


Joined: 20 Aug 2017
Posts: 8

PostPosted: Wed Aug 23, 2017 5:39 am    Post subject: Not letting me get get certain column values Reply with quote

This is a long code, so there is a lot to look at. But when I am calling: $this->mobs->name or $mobid->name etc etc it doesn't work

Code:

<?php
//This file cannot be viewed, it must be included
defined('IN_EZRPG') or exit;

/*
  Class: Module_Battle
*/
class Module_Battle extends Base_Module
{
    /*
      Function: start

    */
    public function start()
    {
        // You may call the requireLogin() function if this module is only available to players who are logged in.
        requireLogin();

        if (isset($_POST['battle_mob']))
        {
          $this->battleMob();
        }

        else
        {
          $query = $this->db->execute('SELECT * FROM `<ezrpg>mobs`');
          $mobs = $this->db->fetchAll($query);
          $this->tpl->assign('mobs', $mobs);
          $this->tpl->display('battle.tpl');
        }
    }

    private function battleMob()
    {

      /* Player variables */

      $player = $this->player;
      $playerhp = floor($player->max_hp * $player->vitality / 2);
      $playermhp = floor($player->max_hp * $player->vitality / 2);
      $wepmin = floor(($player->wep1_level * 5) / 2);
      $wepmax = floor(($player->wep1_level * 10) / 2);
      $playerap = rand(1, $player->agility);
      $helmdef = floor(($player->helm_level + 5 * 5) / 3);
      $chestdef = floor(($player->chest_level + 10 * 6) / 3);
      $bootsdef = floor(($player->boots_level + 3 * 4) / 3);
      $playerdmg = floor($playerstr + rand($wepmin, $wepmax));
      $playerdef = floor(($player->strength + $player->dexterity / 2) + ($helmdef + $chestdef + $bootsdef / 3));
      $playerattlist = array($wepmin, $wepmax, $helmdef, $chestdef, $bootsdef, $playerdmg, $playerdef);

      /* Mob variables */
      $mobid = $_POST['selection'];
      $mobhp = floor((1 + $mobid) * 100 / 2);;
      $mobmhp = floor((1 + $mobid) * 100 / 2);
      $mobstr = floor(5 * $mobid);
      $mobagi = floor(5 * $mobid);
      $mobap = rand(1, $mobagi);
      $mobdex = floor(5 * $mobid);
      $mobdmg = $mobstr + $mobagi + $mobdex;
      $mobdef = floor(($mobstr + $mobdex / 2) + (5 * $mobid / 2));
      $mobattlist = array($mobid, $mobstr, $mobagi, $mobdex, $mobdmg, $mobdef);

      /* Drop calculation and value variables */
      $expgain = 5 * $mobid;
      $goldgain = 2 * $mobid;
      $crychance = rand(1, 100);
      $amechance = rand(1, 200);
      $diachance = rand(1, 400);
      $orbchance = rand(1, 400);
      $rubychance = rand(1, 500);
      $medalchance = rand(1, 1000);



      /*stats and other calculations */
      $playerhits = 0;
      $mobhits = 0;
      $playermiss = 0;
      $mobmiss = 0;
      $playerdamage = 0;
      $mobdamage = 0;
      $rounds = 0;
      $hitfirsttrigger = true;



      # START BATTLE LOOP #
      while ($playerhp > 0 && $mobhp > 0)
      {
        /* miss, dodge calculations */

        $missmob = 1;
        $missplayer = rand($mobagi, $player->agility);


        /* who hits first */
          if ($hitfirsttrigger == true && $player->agility >= $mobagi)
              { $playerturn = true; $hitfirsttrigger = false; }


        /* Battle Time! */

        if ($playerturn == true)
          {
            if ($missmob == 0)
            {
              $playermiss += 1;
              $rounds += 1;
              $playerturn = false;
            }
            else
            {
            if ($mobdef >= $playerdmg)
              {
                $dmgdeltmob = 0;
                $defreducmob = rand(0.05, 0.1);
                $mobdef = floor($mobdef - $playerap);
                $round += 1;
                $playerturn = true;
              }
             else
             {
                $dmgdeltmob = floor($playerdmg - $mobdef);
                $mobhp = $mobhp - $dmgdeltmob;
                $playerhits += 1;
                $rounds += 1;
                $playerdamage = $playerdamage + $dmgdeltmob;
                $playerturn = false;
             }
            }
          }

        elseif ($playerturn == false)
          {
            if ($missmob == 0)
            {
              $mobmiss += 1;
              $rounds += 1;
              $playerturn = true;
            }
            else
            {
              if ($playerdef >= $mobdmg)
              {
                $dmgdeltplayer = 0;
                $playerdef = floor($playerdef - $mobap);
                $round += 1;
                $playerturn = true;
              }
              else
              {
              $dmgdeltplayer = floor($mobdmg - $playerdef);
              $playerhp = $playerhp - $dmgdeltplayer;
              $mobhits += 1;
              $round += 1;
              $mobdamage = $mobdamage + $dmgdeltplayer;
              $playerturn = true;
              }
            }
          }
      } # END BATTLE LOOP #


      # Battling results #
      $playerresulthp = $playerhp . " / " . $playermhp;
      $mobresulthp = $mobhp . " / " . $mobmhp;

      $roundresult = "You totaled " . $rounds . " rounds.";

      $playerbattle = "You did " . number_format($playerdamage) . "to " . $wepmin . "with your " . $player->wep1_name . ".
      You missed " . $playermiss . "times and hit " . $playerhits . " times.";
      $mobbattle = $this->mobs->name . " has done" . $mobdamage . " to you. Missing " . $mobmiss . " and hitting" . $mobhits .
      " times.";

      $this->tpl->assign('playerresulthp', $playerresulthp);
      $this->tpl->assign('mobresulthp', $mobresulthp);
      $this->tpl->assign('roundresult', $roundresult);
      $this->tpl->assign('playerbattle', $playerbattle);
      $this->tpl->assign('mobbattle', $mobbattle);
      # End Battling Results #

      /* Victory / Defeat Check */
      if ($playerhp <= 0)
      {
        #Defeat
        $victorymsg = "";
        $deathmsg = "You've been defeated!";
        $query = $this->db->execute('UPDATE `<ezrpg>players` SET `deaths`=`deaths`+1, `lastmob`=? WHERE `id`=?', array($mobid, $player->id));
        $this->tpl->assign('deathmsg', $deathmsg);

      }
      else
      {
        #Victory
        $query = $this->db->execute('SELECT * FROM `<ezrpg>mobs`');
        $mobs = $this->db->fetchAll($query);
        $deathmsg = "";
        $victorymsg = "You have defeated " . $mobid->name . ". <br /> You have gained " . $expgain . " experience. <br /> You have gained " . $goldgain . " gold.";
        $query = $this->db->execute('UPDATE `<ezrpg>players` SET `lastmob`=?, `kills`=`kills`+1, `exp`=`exp`+?, `money`=`money`+? WHERE `id`=?', array($mobid, $expgain, $goldgain, $player->id));
        $this->tpl->assign('victorymsg', $victorymsg);

      }


      $query = $this->db->execute('SELECT * FROM `<ezrpg>mobs`');
      $mobs = $this->db->fetchAll($query);
      $this->tpl->assign('mobs', $mobs);
      $this->tpl->display('battle.tpl');
  }
}
?>


Also have an issue where itll mess up my template every once in awhile (like it doesn't load the CSS and messes with the width values, kinda weird, but thats a different problem for another time).

I don;t know much about databases and MYSql, so I figured this would work based on how the whole thing is set-up. [/code]
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Wed Aug 23, 2017 1:19 pm    Post subject: Reply with quote

I don't see anything Smarty-relevant in your question.
Either rephrase it, or find a beter place to ask.
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 191
Location: West Coast

PostPosted: Wed Aug 23, 2017 4:00 pm    Post subject: Reply with quote

You are assigning various data sets to the template, and you say the rendered template does not have what you expect.

At the end of your template file, add {debug}. Allow your browser to show a popup window. Make a page request. Examine the variables and their values.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP