The online racing simulator
command call911
Hello,
Yesterday, i created a command for people in lfs can request help in my insim, doing !call911
but when i tested my command he don´t found cadet´s online. What is the problem?
And i want that the request go to cadet´s and officer´s. Can you help me?
The command is the next:

[Command("call911", "call911")]
public void callpolice(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
clsConnection Conn = Connections[GetConnIdx(MSO.UCID)];
if (StrMsg.Length > 0)
{
int FoundCadet = 0;
foreach (clsConnection C in Connections)
{
if (Conn.IsCadet == 1)
{
FoundCadet = 1;
InSim.Send_MTC_MessageToConnection("^1-^7 Please wait for awhile your Call is Accepted!", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^1-^7 Calling for Police Request: ", C.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^1-^7 Name: " + Conn.PlayerName, C.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^1-^7 Located: " + Conn.Location, C.UniqueID, 0);
C.PoliceUsername = Conn.Username;
Conn.PoliceUsername = 1;
}
}
if (Conn.IsCadet == 0)
{
InSim.Send_MTC_MessageToConnection("^1»^7 There are no Polices Online :(", MSO.UCID, 0);
}
}
else
{
InSim.Send_MTC_MessageToConnection("^1»^7 Invalid command. See ^2!help^7 for a command list", MSO.UCID, 0);
}
}

Thanks for all help, and have a good day.
You did not created. I sended it to you.

1 - You strealing my code.

No one, will help you.
Quote from impresora :You did not created. I sended it to you.

1 - You strealing my code.

No one, will help you.

Is your? where?
Yep, it is mine. Do you see anyone helping you ??? No ??? That's because u ' re a lier and a robber.
Oh here we go again. This is why Open Sourcing your code makes sure you get the kudos.
Quote from Dygear :Oh here we go again. This is why Open Sourcing your code makes sure you get the kudos.

Ye... But he just copy codes don't worry.
This is the kind of debugging you really have to do yourself. I'd start with listing the contents of Connections collection to see if the IsCadet flag is set correctly.

Quote from impresora :You did not created. I sended it to you.

1 - You strealing my code.

Am I the only one who sees the contradiction here?
Quote from MadCatX :Am I the only one who sees the contradiction here?

^^ Your stolen mine words, right out of mine mouth.


I am looking at the code (copied it to note pad as its easier to read) and I don't see a mistake in that specific snippet, someone may see something I don't. So I will ask a silly question because of my experiences. Are you 100% sure that you put a cadet on duty? You could make a !command to tell you how many cadets are connected, this may help you solve the problem


A small example, just an example, may not be 100% correct...

[Command("howmanycadets", "howmanycadets")]
public void howmanycadets(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
int FoundCadet = 0;
foreach (clsConnection C in Connections)
{
if (Conn.IsCadet == 1)
{
FoundCadet = 1;
}
}
InSim.Send_MTC_MessageToConnection("There are " + FoundCadet + " Online", MSO.UCID, 0);
}

Sorry, I stole your code and edited it to make the example
Quote from Psysim :
A small example, just an example, may not be 100% correct...

Not to nitpick but that doesn't actually tell you a number of cadets does it? :P
Your correct, it just shows that a cadet is online, I half knew someone would of seen that. It's also a good example of how coping can be the cause of the issue in the first place, and well spotted


As hyntty pointed out... change "FoundCadet = 1;" to "FoundCadet += 1;" for a count, or leave it as it is if you just want to confirm that a cadet is on-duty
Quote from Psysim :Your correct

And let that be a remind us of the importance of syntax in a language...
-
(MariusMM) DELETED by MariusMM
Quote from MariusMM :If I have not misunderstood, it should be

Not really unless you want to call every single police officer there is and to print out "No policies found" for every player that is online and isn't an officer...

This is a very backwards approach to a problem that shouldn't even exist guys. There's absolutely no reason to do that kind of a loop every time someone wants to call the police just to find out if any are present: Wouldn't it be smarter to set a global variable indicating the amount of officers present that changes whenever an officer joins or leaves the server? (And it would also use less cpu cycles :P)

Also I reckon if you used an if-else structure when there's such a clear 2-option screnario the code would be nicer to the eye. Or if there are multiple choises use a switch case statement, putting multiple if-clauses one after another might be confusing to read afterwards.
This is an interesting "get it right" contest, I'd use something like this to debug


public void callpolice(string Msg, string[] StrMsg, Packets.IS_MSO MSO) {
clsConnection Conn = Connections[GetConnIdx(MSO.UCID)];
if (StrMsg.Length > 0) {
bool FoundCadet = false;
foreach (clsConnection C in Connections) {
if (Conn.IsCadet == 1) {
FoundCadet = true;
InSim.Send_MTC_MessageToConnection("^1-^7 Please wait for awhile your Call is Accepted!", MSO.UCID, 0);
C.PoliceUsername = Conn.Username;
Conn.PoliceUsername = 1;
} else {
InSim.Send_MTC_MessageToConnection("^1»^7 Connection" + C.UniqueID + " is not a cadet.", MSO.UCID, 0);
}
} else {
InSim.Send_MTC_MessageToConnection("^1»^7 Invalid command. See ^2!help^7 for a command list", MSO.UCID, 0);
}
}
}


<?php 
      
foreach (clsConnection C in Connections) {
         if (
Conn.IsCadet == 1) {
            
FoundCadet true;
            
InSim.Send_MTC_MessageToConnection("^1-^7 Please wait for awhile your Call is Accepted!"MSO.UCID0);
            
C.PoliceUsername Conn.Username;
            
Conn.PoliceUsername 1;
         } else { 
// This would result in spam?
            
InSim.Send_MTC_MessageToConnection("^1»^7 Connection" C.UniqueID " is not a cadet."MSO.UCID0);
         }

?>

Nice, but do you want to tell the connection user by user, who is not a cadet?

EDIT: forget that, I see why you suggest it
-
(MariusMM) DELETED by MariusMM
Hello and thanks for all help.
the code is mine and not of the impresora so do not worry,
I wish that when people do! call911 a message appear on the cadet's or officer's, and if there were no police appear a warning message.

Sorry for my bad english.
I suggest you keep track of cadets and officers in a separate list. Then when you receive the 911-command you would do something like:


<?php 
clsConnection Conn 
Connections[GetConnIdx(MSO.UCID)];

if ( 
ListOfOfficersAndCadets.isEmpty() ) {  // Somehow figure out if it is empty or not. I'm sure C# has some smart data structures to do the work for you.
    
InSim.Send_MTC_MessageToConnection("There are no officers or cadets"MSO.UCID0);
    }
else {
    
InSim.Send_MTC_MessageToConnection("^1-^7 Please wait for awhile your Call is Accepted!"MSO.UCID0);
    foreach( 
clsConnection C in ListOfOfficersAndCadets ) {
        
InSim.Send_MTC_MessageToConnection(Conn.Name " called teh rozzers!"C.UCID0); // I've no idea what a clsConnection has or hasn't got for attributes but I suppose it should have a user id and a player name at least?
        
        
}
    }

?>

(Note that I know jack shit about C# and this isn't a working piece of code.)

This is the general idea how I would do it. It may or may not be the smartest way but we'll see if others take part in the 'get it right' competition.
LOOOL ok ok so make another code in my front XD You are like speedboy ! You just copy and PASTE codes xD

FGED GREDG RDFGDR GSFDG