The online racing simulator
Click Button Only Works For One Player?
hi guys i have a new problem i've made a few menus on my server for shops and for some reason when any player other than the first player that joined clicks one of the buttons they do nothing, where as the first player that joins has all the buttons working perfectly.

my code is :



private void BTC_ButtonClicked(Packets.IS_BTC BTC)
{
try
{

switch (BTC.ClickID)
{


case 186: // Close Button

if (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].InShop == 1) // Close Pizza
{
// Shop Menu
InSim.Send_BFN_DeleteButton(0, 176, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
// Shop Name
InSim.Send_BFN_DeleteButton(0, 177, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
// Shop Items
InSim.Send_BFN_DeleteButton(0, 178, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 179, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 180, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 181, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 182, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 183, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 184, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 185, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
// Click buttons
InSim.Send_BFN_DeleteButton(0, 186, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Close
InSim.Send_BFN_DeleteButton(0, 187, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 1
InSim.Send_BFN_DeleteButton(0, 188, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 2
InSim.Send_BFN_DeleteButton(0, 189, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 3
InSim.Send_BFN_DeleteButton(0, 190, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 4
InSim.Send_BFN_DeleteButton(0, 191, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 5
InSim.Send_BFN_DeleteButton(0, 192, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 6
InSim.Send_BFN_DeleteButton(0, 193, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 7

}
if (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].InLotto == 1) // Close Lotto
{
// Shop Menu
InSim.Send_BFN_DeleteButton(0, 176, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
// Shop Name
InSim.Send_BFN_DeleteButton(0, 177, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
// Shop Items
InSim.Send_BFN_DeleteButton(0, 178, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 179, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 180, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 181, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 182, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 183, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 184, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 185, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);
// Click buttons
InSim.Send_BFN_DeleteButton(0, 186, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Close
InSim.Send_BFN_DeleteButton(0, 187, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 1
InSim.Send_BFN_DeleteButton(0, 188, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 2
InSim.Send_BFN_DeleteButton(0, 189, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 3
InSim.Send_BFN_DeleteButton(0, 190, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 4
InSim.Send_BFN_DeleteButton(0, 191, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 5
InSim.Send_BFN_DeleteButton(0, 192, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 6
InSim.Send_BFN_DeleteButton(0, 193, Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID);// Info 7
}

break;

case 187: // Buy Button 1

if (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].InShop == 1) // Buy Pizza
{
if (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Health <= 89)
{
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Cash -= 10;
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Health += 10;
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].TodaysCash -= 10;
InSim.Send_MTC_MessageToConnection("^1* ^3You bought a ^7Pizza", Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID, 0);
}
else
{
InSim.Send_MTC_MessageToConnection("^1* ^3Your health is too high to buy more food", (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID), 0);
}
}
if (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].InLotto == 1) // Buy Lotto Ticket
{
if (Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].InLotto == 1 && Environment.TickCount - Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].LastLotto > 1296000) //3 hours
{
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Cash -= 250;
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].TodaysCash -= 250;
int prize = new Random().Next(0, 2000);
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Prize += prize;
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Cash += Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Prize;
InSim.Send_MTC_MessageToConnection("^1* ^3You have received ^2£" + Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Prize + " ^3from Lotto", Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID, 0);
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].TodaysCash += Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].Prize;
Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].LastLotto = Environment.TickCount;
}
else if (Environment.TickCount - Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].LastLotto < 1296000)
{
InSim.Send_MTC_MessageToConnection("^1* ^3You have to wait ^73 ^3hours to buy another ticket", Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)].UniqueID, 0);
//Connections[GetConnIdx(MSO.UCID)].InLotto = 1;
}
}

break;



}
}
catch (Exception EX)
{
//MessageBox.Show("BTC - " + EX.Message);
}
}


the code is longer i just couldnt fit it all in

i dont see anything that i could have done wrong here, but like i said it only works for the first player that joined the server any ideas?
I can't tell much about it but I have an idea that the problem lies somewhere within this:

Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)]

Also, I noticed that that was copy and pasted several times throughout that code snippet, as an improvement, both for speed and readability you could do:

Connection c = Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)];

and using c.InShop, or c.UniqueID etc for the code rather than the long, and slower access of Connections[...] each time. Small improvement with speed, but a large improvement for readability. Anyways, I have a hunch that your problem would lie within the Connections[] IDs somehow, if possible.

I know this didn't really help you much, but I figured I'd give some friendly advice. (By the way, if the Connection has a UniqueID why can't it just be something like Connection c = Connections.GetConnection(BTC.UCID); or something similar, rather than searching through the player, then the players connection etc... Could that be the source of the problem? If it was my code, obviously it isn't, then GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID) would be GetConnIdx(BTC.UCID), which is what I was mentioning with my "GetConnection" method above. Anyways, good luck.
to be honest i saw that same answer in a post to do with some other query so i did try using c.blah blah but it was spamming the commands twice when i clicked the button once.

i really dont get why it doesnt work unfortantly this bug is running on my server now if you wana test it out for yourself and if you can think of any other ideas to fix this as i'm also asking quite a few other people who are all telling me there is not a problem in the code. i'm completely baffled

Server: [WKD] Cruise Server


EDIT: ok problem solved i just decided to re-write the whole lot seems to work now. no idea why it didnt before tho.
It didn't work, because of the exactly same thing blackbird said.
That is -> Connections[GetConnIdx(Players[GetPlyIdx(BTC.UCID)].UniqueID)]

It says GetPlyIdx(Get PLAYER Index, not connection, which means PLID, not UCID)

The right snippet of code for there would be (just as blackbird said again): Connections[GetConnIdx(BTC.UCID)]

And so the example he gave, would obviously look more right like this: clsConnection C = Connections[GetConnIdx(BTC.UCID)]
Saving both coding and processing time.

And after his explanation you still didn't get what's wrong... It was more than obvious if you ask me, but whatever.

FGED GREDG RDFGDR GSFDG