Jump to content

php voting


zunnu

Recommended Posts

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);
Link to comment
https://forums.phpfreaks.com/topic/292740-php-voting/#findComment-1497803
Share on other sites

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?  :psychic:
Link to comment
https://forums.phpfreaks.com/topic/292740-php-voting/#findComment-1497817
Share on other sites

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));
Link to comment
https://forums.phpfreaks.com/topic/292740-php-voting/#findComment-1497901
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/292740-php-voting/#findComment-1497903
Share on other sites

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.
 

  1. //define it if doesn't exist
  2. if (!$this['already_played']) {
  3.    
  4.     $this['already_played'] = array();
  5.    
  6. }
  7.  
  8. $new_maps = array();
  9.  
  10. if ($message->getUserTeam() == "CT") {
  11.     $team = ($this->side['team_a'] == "ct") ? $this->teamAName : $this->teamBName;
  12.     $maps = \eBot\Config\Config::getInstance()->getMaps();
  13.    
  14.     if (in_array($preg['mapname'], $maps) && !in_array($preg['mapname'], $this['already_played'])) {
  15.         $this->playMap['ct'] = $preg['mapname'];
  16.         $this->say($team . " (CT) \003Removed \004" . $preg['mapname']);
  17.        
  18.         //adding map into session
  19.        
  20.         $this['already_played'][] = $preg['mapname'];
  21.        
  22.        
  23.     } else {
  24.         $this->say($preg['mapname'] . " was not found! Available maps are:");
  25.        
  26.         $new_maps = array_diff($maps, $this['already_played']); //maps in session removed from maps array
  27.        
  28.         //reset already played session when list is 1 or less
  29.          if (count($new_maps) <= 1) {
  30.            
  31.             $this['already_played'] = array();
  32.            
  33.         }
  34.        
  35.        
  36.         foreach ($new_maps as $map) {            
  37.             $mapmessage .= "$map, ";            
  38.         }
  39.        
  40.        
  41.     }
  42.     $this->say(substr($mapmessage, 0, -2));                    }
Link to comment
https://forums.phpfreaks.com/topic/292740-php-voting/#findComment-1497921
Share on other sites

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.

or

Ban A - Ban B - Ban A - Ban B - Randomized map out of the three remaining

Would that be possible?
Link to comment
https://forums.phpfreaks.com/topic/292740-php-voting/#findComment-1497922
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.