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

Stupid PHP question

Comments in 'Plugin Development' started by MyNameIsTriXz, Feb 1, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I want to count the kills of every player,
    I do $this->players [$player->getName] = 1;
    When I want to add a kill, I do $this->players[$player->getName()] = $this->players[$player->getName()] + 1;
    Is that right?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    no, why don't you test instead of making a useless thread?
    missing () on
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Would also be better to use
    PHP:
    $this->players[$player->getName()] += 1;
    and maybe strtolower() on the Name.
    And by the way, why using an array that resets on server restart to save the amount of kills?
  4. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    I Think the best is ->
    PHP:
    $this->players[strtolower($player->getName())]++;
    xD
    or use a config and store there the kills ^^
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I dont do a K/D plugin.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Yeah, sounds good, thx, btw why should I use strtolower?
  7. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Why dont you help me, I couldnt test it, because I need more players for that...
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    If a player changes his name(for example from "hey" to "Hey"), it wouldn't have the same amount of Kills(without strtolower)
    applqpak and PocketKiller like this.
  9. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Oh okay, but I use it for the session
  10. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    If you're saving it in an array, the kills reset after the server does.

    I suggest you save it with json_encode and json_decode, this way it saves them to a file and you can access it again in array format.
    PocketKiller likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There are the ++ and -- operators.
    applqpak likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In that way, it might be useful to store an array of Config objects that contain the data, construct upon player join, modify upon kill, save (and remember, unset to free memory!) upon player quit.
    applqpak likes this.

Share This Page

Advertisement