The online racing simulator
police thing.
On most cruise servers i've been on when a cop is in a chase a flashing word appears in the middle of the screen how is this done?

could it be done by putting a button there?

(i am very new to the coding but i can always work things out by reading just rock solid code for a few minutes like i already worked out how to do the km count and speed count - my next tasks are to add colours in speed and to make buy zones with energy)

thanks.
just one thing... i'm not asking for the code. i'm only asking for methods it could be done with.
just incase you were woundering
Yes, the best way is to use buttons for that. RCM messages are no good because they conflict with each other, but transparent buttons are ok.

If you are using a time-based library (I think LFS External is one of these), you must create and send an IS_BTN button, then after one second you clear it with an IS_BFN, then after one second you send the same button (no need to create it again), and so on. All this controlled by a var that tells the application when to stop this sending/clearing button thing.

If you are not using a timed library, you should use some other way, like a separate thread that controls all the button thing using a function like "sleep()".
thanks for the help! i'll see what i can do.
A little more help/tips on this topic This is only helpful if you haven't worked with manipulating button aspect properties before:

This is the structure of button packets:
struct IS_BTN // BuTtoN - button header - followed by 0 to 240 characters
{
byte Size; // 12 + TEXT_SIZE (a multiple of 4)
byte Type; // ISP_BTN
byte ReqI; // non-zero (returned in IS_BTC and IS_BTT packets)
byte UCID; // connection to display the button (0 = local / 255 = all)

byte ClickID; // button ID (0 to 239)
byte Inst; // some extra flags - see below
byte BStyle; // button style flags - see below
byte TypeIn; // max chars to type in - see below

byte L; // left : 0 - 200
byte T; // top : 0 - 200
byte W; // width : 0 - 200
byte H; // height : 0 - 200

// char Text[TEXT_SIZE]; // 0 to 240 characters of text
};


// BStyle byte : style flags for the button

#define ISB_C1 1 // you can choose a standard
#define ISB_C2 2 // interface colour using
#define ISB_C4 4 // these 3 lowest bits - see below
#define ISB_CLICK 8 // click this button to send IS_BTC
#define ISB_LIGHT 16 // light button
#define ISB_DARK 32 // dark button
#define ISB_LEFT 64 // align text to left
#define ISB_RIGHT 128 // align text to right

// colour 0 : light grey (not user editable)
// colour 1 : title colour (default:yellow)
// colour 2 : unselected text (default:black)
// colour 3 : selected text (default:white)
// colour 4 : ok (default:green)
// colour 5 : cancel (default:red)
// colour 6 : text string (default:pale blue)
// colour 7 : unavailable (default:grey)

Take a look at filed "BStyle". If you don't set it to any of ISB_DARK or ISB_LIGHT then the button will be transparent, so only the text will show.

You can have coloured text in two ways. One is using LFS colour tags wihtin the text. For example: "^1POLICE! STOP". If you want to have that message in red.

The other one is using BStyle field. For red you would use ISB_C1 + ISB_C4.

The difference is that default button colors defined with BStyle field are darker/lighter than the ones you get using color tags. The red color tag would give a very bright red, while BStyle defined red is darker red, tending to brown. Something like this:

Color tag: POLICE! STOP
BStyle: POLICE! STOP
hmm... upon testing, this is my code on the '!engage' command currently

InSim.Send_BTN_CreateButton("^7Police, Pull Over!", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK, 6, 31, 25, 15, 142, MSO.UCID, 40, false);

how can i make it show to every one? or maybe even the person they're chasing - that probably won't work atm coz i'll need ot edit it to go after a specific driver.
Quote from joe9380 :hmm... upon testing, this is my code on the '!engage' command currently

InSim.Send_BTN_CreateButton("^7Police, Pull Over!", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK, 6, 31, 25, 15, 142, [B]MSO.UCID[/B], 40, false);

how can i make it show to every one? or maybe even the person they're chasing - that probably won't work atm coz i'll need ot edit it to go after a specific driver.

The button shouldn't be shown to everyone, but just the guy that is being chased. If no one is chasing me I don't have to have a text telling me "police, pull over".

You must know the UCID of the driver that is being chased to send the button only to that specific driver. The way to know this UCID depends on how you trigger the persecution.

Another tip. If you want the text to appear in the center of the screen then don't use ISB_LEFT. Don't use neither left or tright alignment, and the text will be centered within the button. Then you just have to make the appropiate maths. Max width is 200, so left-place the button at "(200 - button_width) / 2"
i'm stuck on the code to actually send the button :s

atm i have this which definatly dosn't work :s

InSim.Send_MS_CreateButton("^7Police, Pull Over! " + Connections[GetConnIdx(MSO.UCID)].ChaseeUsername + "^7!");

oh wait.. i see whats wrong with that..
thats mentionioning the person inside the button. how can i mention him outside of the button, i do want to keep him in there though. ;D
How can i make a button goto the specific chasee?

this will probably help (case "!engage"

case "!engage":
if (StrMsg.Length == 1)
{
if (Connections[GetConnIdx(MSO.UCID)].IsOfficerORCadet != 0)
{
if (Connections[GetConnIdx(MSO.UCID)].ChaseCondition == 0)
{
ChaseInitiated = 1;
ChaserUCID = MSO.UCID;
}
if (Connections[GetConnIdx(MSO.UCID)].ChaseCondition == 4)
{
Connections[GetConnIdx(MSO.UCID)].ChaseCondition = 5;
BumpCondition = 1;
BumpUCID = MSO.UCID;

}
if (Connections[GetConnIdx(MSO.UCID)].ChaseCondition == 3)
{
Connections[GetConnIdx(MSO.UCID)].ChaseCondition = 4;
BumpCondition = 1;
BumpUCID = MSO.UCID;

}
if (Connections[GetConnIdx(MSO.UCID)].ChaseCondition == 2)
{
Connections[GetConnIdx(MSO.UCID)].ChaseCondition = 3;
BumpCondition = 1;
BumpUCID = MSO.UCID;

}
if (Connections[GetConnIdx(MSO.UCID)].ChaseCondition == 1)
{
Connections[GetConnIdx(MSO.UCID)].ChaseCondition = 2;
BumpCondition = 1;
BumpUCID = MSO.UCID;
}


}
else
{
InSim.Send_MTC_MessageToConnection("^1Not Authorised", MSO.UCID, 0);
}
}
else
{
InSim.Send_MTC_MessageToConnection("^6|^7 Invalid command. Please see ^2!help^7 for a command list", MSO.UCID, 0);
}
break;

You are pretending that sending the command "!engage" by a cop then a chase starts, don't you? In that case YOU must decide how you are going to decide who to chase.

There are some possibilities. One is "!engage user_name", thinking that you have in some kind of structured the players mapped, so you correlate the username to its UCID.

Another possibility is to check how far are all drivers respect to the cop that typed "!engage", and select the closest one. I haven't worked with MCI and NLP packets yet, but you have the exact coordenates of each car by requesting IS_MCI packets sending a request via an IS_TINY. Then you compare the coordinates of all cars with the one that typed "!engage" and select the PLID of the one that is closest, and from then you get the matching UCID.

There's high probability that you are already receiving IS_MCI packets on a fixed interval, so there'd be no need to use an IS_TINY to request.

How do you like this solution? It might look complex, but it lets you assign "!engage" to one function key so you don't have to care about who you are going to chase. You just have to make sure that the closest car to yous is the one you want to chase

PS: I'm not into cruising servers and I'm not a good InSim programmer myself yet, so it'd be good if someone who has already done these things could help you too.
He's using the open source mod, so it's going on the distance one.

InSim.Send_BTN_CreateButton("^7Police, Pull Over!", Flags.ButtonStyles.ISB_C1, 6, 31, 25, 15, 142, MSO.UCID, 40, false);

Would send a transparent button, but you'll have to adjust location and size yourself. As for the UCID, if you are sending from the MCI method, you can "convert" the PLID to UCID, like so:

Players[GetPlyIdx(MCI.Info[index].PLID)].UniqueID

To send it to everyone, replace MSO.UCID with 255.
A small tip on calculating the distance to other cars:

You have 3 coordinates for each car: X, Y, Z. If you are good with geometry you can get the formula to calculate the distance between two points using 3 coordenates. But, in this context that is just a waste of processing time and power.

First of all, you can totally forget about the Z component. Surface is not totally plain, but comparing car's relative positions you would notice that the difference in heigth is irrelevant here, and most of all when you are looking for a car that should be close to you (therefore the heigth would be very close). Now you only have to compare positions using two coordenates, which simplifies the whole thing a lot (in terms of arithmetic operations needed).

With two coordenates you only need to apply the Pythagoras' theorem. But we can simplify it even more:

Car1 pos:
x1,y1

Car2 pos:
x2,y2

distance_in_meters = square_root ( (x1-x2)^2 + (y1-y2)^2 ) / 65536

This would give us the distance in meters (because of the "/65536")

But in our case we don't care about the actual distance in meters or any other measure unit. The only thing we want to know is "the closest car", not "how far is each car". So first of all we get rid of the "/65536". And then we change:

lfs_distance^2 = (x1-x2)^2 + (y1-y2)^2

We calculate "lfs_distance^2", and that's what we are going to compare. This way we don't need to calculate square roots or convert anything to meters.

The only thing you need to take care is not to cause an overflow here. For this you should choose the appropiate data types, and maybe divide the original x1,y1,x2,y2 by some factor like 2^17 to prevent getting too high. This would cause you to lose precission (precission this way would be 2 meters in each X and Y coordenate), but you won't be needing much precission.
That's already in the cruise mod, it stores the difference between every player and every cop as-is

FGED GREDG RDFGDR GSFDG