Raised This Month: $ Target: $400
 0% 

Random problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fxfighter
Veteran Member
Join Date: Feb 2007
Location: Trollhättan
Old 07-15-2007 , 06:07   Random problem
Reply With Quote #1

i cant get a way to give all players a random number betwin 1-32 at start and no one can get the same number.
enyone have eny ide?
__________________
If one of my plugins become broken, contact me by mail. [email protected]
fxfighter is offline
Send a message via MSN to fxfighter
Drak
Veteran Member
Join Date: Jul 2005
Old 07-15-2007 , 06:56   Re: Random problem
Reply With Quote #2

Code:
new playerNum[33]; // Global public giveNum(id) {     if(id>=1)     {         new number = random_num(1,32)         if(checkNum(number))         {             playerNum[id] = number;         } else {             giveNum(id)         }         return PLUGIN_HANDLED     }         new i,players[32],num     get_players(players,num)     for(i;i<num;i++)     {         new randomNum = random_num(1,32)         if(checkNum(randomNum))         {             playerNum[i] = randomNum;         } else {             giveNum(i) // Someone has the number, call the function again. Only for this player         }             } } public checkNum(number) {     for(new i;i<sizeof(playerNum);i++) {         if(number == playerNum[i]) {             return 0;         } else {             return 1;         }     } }
I think i'm making this way over complicated, but... This might, but probably wont, work.

Just call the function with id being zero.
__________________
Oh yeah

Last edited by Drak; 07-15-2007 at 07:11.
Drak is offline
Send a message via MSN to Drak
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 07-15-2007 , 12:48   Re: Random problem
Reply With Quote #3

I would make it this way:

PHP Code:
#include <amxmodx>
new g_player_num[33]
new 
g_max_players

public plugin_init(){
    
register_plugin"test""1.0""Sylwester" )
    
g_max_players get_maxplayers()
    
set_numbers()
    
mix_numbers()
}

public 
set_numbers(){   //set default numbers {1,...,32}
    
for(new i=1i<=32i++)
        
g_player_num[i] = i
}

public 
mix_numbers(){   //exchange every number with randomly chosen
    
new temp_exchange
    
new temp_random

    
for(new i=1i<=g_max_playersi++){
        
temp_random random_num(1g_max_players)  //use this if you want to give them numbers {1,...,g_max_players}
        //temp_random = random_num(1, 32)    //use this if you want to give them numbers {1,...,32}

        //exchange numbers
        
temp_exchange g_player_num[i]
        
g_player_num[i] = g_player_num[temp_random]
        
g_player_num[temp_random] = temp_exchange
    
}

__________________
Impossible is Nothing

Last edited by Sylwester; 07-15-2007 at 12:52.
Sylwester is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 07-15-2007 , 16:21   Re: Random problem
Reply With Quote #4

Hum with you'r code, sylwester i maked this! Is always show me 1 ...my userid!

Code:
#include <amxmodx>
 
#define PLUGIN "Random Num"
#define VERSION "1.0"
#define AUTHOR "sylwester"
 
new g_player_num[33]
new g_max_players
 
public plugin_init() {
 
 register_plugin(PLUGIN, VERSION, AUTHOR);
 register_event("HLTV", "new_round", "a", "1=0", "2=0");
 
 g_max_players = get_maxplayers();
}
 
public new_round() {
 
 set_task(1.0,"set_numbers");
 set_task(1.5,"mix_numbers");
}
 
public set_numbers() {
 
 for(new i=1 ; i <= g_max_players ; i++)
  g_player_num[i] = i;
}
 
public mix_numbers() {
 
 new temp_exchange;
 new temp_random;
 
 for(new i=1 ; i <= g_max_players ; i++)
 {
  temp_random = random_num(1, g_max_players);
 
  temp_exchange = g_player_num[i];
  g_player_num[i] = g_player_num[temp_random];
  g_player_num[temp_random] = temp_exchange;
 
  client_print(i, print_chat, "You'r number : %i", temp_exchange);
 }
}
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 07-15-2007 , 17:14   Re: Random problem
Reply With Quote #5

You made some mistakes.
PHP Code:
#include <amxmodx>
 
#define PLUGIN "Random Num"
#define VERSION "1.0"
#define AUTHOR "sylwester"
 
new g_player_num[33]
new 
g_max_players
 
public plugin_init() {
 
 
register_plugin(PLUGINVERSIONAUTHOR);
 
register_event("HLTV""new_round""a""1=0""2=0");
 
 
g_max_players get_maxplayers();
 
set_numbers();    //you need to use set_numbers function only once
}
 
public 
new_round() {
 
// set_task(1.0,"set_numbers");  
 
set_task(1.5,"mix_numbers");
}
 
public 
set_numbers() {
// for(new i=1 ; i <= g_max_players ; i++)
//fill whole array with numbers, it's not mistake but may avoid some errors later
//in case you want to use temp_random = random_num(1, 32);
 
for(new i=<= 32 i++)
  
g_player_num[i] = i;
}
 
public 
mix_numbers() {
 
 new 
temp_exchange;
 new 
temp_random;
 
 for(new 
i=<= g_max_players i++)
 {
  
temp_random random_num(1g_max_players);
 
  
temp_exchange g_player_num[i];
  
g_player_num[i] = g_player_num[temp_random];
  
g_player_num[temp_random] = temp_exchange;

  
//temp_exchange is not your current number, it's your old number
  //client_print(i, print_chat, "You'r number : %i", temp_exchange);
  //displaying numbers to players here is wrong
  //(number for current player may change in next iterations)
 
}

 for(new 
i=<= g_max_players i++)
 {
  
client_print(iprint_chat"Your number : %i"g_player_num[i]);
 }


__________________
Impossible is Nothing

Last edited by Sylwester; 07-15-2007 at 17:17.
Sylwester is offline
fxfighter
Veteran Member
Join Date: Feb 2007
Location: Trollhättan
Old 07-16-2007 , 04:44   Re: Random problem
Reply With Quote #6

wow thx guys
__________________
If one of my plugins become broken, contact me by mail. [email protected]
fxfighter is offline
Send a message via MSN to fxfighter
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode