Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MySql - Saving Kills ( PlayerStats Plugin Fix ? )

Comments in 'Plugin Development' started by Radix, Aug 12, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    The code is down below but it does not save player kills ....
    PHP:

    /**
    API PART

    */
      /**
      * @param Player $player
      * @return null|int
      */
      
    public function getKills(Player $player){
      
    $name trim(strtolower($player->getName()));
      
    $result $this->db->query("SELECT * FROM player_stats WHERE name = '".$this->db->escape_string($name)."'");
      if(
    $result instanceof \mysqli_result){
      
    $data $result->fetch_assoc();
      
    $result->free();
      if(isset(
    $data["name"]) and strtolower($data["name"]) === $name){
      unset(
    $data["name"]);
      return 
    $data["kills"];
      }
      }
      return 
    null;
      }


    /**

    NON API
    */

      /**
      * @param PlayerDeathEvent $event
      */
      
    public function DeathEvent(PlayerDeathEvent $event){
      
    $victim $event->getEntity();
      if(
    $victim instanceof Player){
      
    $this->db->query("UPDATE player_stats SET deaths = deaths +1 WHERE name = '".strtolower($this->db->escape_string($event->getEntity()->getPlayer()->getDisplayName()))."'");
      
    $cause $event->getEntity()->getLastDamageCause()->getCause();
      if(
    $cause == 1){
      
    $killer $event->getEntity()->getLastDamageCause()->getEntity();
      if(
    $killer instanceof EntityDamageByEntityEvent){
      
    $this->db->query("UPDATE player_stats SET kills = kills +1 WHERE name = '".strtolower($this->db->escape_string($killer))."'");
      }

      }
      }
      }

    [​IMG]

    Website: http://stats.dr-pvp.net/stats/purple/stats.php?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    getEntity()->getPlayer()?
  3. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Umm , Idk ...
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Who coded this? How can an Entity object be a EntityDamageByEntityEvent???
  5. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Idk , Its in plugin repo , Can it be fixed?
  6. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    any fix?
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    @Radix, the fix is so easy. Just add a var before instanceof called '$cause'.
    And it is:
    PHP:
     $cause $event->getEntity()->getLastDamageCause(); 
    And change the
    PHP:
     if($killer instanceof … 
    to
    PHP:
     if($cause instanceof … 
  8. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  9. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Even after still doesnt work

    I'll try this again!
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It still does not work... Hmmm...
  11. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
  12. Goerick
    Offline

    Goerick Active Member

    Joined:
    Jan 24, 2014
    Posts:
    250
    Minecraft User:
    goerick
    Maybe "steal" the code from killrate, atleast get an idea
  13. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
    Run a query on enable something on the lines of "CREATE TABLE IF NOT EXISTS ''table name"
  14. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    I just want to track kills and death thats all , Kill rate has a really nasty structure!
    [​IMG]

    How am I suppose to freaking show this in a webpage ? Its so easy with PlayerStats structure!
    PEMapModder likes this.
  15. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
    With some query like:
    SELECT * FROM Scores WHERE player = "0speed0"

    And then you would get each type as count o.o?
  16. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    i have test, if u set all correct it have to run... please contact me if u re online by kik!
  17. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    will try it for easier use
  18. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    $link = mysqli_connect("$this->serverip", "$this->user", "$this->password");
    if (!mysqli_select_db('mydb', "$link")) {

    mysqli_query('CREATE DATABASE mydb');
    mysqli_select_db('mydb');
    }


    if (!mysqli_select_db('mydb', "$link")) { //<--- "mysqli_select_db() expects parameter 1 to be mysqli, string given"
    if (!mysqli_select_db('mydb', `$link`)) { //<--- "Object of class mysqli could not be converted to string"
    if (!mysqli_select_db('mydb', $link)) { //<--- "Object of class mysqli could not be converted to string"

    this line makes me trouble! can anyone help???

  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What?
    Xenturio likes this.
  20. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio

Share This Page

Advertisement