The online racing simulator
Adding a button
Hello, again

I've read some tutorials but i still don't quite understand how to add simplest thing Lapper....
Buttons....

In what specific file to place them, how to connect them to a certain zone?
Etc.

Some beginner advice and simple help would be much appreciated!

Thanks Smile
** Best answer **
When writing code for Lapper, you basicly have two options to put your code in:

1) Write it directly in 'LFSLapper.lpr' which can be found in folder 'bin\default'
2) Write it in a seperate file, save that file in the 'bin\default\includes' folder and mention the newly written file in 'bin\default\includes\addonsused.lpr'

The second option is the best one, as it keeps the default script clean and by adjusting file 'addonsused.lpr' you can easily turn on/off scripts you have written.

With buttons there are two options as well:

openPrivButton - this will open a button only to be seen by the player that has triggered the event

openGlobalButton - this will be seen by all players and is triggered by the first player that triggered the event.

PrivButton is mainly used to display information that is player specific, while GlobalButton is used for general information

The syntax for both buttons is the same:

1 - Unique id for this button
2 - Left coordinate for this button ( 0-200 ) , $origL = (value between 0-200); - when this value is used, every next value can be made relative to this one (example: $origL + 5; )
3 - Top coordinate for this button ( 0-200 ) , $origT = (value between 0-200); - when this value is used, every next value can be made relative to this one (example: $origT + 5; )
4 - Width of the button ( 0-200 )
5 - Heigth of the button ( 0-200 )
6 - Space between line in multiline button
7 - Duration in seconds for the button to be displayed (use -1 if you don't want an automatic close)
8 - Format of the button, look at insim.txt for values
9 - Button caption, for multiline, separate each line with &
10 - Option name of the backcalled sub

When formatting a button, these are the codes you can use:

0 - transparent button
16 - light button
32 - dark button
64 - align text to left
128 - align text to right

If you want to make a light colored button with text aligned to the left, combine the codes to one new code, for example 16+64 = 80

When a button is clicked a next routine can be started and it's possible to know which mousebutton is used to click the button with.
This can be read using the $KeyFlags value in the sub-routine and can return the following values:

// CFlags byte : click flags

1 // left click
2 // right click
4 // ctrl + click
8 // shift + click

If left click and right click, you receive 2 + 1 = 3

That are the basics of creating a button, which hopefully make some sense.
Now back to your question about displaying a button when a zone is reached.
Let's say we register a zone on the basic Blackwood track (BL1):

RegisterZoneAction( "MyZone", "BL1" , 0 , SA_Test_1, "" );

This means that as soon as a player enters zone 0, the sub-routine 'SA_Test_1' will be executed.
As you can see, there's also "" in the RegisterZoneAction, which can be used to define a sub-routine to be executed when a player leaves zone 0.

The sub-routine could look like this:


<?php 
Sub SA_Test_1 
$userName$id )
    
openPrivButton"test_button",25,28,150,10,5,-1,0,"This is a test""" );
EndSub
?>


As you can see, a PrivButton is opened and has been given the name 'test_button'.
This name is important and should be unique, because you need that name to close the button at some point and if multiple buttons have the same name, they will all close when using that name.
Value 25 means that the button is starting from position 25 seen from the left side of the screen. (the screen for buttons is a 200 by 200 square, where the top left corner has coordinate 0,0)
Value 28 means that the button is starting from position 28 seen from the top of the screen.
Value 150 means that the button has a width of 150 (since it is starting 28 from the left, the end of the button is at position 178, which is within the range of 200.
Value 10 means that the button has a height of 10 (if you want to display text on the button, then it will take a height of 5, to display one line of text, 2 lines means a height of 10 is needed, ect. etc.)
Value 5 has to do with space between a multiline button, but in most cases 5 will do.
Value -1 means that the button won't close automaticly and will be waiting for the user to click on it and then execute the sub-routine.
Value 0 means that the button will be transparent.
Value 'This is a test' is the text that will be displayed on the button.
Value "" means that no further sub-routine will be executed when the player clicks the button.

Since we haven't specified a time (we used -1) after which the button will close automaticly and since whe haven't specified a sub-routine when the player clicks the button, it will mean the player is stuck with that button until he disconnects from the server, which isn't very useful.
So either we specify a time (in seconds) to automaticly close the button, or we specify a sub-routine to be executed when the player clicks the button.

Be carefull though, when players are driving their car using the mouse as control, such button will screw up their car control for as long as such button is on their screen.

I hope this post is useful to you, but don't hesitate to ask more questions if you have any.
Thank you so much, Yisc!
I was looking for this explanation for so long now!

Hopefully other beginners can understand as well now!

Thanks again Smile
I tried to exactly do what you have said but for some reason it doesnt seem to work Frown

I created a new .lpr file in /Includes named "buttons".
I placed the name in addonused: include( "./buttons.lpr");

But still....

This is how the file looks:



<?php
Sub SA_Test_1 ( $userName, $id )
openPrivButton( "test_button",25,28,150,10,5,-1,0,"This is a test", "" );
EndSub
?>

RegisterZoneAction( "MyZone", "BL1" , 0 , SA_Test_1, "" );




I also tried to place Insim Circles in my created map with the "0 identification" but i still got no reaction.

This is probably a stupid beginner mistake...

Cloud you please explain this??
Thanks Smile

(also the welcome text doesnt show when i include the "buttons"file.)
Hello,

To enable the Zone/Node action to have you add the RegisterZoneAction/RegisterNodeAction in the 'OnLapperStart' event.

<?php 
CatchEvent OnLapperStart
()
    
#Zone/Node actions in OnLapperStart event
                        #ZoneID,Track,Node,EnterNode,LeaveNode
    
RegisterNodeAction"MyNode""BL1" SA_Test_1"" );
 
                        
#ZoneID,Track,X,Y,EnterZone,LeaveZone
    
RegisterZoneAction"MyZone""BL1" 0,100 SA_Test_1"" );
EndCatchEvent
?>


The way you called the 'SA_Test_1' sub routine is good.

To use the InsimCircles in lapper you have to use the OnCrossingChecker() event. And the $CircleIndex, which is the Index of the circle you used ingame.


<?php 
CatchEvent OnCrossingChecker
($userName,$Flags,$Time,$Object,$UserSpeed,$CircleIndex)  # Player event
   
IF($CircleIndex == 1THEN
      privmsg
("Blahblah");
   ENDIF
EndCatchEvent
?>


If something isnt working, you have to check the errorlogs first. These files are located in the 'Logs' folder (Bin/Default/Logs)
Noted!
Thanks for your Reply!
It really helps me out!
Smile
Hello

When i try the OnCrossingChecker Event the error log says: Event OnCrossingChecker do not exist in LFSLapper on file : "./SA_test_1.lpr" at line #1

How can i add it?

Also where do i put all the files given?
specifically!

Thanks Wink
Use CatchEvent/EndCatchEvent instead of Event/EndEvent.

'Event' will only be used in the LFSLapper.LPR file.

Open the file AddonsUsed.LPR and add include ("./SA_test_1.lpr");
This thread is closed

FGED GREDG RDFGDR GSFDG