Help with programming a bot

Hey guys, need some help reprogramming the source code of a bot. The bot works by using various modules and I'm reprogramming the function called "FLATROLL". Flatroll is a function that randomly selects the winner of an item that the user has previously added to. What I want to do is reprogram it so I, "Bobby", am always the winner when I add to that item. . The problem that I'm having is that the $winner is stored in an array. So if I change $winner to "Bobby" it makes ALL the winners "Bobby", not just the item I added to. This is problematic. Any help would be appreciated.
Heres the Code for FLATROLL :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 global $loot;
global $loot_winners;
global $residual;

if (preg_match("/^flatroll$/i", $message)) {
	//Check if a loot list exits
  	if (!is_array($loot)) {
	    $msg = "There is nothing to roll atm.";
	    $chatBot->send($msg, $sendto);
	    return;
	}
	
	srand( ((int)((double)microtime()*1000003)) ); // get a good seed
  	
  	$list = "<header> :::::: Win List :::::: <end>\n\n";
  	//Roll the loot
	$resnum = 1;
	forEach ($loot as $key => $item) {
  	  	$list .= "Item: <orange>{$item["name"]}<end>\n";
  	  	$list .= "Winner(s): ";
	    $users = count($item["users"]);
	 	if ($users == 0) {
	 		$list .= "<highlight>None added.<end>\n\n";
			$residual[$resnum]["name"] = $item["name"];
			$residual[$resnum]["icon"] = $item["icon"];
			$residual[$resnum]["linky"] = $item["linky"];
			$residual[$resnum]["multiloot"] = $item["multiloot"];
			$resnum++;
	 	} else {
			if ($item["multiloot"] > 1) {
				if ($item["multiloot"] > sizeof($item["users"])) {
					$arrolnum = sizeof($item["users"]);
				} else {
					$arrolnum = $item["multiloot"];
				}

				for ($i = 0; $i < $arrolnum; $i++) {
					$winner = array_rand($item["users"], 1);
					unset($item["users"][$winner]);
					$list .= "<red>$winner<end> ";
				}

				if ($arrolnum < $item["multiloot"]) {
					$newmultiloot = $item["multiloot"]-$arrolnum;
					$residual[$resnum]["name"] = $item["name"];
					$residual[$resnum]["icon"] = $item["icon"];
					$residual[$resnum]["linky"] = $item["linky"];
					$residual[$resnum]["multiloot"] = $newmultiloot;
					$resnum++;
				}
			} else {
            	$winner = array_rand($item["users"], 1);
				$list .= "<red>$winner<end>";
			}
			$list .= "\n\n";
		}
	}
	//Reset loot
	$winner = "";
	$arrolnum = "";
	$loot = "";
	//Show winner list
	$msg = Text::make_blob("Winner List", $list);
	if (is_array($residual)) {
		$rerollmsg = " (There are item(s) left to be rolled. To re-add, type <symbol>reroll)";
	} else {
		$rerollmsg = "";
	}

	$chatBot->send($msg.$rerollmsg, 'priv');

	if ($type != 'priv') {
		$chatBot->send($msg.$rerollmsg, $sendto);
	}
} else {
	$syntax_error = true;
}

?> 


Here is the code for Adding a player to item slot in the roll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
global $loot;
global $raidlist;
global $raidloot;

if (preg_match("/^add$/i", $message)) {
	//Check if a flat(multiroll) or pts roll is going on
	if ($chatBot->vars["raid_pts"] > 0) {
		$msg = "This raid is pts rolled. Use instead bid.";
		$chatBot->send($msg, $sender);
		return;
	}
	
	if (!isset($raidlist[$sender])) {
		$msg = "You need to be on the raidlist to be able to add to an item!";
		$chatBot->send($msg, $sender);
		return;		
	}

	$index = $chatBot->vars["raid_loot_index"];
	$cat = $chatBot->vars["raid_loot_cat"];
	
	//Check if minlvl is set and if the player is higher then it
	if (isset($raidloot[$cat][$index]["minlvl"])) {
	  	$whois = Player::get_by_name($sender);
	  	if ($whois === null || $whois->level < $raidloot[$cat][$index]["minlvl"]) {
		    $msg = "You need to be at least lvl<highlight>{$raidloot[$cat][$index]["minlvl"]}<end> to join this roll.";
	  		$chatBot->send($msg, $sender);
	  		return;
		}
	}
	  	
	//Check if the player is already added
	
	if ($raidloot[$cat][$index]["users"][$sender]) {
		$msg = "You are already assigned to this roll.";
		$chatBot->send($msg, $sender);
		return;
	}
	
	//Add the player to the choosen slot
    $raidloot[$cat][$index]["users"][$sender] = true;
	
    $msg = "You have been assigned to the roll of <highlight>\"{$raidloot[$cat][$index]["name"]}\"<end>.";
	$chatBot->send($msg, $sender);
	
	$msg = "<highlight>$sender<end> has been added for this roll.";
	$chatBot->send($msg, 'priv');
} else if (preg_match("/^add ([0-9]+)$/i", $message, $arr)) {
  	$slot = $arr[1];
  	$found = false;
  	//Raid with flatrolls
	if ($chatBot->vars["raid_status"] != "" && $chatBot->vars["raid_pts"] == 0) {
  	  	$slot = $arr[1];
		
		if (!isset($raidlist[$sender])) {
			$msg = "You need to be on the raidlist to be able to add to an item!";
			$chatBot->send($msg, $sender);
			return;		
		}
	
		//Check if the slot exists
		$found = false;
		forEach ($raidloot as $key => $value) {
			forEach ($value as $key1 => $value1) {
				if ($key1 == $slot) {
					$found = true;
					$cat = $key;
					$index = $key1;
					break;
				}
			}
			if ($found) {
				break;
			}
		}
		
	  	if (!$found) {
	  		$msg = "The slot you trying to add in doesn't exist!";
		  	$chatBot->send($msg, $sender);
		  	return;
	  	}
	
		//Check if minlvl is set and if the player is higher then it
		if (isset($raidloot[$cat][$index]["minlvl"])) {
		  	$whois = Player::get_by_name($sender);
		  	if ($whois === null || $whois->level < $raidloot[$cat][$index]["minlvl"]) {
			    $msg = "You need to be at least lvl<highlight>{$raidloot[$cat][$index]["minlvl"]}<end> to join this roll.";
		  		$chatBot->send($msg, $sender);
		  		return;
			}
		}
	  	
	  	//Remove the player from other slots if set
	  	$found = false;
	  	forEach ($raidloot as $key => $value) {
	  		forEach ($value as $key1 => $value1) {
				if ($raidloot[$key][$key1]["users"][$sender] == true) {
					unset($raidloot[$key][$key1]["users"][$sender]);
					$found = true;
					break;
				}		 		
			}
			if ($found) {
				break;
			}
		}
		
		//Add the player to the choosen slot
	    $raidloot[$cat][$index]["users"][$sender] = true;
	
	    if ($found == false) {
		    $msg = "$sender has added to <highlight>\"{$raidloot[$cat][$index]["name"]}\"<end>.";
		} else {
			$msg = "$sender has moved to <highlight>\"{$raidloot[$cat][$index]["name"]}\"<end>.";
		}
		
	  	$chatBot->send($msg, 'priv');
	} else if (count($loot) > 0) {
  	  	$slot = $arr[1];

		//Check if the slot exists
	  	if (!isset($loot[$slot])) {
	  		$msg = "The slot you trying to add in doesn't exist.";
		  	$chatBot->send($msg, $sender);
		  	return;
	  	}
	
		//Check if minlvl is set and if the player is higher then it
		if (isset($loot[$slot]["minlvl"])) {
		  	$whois = Player::get_by_name($sender);
		  	if ($whois === null || $whois->lvl < $loot[$slot]["minlvl"]) {
			    $msg = "You need to be at least lvl<highlight>{$loot[$slot]["minlvl"]}<end> to join this roll.";
		  		$chatBot->send($msg, $sender);
		  		return;
			}
		}
	  	
	  	//Remove the player from other slots if set
	  	$found = false;
		forEach ($loot as $key => $item) {
			if ($loot[$key]["users"][$sender] == true) {
				unset($loot[$key]["users"][$sender]);
				$found = true;
			}
		}
	
		//Add the player to the choosen slot
	    $loot[$slot]["users"][$sender] = true;
	
	    if ($found == false) {
		    $msg = "$sender has added to <highlight>\"{$loot[$slot]["name"]}\"<end>.";
		} else {
			$msg = "$sender has moved to <highlight>\"{$loot[$slot]["name"]}\"<end>.";
		}
		
	  	$chatBot->send($msg, 'priv');
	} else {
		$chatBot->send("No list available where you can add in.", $sender);
	}
} else {
	$syntax_error = true;
}

?>


thanks for the help!
Topic archived. No new replies allowed.