Raised This Month: $ Target: $400
 0% 

Random number to each player.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Paulster1022
Member
Join Date: Apr 2006
Old 03-16-2011 , 04:09   Random number to each player.
Reply With Quote #1

I am basically trying to set a random number to each player and also making sure it doesn't equal anyone else's number. It works of course, but my server is crashing. I know this because when i comment this function out, crashes don't exist. Is there a more efficient way of doing this? Thanks in advance.

Code:
public round_start() set_numbers()

// ============= Assigns a random number to each player ==================
set_numbers()
{
	new alive_humans = get_alivehumans()

	// Give Players random suspect #. If the same number as anyone else, redo loop.
	for(new i = 1; i <= maxplayers; i++)
    	{
		if(is_user_alive(i))
		{
			if(PlayerInfo[i] == HUMAN)
			{
				pnumber[i] = random_num(1, alive_humans)

				for(new j = i - 1; j >= 1; j--)
    				{
					if(pnumber[i] == pnumber[j])
					{
						i--
						break
					}
				}		
			}
		}
	}	
}

get_alivehumans()
{
	new alive_humans
	alive_humans = 0
	
	for(new id = 1; id <= maxplayers; id++)
	{
		if (is_user_alive(id) && PlayerInfo[id] == HUMAN)
			alive_humans++
	}
	
	return alive_humans
}

Last edited by Paulster1022; 03-16-2011 at 04:13.
Paulster1022 is offline
Send a message via AIM to Paulster1022
 



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 14:41.


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