PHP Vote

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zunnu
Forum Newbie
Posts: 3
Joined: Sun Dec 14, 2014 3:19 pm

PHP Vote

Post by zunnu »

Hello,

I would like to make map vote to game with php!

Vote should go like this

• Team B removes one of the 7 maps;
• Team A removes one of the 6 remaining maps;
• Team B removes one of the 5 remaining maps;
• Team A removes one of the 4 remaining maps;
• Team B removes one of the 3 remaining maps;
• Team A picks the map to be played on;
The last map remaining will be discarded.

Problem is that i don't know how i can remove map from array when its voted like if somebody uses "!map test" that the map would be removed and last map will be used

$maps = $array = array(test1, "test2", test3, "test4", "test5");
print_r(array_count_values($array));
or how could i remove from list?

$maps = \folder\Config\Config::getInstance()->getMaps();
zunnu
Forum Newbie
Posts: 3
Joined: Sun Dec 14, 2014 3:19 pm

Re: PHP Vote

Post by zunnu »

Forgot this:

Code: Select all

$text = trim($message->getText());
        if (preg_match('/\!map (?<mapname>.*)/i', $text, $preg)) {
            if (!$this->mapIsEngaged && (( $this->getStatus() == self::STATUS_WU_KNIFE && $this->config_kniferound ) || ( $this->getStatus() == self::STATUS_WU_1_SIDE && !$this->config_kniferound ))) {
                $this->addLog($message->getUserName() . " (" . $message->getUserTeam() . ") removed" . $preg['mapname']);
                Logger::log($message->getUserName() . " (" . $message->getUserTeam() . ") removed " . $preg['mapname']);
                if ($message->getUserTeam() == "CT") {
                    $team = ($this->side['team_a'] == "ct") ? $this->teamAName : $this->teamBName;
                    $maps = $array = array(test1, "test2", test3, "test4", "test5");
			print_r(array_count_values($array));
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Vote

Post by requinix »

You do know that nobody here knows what you're talking about, right? No idea what these maps are or where this code is coming from or how it's used...

Assuming this is running like a regular PHP script, you have to store the maps somewhere so that the next time PHP runs it can look up the current set of maps and act accordingly. Though your use of "!map" suggests an IRC bot, in which case this isn't a regular PHP script and the $maps stays in memory and you just need to make sure that you're passing that variable around your application so it doesn't get lost during execution.
zunnu
Forum Newbie
Posts: 3
Joined: Sun Dec 14, 2014 3:19 pm

Re: PHP Vote

Post by zunnu »

Okey so the game is counter-strike global offensive and by maps i mean like de_dust2 or de_nuke etc

The softare is called eBOT https://github.com/deStrO/eBot-CSGO

I hope this helps.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Vote

Post by requinix »

The answer depends on whether PHP is staying active or whether there's a new request every time something happens. Do you know the answer to that?

If not, set a global variable somewhere like

Code: Select all

global $asdfg; $asdfg = time();
and put that in a place you know only executes once. Like a bootloader or init script. Then check the value of

Code: Select all

$GLOBALS["asdfg"]
at some point in your code to see if that value ever changes. Hopefully not.
Post Reply