zunnu Posted November 27, 2014 Share Posted November 27, 2014 Hello, I was wondering is it possible to create vote with php when people vote the voted thing will go away like for exsample if there is ingame map vote and players vote !map de_dust2 the de_dust2 will be removed from map list and the last map that stays will be used? Sorry for bad english. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 27, 2014 Share Posted November 27, 2014 Supplying some code would make this easier. If you have the map data in an array... doing by it's array key with unset() unset($array[0]); array_splice() array_splice($array, 0, 1);//array,key position, amount to remove from key position deleting an element in an array if only know it's value $key = array_search($value,$array); if($key!==false){ unset($array[$key]); } To reset the array keys array_values() $array = array_values($array); Quote Link to comment Share on other sites More sharing options...
zunnu Posted November 27, 2014 Author Share Posted November 27, 2014 There is this kind of code that im changing. if ($message->getUserTeam() == "CT") { $team = ($this->side['team_a'] == "ct") ? $this->teamAName : $this->teamBName; $maps = \eBot\Config\Config::getInstance()->getMaps(); if (in_array($preg['mapname'], $maps)) { $this->playMap['ct'] = $preg['mapname']; $this->say($team . " (CT) \003Removed \004" . $preg['mapname']); } else { $this->say($preg['mapname'] . " was not found! Available maps are:"); foreach ($maps as $map) { $mapmessage .= "$map, "; } $this->say(substr($mapmessage, 0, -2));if i change $this->playMap['ct'] = $preg['mapname']; to $this->unset['ct'] = $preg['mapname']; will that remove map and how can i set that it would be removed from listning too? Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 28, 2014 Share Posted November 28, 2014 Your best bet is to make a session to retain the data I would make a $_SESSION['already_played'] array Every time a map is played it can add it to $_SESSION['already_played'] For the game maps list you would show all but the ones that are in the $_SESSION['already_played'] When the number of maps left is 1...you can clear the $_SESSION['already_played'] so they all show again Guessing this may work session_start(); //top of the script //define it if doesn't exist if (!$_SESSION['already_played']) { $_SESSION['already_played'] = array(); } $new_maps = array(); if ($message->getUserTeam() == "CT") { $team = ($this->side['team_a'] == "ct") ? $this->teamAName : $this->teamBName; $maps = \eBot\Config\Config::getInstance()->getMaps(); if (in_array($preg['mapname'], $maps) && !in_array($preg['mapname'], $_SESSION['already_played'])) { $this->playMap['ct'] = $preg['mapname']; $this->say($team . " (CT) \003Removed \004" . $preg['mapname']); //adding map into session $_SESSION['already_played'][] = $preg['mapname']; } else { $this->say($preg['mapname'] . " was not found! Available maps are:"); $new_maps = array_diff($maps, $_SESSION['already_played']); //maps in session removed from maps array //reset already played session when list is 1 or less if (count($new_maps) <= 1) { $_SESSION['already_played'] = array(); } foreach ($new_maps as $map) { $mapmessage .= "$map, "; } } $this->say(substr($mapmessage, 0, -2)); Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 28, 2014 Share Posted November 28, 2014 I guess depends on the type of game, if sessions doesn't work then save data to the database instead. Something has to track the games played each time and then reset them each time the script is loaded, can't just do it with code. Quote Link to comment Share on other sites More sharing options...
zunnu Posted November 28, 2014 Author Share Posted November 28, 2014 Thanks alot for help!There isn't session in the ebot daemon because its not web page But i can store it in the ebot memory I replaced $_SESSION by $this but it didn't work or maybi i missed something. //define it if doesn't exist if (!$this['already_played']) { $this['already_played'] = array(); } $new_maps = array(); if ($message->getUserTeam() == "CT") { $team = ($this->side['team_a'] == "ct") ? $this->teamAName : $this->teamBName; $maps = \eBot\Config\Config::getInstance()->getMaps(); if (in_array($preg['mapname'], $maps) && !in_array($preg['mapname'], $this['already_played'])) { $this->playMap['ct'] = $preg['mapname']; $this->say($team . " (CT) \003Removed \004" . $preg['mapname']); //adding map into session $this['already_played'][] = $preg['mapname']; } else { $this->say($preg['mapname'] . " was not found! Available maps are:"); $new_maps = array_diff($maps, $this['already_played']); //maps in session removed from maps array //reset already played session when list is 1 or less if (count($new_maps) <= 1) { $this['already_played'] = array(); } foreach ($new_maps as $map) { $mapmessage .= "$map, "; } } $this->say(substr($mapmessage, 0, -2)); } Quote Link to comment Share on other sites More sharing options...
zunnu Posted November 28, 2014 Author Share Posted November 28, 2014 And with the vote i mean is • 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.orBan A - Ban B - Ban A - Ban B - Randomized map out of the three remainingWould that be possible? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.