The online racing simulator
Help with Clicking buttons in C#
Hello
i need help with a clicking button system
i have to create a few buttons the proplem is [ No Action ]

Here my code

BANK EXAMPLE

// City Bank
int BankDist = ((int)Math.Sqrt(Math.Pow(MCI.Info[i].X - (296 * 196608), 2) + Math.Pow(MCI.Info[i].Y - (-331 * 196608), 2)) / 65536);
if (BankDist < 4 && (MCI.Info[i].Speed / 147) <= 3)
{
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].InBank == 0)
{
MCI_Update(MCI.Info[i].PLID);
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].InBank = 1;

[COLOR=Red] InSim.Send_BTN_CreateButton("", Flags.ButtonStyles.ISB_DARK, 40, 40, 25, 80, 210, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^6Welcome to the ^7Bank", Flags.ButtonStyles.ISB_DARK, 8, 40, 25, 80, 211, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^6!insert: ^7[ AMOUNT ]", Flags.ButtonStyles.ISB_CLICK, 5, 40, 35, 80, 213, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^6!balance", Flags.ButtonStyles.ISB_CLICK, 5, 40, 40, 80, 212, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^6!withdraw: ^7 [ AMOUNT ]", Flags.ButtonStyles.ISB_CLICK, 5, 40, 45, 80, 214, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^6!bankbonus", Flags.ButtonStyles.ISB_CLICK, 5, 40, 50, 80, 215, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);[/COLOR]

}

}
else if (BankDist > 14)
{
MCI_Update(MCI.Info[i].PLID);
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].InBank = 0;
[COLOR=Red]InSim.Send_BFN_DeleteButton(0, 210, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 211, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 212, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 213, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 214, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID);
InSim.Send_BFN_DeleteButton(0, 215, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID);
[/COLOR]
}

Can everywher tell me
how to make a button clickable

z.b the button [Insert amount] and when i click this button i have insert the amount in to the bank.....


Sry for my bad english

Regard

Seidel
Read about BTT and BTC packets in %LFSFOLDER%/docs/InSim.txt
i cant find anything..... whats me help.....
From the insim text file.
Quote :
// BUTTONS
// =======

// You can make up to 240 buttons appear on the host or guests (ID = 0 to 239).
// You should set the ISF_LOCAL flag (in IS_ISI) if your program is not a host control
// system, to make sure your buttons do not conflict with any buttons sent by the host.

// LFS can display normal buttons in these four screens :

// - main entry screen
// - game setup screen
// - in game
// - SHIFT+U mode

// The recommended area for most buttons is defined by :

#define IS_X_MIN 0
#define IS_X_MAX 110

#define IS_Y_MIN 30
#define IS_Y_MAX 170

// If you draw buttons in this area, the area will be kept clear to
// avoid overlapping LFS buttons with your InSim program's buttons.
// Buttons outside that area will not have a space kept clear.
// You can also make buttons visible in all screens - see below.

// To delete one button or clear all buttons, send this packet :

struct IS_BFN // Button FunctioN - delete buttons / receive button requests
{
byte Size; // 8
byte Type; // ISP_BFN
byte ReqI; // 0
byte SubT; // subtype, from BFN_ enumeration (see below)

byte UCID; // connection to send to or from (0 = local / 255 = all)
byte ClickID; // ID of button to delete (if SubT is BFN_DEL_BTN)
byte Inst; // used internally by InSim
byte Sp3;
};

enum // the fourth byte of IS_BFN packets is one of these
{
BFN_DEL_BTN, // 0 - instruction : delete one button (must set ClickID)
BFN_CLEAR, // 1 - instruction : clear all buttons made by this insim instance
BFN_USER_CLEAR, // 2 - info : user cleared this insim instance's buttons
BFN_REQUEST, // 3 - user request : SHIFT+B or SHIFT+I - request for buttons
};

// NOTE : BFN_REQUEST allows the user to bring up buttons with SHIFT+B or SHIFT+I

// SHIFT+I clears all host buttons if any - or sends a BFN_REQUEST to host instances
// SHIFT+B is the same but for local buttons and local instances

// To send a button to LFS, send this variable sized packet

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
};

// ClickID byte : this value is returned in IS_BTC and IS_BTT packets.

// Host buttons and local buttons are stored separately, so there is no chance of a conflict between
// a host control system and a local system (although the buttons could overlap on screen).

// Programmers of local InSim programs may wish to consider using a configurable button range and
// possibly screen position, in case their users will use more than one local InSim program at once.

// TypeIn byte : if set, the user can click this button to type in text.

// Lowest 7 bits are the maximum number of characters to type in (0 to 95)
// Highest bit (128) can be set to initialise dialog with the button's text

// On clicking the button, a text entry dialog will be opened, allowing the specified number of
// characters to be typed in. The caption on the text entry dialog is optionally customisable using
// Text in the IS_BTN packet. If the first character of IS_BTN's Text field is zero, LFS will read
// the caption up to the second zero. The visible button text then follows that second zero.

// Text : 0-65-66-0 would display button text "AB" and no caption

// Text : 0-65-66-67-0-68-69-70-71-0-0-0 would display button text "DEFG" and caption "ABC"

// Inst byte : mainly used internally by InSim but also provides some extra user flags

#define INST_ALWAYS_ON 128 // if this bit is set the button is visible in all screens

// NOTE : You should not use INST_ALWAYS_ON for most buttons. This is a special flag for buttons
// that really must be on in all screens (including the garage and options screens). You will
// probably need to confine these buttons to the top or bottom edge of the screen, to avoid
// overwriting LFS buttons. Most buttons should be defined without this flag, and positioned
// in the recommended area so LFS can keep a space clear in the main screens.

// 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 (defaultale blue)
// colour 7 : unavailable (default:grey)

// NOTE : If width or height are zero, this would normally be an invalid button. But in that case if
// there is an existing button with the same ClickID, all the packet contents are ignored except the
// Text field. This can be useful for updating the text in a button without knowing its position.
// For example, you might reply to an IS_BTT using an IS_BTN with zero W and H to update the text.

// Replies : If the user clicks on a clickable button, this packet will be sent :

struct IS_BTC // BuTton Click - sent back when user clicks a button
{
byte Size; // 8
byte Type; // ISP_BTC
byte ReqI; // ReqI as received in the IS_BTN
byte UCID; // connection that clicked the button (zero if local)

byte ClickID; // button identifier originally sent in IS_BTN
byte Inst; // used internally by InSim
byte CFlags; // button click flags - see below
byte Sp3;
};


// CFlags byte : click flags

#define ISB_LMB 1 // left click
#define ISB_RMB 2 // right click
#define ISB_CTRL 4 // ctrl + click
#define ISB_SHIFT 8 // shift + click

// If the TypeIn byte is set in IS_BTN the user can type text into the button
// In that case no IS_BTC is sent - an IS_BTT is sent when the user presses ENTER

struct IS_BTT // BuTton Type - sent back when user types into a text entry button
{
byte Size; // 104
byte Type; // ISP_BTT
byte ReqI; // ReqI as received in the IS_BTN
byte UCID; // connection that typed into the button (zero if local)

byte ClickID; // button identifier originally sent in IS_BTN
byte Inst; // used internally by InSim
byte TypeIn; // from original button specification
byte Sp3;

char Text[96]; // typed text, zero to TypeIn specified in IS_BTN
};


ah.... ok thanx i test it......
woOps......
sry for my begging
and my bad english......

i have test it to code but i cant i understand its.....
i want to ask.......

Can everywhere please code me an Exsample

Like this
I have a job button
when i press it than i accept a job.....



Regards

Seidel
Are you listening for the button click event? If not, do so. Then compare the button id to something and take the appropriate action.



-
(MariusMM) DELETED by MariusMM : History
!!! Thanx !!!


WOW you good !

Very very thanx !!!!
ya thats working but my problem is now i dont need NCN
i need this code for a
InSim.Send_BTN_CreateButton("^6!job: ^7Delivery a Pizza", Flags.ButtonStyles.ISB_LEFT, 5, 40, 50, 80, 225, [COLOR=Red]Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 40, true);[/COLOR]

STOOOOOPPPPPPP !!!!!!


I have all !!
its now working !!!!


i have to edit my ID xD

Very Thanx !
ya its working nice ...... only on my computer ??????
why isnt this working on a host ? here my code

Why my host ?

^7host ^7: ^8!job
^7host ^7: ^8!beer
^7host ^7: ^8!pizza
^7host ^7: ^8!donuts

case 200:
InSim.Send_MST_Message("!job");
break;

case 222:
InSim.Send_MST_Message("!donuts");
break;

case 223:
InSim.Send_MST_Message("!pizza");
break;

case 224:
InSim.Send_MST_Message("!beer");
break;
The very simple question here would be: Do you even see enough space on the dedi window to display buttons? I don't..

Unless the host is you, you will get no buttons on the server side.
i have found me fail very thanx

i have used the wrong codes.......
what are the right codes i have the same problem lol
Quote from shane2k7 :what are the right codes i have the same problem lol

Read the whole thread.
Quote from Bremskiller18akaHeinz :ya its working nice ...... only on my computer ??????
why isnt this working on a host ? here my code

Why my host ?

^7host ^7: ^8!job
^7host ^7: ^8!beer
^7host ^7: ^8!pizza
^7host ^7: ^8!donuts

case 200:
InSim.Send_MST_Message("!job");
break;

case 222:
InSim.Send_MST_Message("!donuts");
break;

case 223:
InSim.Send_MST_Message("!pizza");
break;

case 224:
InSim.Send_MST_Message("!beer");
break;

I know this is a old thread to bump it but here is my help

for example:
case 224:
if (Connections[GetConnIdx(BTT.UCID)].InShop == 1)
{
if (Connections[GetConnIdx(BTT.UCID)].Health <= 94)
{
Connections[GetConnIdx(BTT.UCID)].Cash -= 5;
Connections[GetConnIdx(BTT.UCID)].Health += 5;
InSim.Send_MTC_MessageToConnection("^6>^7 " + Connections[GetConnIdx(BTT.UCID)].PlayerName + " ^7 bought a ^1beer", BTT.UCID, 0);
}
else if (Connections[GetConnIdx(BTT.UCID)].Health >= 94 && Connections[GetConnIdx(BTT.UCID)].InShop == 1)
{
InSim.Send_MTC_MessageToConnection("^7Your energy is too high to buy more beer!", (BTT.UCID), 0);
}
}
break;

Take note that Send_MST_Message is a essentials from your dedi
ABOUT CASE: just remove them on the commands list like "!beer" and put it in case 224: as a Button Click

FGED GREDG RDFGDR GSFDG