[Help] Can i make this shorter?

07/08/2009 10:32 nuhali#1
Can any help me with the cps command

Quote:
case "cps":
{
if (Command.Length == 2 && CSocket.Client.isPM || CSocket.Client.isGM)
{
int Cps = Convert.ToInt32(Command[1]);
CSocket.Client.CPs += Cps;
CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You now have " + CSocket.Client.CPs + " CPs.", Struct.ChatType.Top));
CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CPs, Struct.StatusTypes.InvCPoints));
}
break;
}

How can i send cps to every registered users
07/08/2009 11:54 yuko#2
not sure about what you meant with every registered user.
a registered user or each char in the database or each char connected on the server.

the code below should work for each char in nano.clientspool
Code:
						
case "cps":
							{
								if(Command.Length == 2 && CSocket.Client.isPM || CSocket.Client.isGM)
								{
                                    [COLOR="Red"]foreach (KeyValuePair<int, ClientSocket> Clients in Nano.ClientPool)[/COLOR]
                                    {
                                        int Cps = Convert.ToInt32(Command[1]);
                                        Clients.Value.Client.CPs += Cps;
                                        Clients.Value.Send(ConquerPacket.Chat(0, "SYSTEM", Clients.Value.Client.Name, "You now have " + Clients.Value.Client.CPs + " CPs.", Struct.ChatType.Top));
                                        Clients.Value.Send(ConquerPacket.Status(Clients.Value, 2, Clients.Value.Client.CPs, Struct.StatusTypes.InvCPoints));
                                    }
								}
								break;
							}
if you want it for each char in the database you'll be better of with a little php else you'll have to select all chars in the source first which would be useless.
07/08/2009 11:56 habbo245#3
Thanks for comprehensio
07/08/2009 12:46 nuhali#4
how can i make a timer that reset every day your cps to 1 cps
07/08/2009 13:20 nuhali#5
Quote:
Originally Posted by yuko View Post
not sure about what you meant with every registered user.
a registered user or each char in the database or each char connected on the server.

the code below should work for each char in nano.clientspool
Code:
						
case "cps":
							{
								if(Command.Length == 2 && CSocket.Client.isPM || CSocket.Client.isGM)
								{
                                    [COLOR="Red"]foreach (KeyValuePair<int, ClientSocket> Clients in Nano.ClientPool)[/COLOR]
                                    {
                                        int Cps = Convert.ToInt32(Command[1]);
                                        Clients.Value.Client.CPs += Cps;
                                        Clients.Value.Send(ConquerPacket.Chat(0, "SYSTEM", Clients.Value.Client.Name, "You now have " + Clients.Value.Client.CPs + " CPs.", Struct.ChatType.Top));
                                        Clients.Value.Send(ConquerPacket.Status(Clients.Value, 2, Clients.Value.Client.CPs, Struct.StatusTypes.InvCPoints));
                                    }
								}
								break;
							}
if you want it for each char in the database you'll be better of with a little php else you'll have to select all chars in the source first which would be useless.

I need for all char in databse ofline or online
07/09/2009 02:50 kinshi88#6
Quote:
Originally Posted by nuhali View Post
I need for all char in databse ofline or online
Command: (Gives it to all online players)
Code:
                        case "cps":
                            {
                                if (CSocket.Client.isGM || CSocket.Client.isPM)
                                {
                                    foreach (ClientSocket OSocket in Nano.ClientPool.Values)
                                    {
                                        OSocket.Client.CPs += Convert.ToInt32(Command[1]);
                                        OSocket.Send(ConquerPacket.Status(OSocket, 2, OSocket.Client.CPs, Struct.StatusTypes.InvCPoints));
                                        OSocket.Send(ConquerPacket.Chat(0, "SYSTEM", OSocket.Client.Name, "You gianed " + Command[1] + " CPs from " + CSocket.Client.Name + "!", Struct.ChatType.Center));
                                    }
                                    Database.Database.GiveCPs2All(CSocket, Convert.ToInt32(Command[1]));
                                }
                                break;
                            }
Database: (Gives it to all offline Players)
Code:
        public static void GiveCPs2All(ClientSocket CSocket, int Amount)
        {
            MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `characters`", DatabaseConnection.NewConnection());
            MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                if (!Nano.ClientPool.ContainsKey(Convert.ToInt32(DR["CharID"])))
                {
                    int Cps = Convert.ToInt32(DR["CPoints"]) + Amount;
                    MySqlCommand Cmd2 = new MySqlCommand("UPDATE `characters` SET `CPoints` = " + Cps + " WHERE `CharID` = " + CSocket.Client.ID + "", DatabaseConnection.NewConnection());
                    Cmd2.ExecuteNonQuery();
                    Cmd2.Connection.Close();
                    Cmd2.Connection.Dispose();
                    Cmd2.Dispose();
                }
            }
        }
07/09/2009 16:26 nuhali#7
tnx
07/10/2009 02:59 kinshi88#8
Quote:
Originally Posted by nuhali View Post
tnx
Press Thanks, don't just say it.

P.s.
I noticed an error in the Database code, I'm sure you can figure it out tho.
07/10/2009 10:44 nuhali#9
kinshi i need help again

how can i make if i you kill a player in map 1000 you get cps