Jump to content

php voting


zunnu

Recommended Posts

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?  :happy-04:  

Sorry for bad english.

Link to comment
Share on other sites

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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.