scripting:scriptedosd
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
scripting:scriptedosd [2020/01/29 07:56] – [ScriptedOSD Example] mit | scripting:scriptedosd [2023/02/28 07:02] (current) – mit | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Scripted OSD Overview ===== | ===== Scripted OSD Overview ===== | ||
- | The ScriptedOSD | + | The Scripted OSD system allows you to write scripts on your server that can bring up a window on the client, displaying images, text, buttons etc, which the player is able to interact with. |
- | <note tip>One common use for ScriptedOSD is in conjunction with the ' | + | <note tip>One common use for ScriptedOSD is in conjunction with the ' |
</ | </ | ||
- | For details of all the OSD commands and parameters available see the [[scripting: | + | For details of all the OSD commands and parameters available see the [[scripting: |
+ | |||
+ | If you are looking to override or extend parts of the main UI layout with script, refer to the [[scripting: | ||
===== ScriptedOSD Example ===== | ===== ScriptedOSD Example ===== | ||
- | Here is an example script that activates a dialog on the client. | + | Here is a basic example script that activates a dialog on the client. |
< | < | ||
Line 15: | Line 18: | ||
{ | { | ||
| | ||
- | osdadditem(TEXT, "", | + | osdaddauto(TEXT, "", |
- | osdadditem(BUTTON, " | + | osdaddauto(BUTTON, " |
- | osdadditem(BUTTON, " | + | osdaddauto(BUTTON, " |
| | ||
} | } | ||
Line 35: | Line 38: | ||
The second parameter of the OSDCreate function ' | The second parameter of the OSDCreate function ' | ||
</ | </ | ||
- | Each 'osdadditem' line adds a line to the display. TEXT is used to put some text on the screen, then BUTTON to add a couple of buttons. The second two blocks handle the response when the player selects one of the buttons. The second parameter of the event is formatted '' | + | Each 'osdaddauto' line adds a line to the display. TEXT is used to put some text on the screen, then BUTTON to add a couple of buttons. The second two blocks handle the response when the player selects one of the buttons. The second parameter of the event is formatted '' |
- | If you want to control the layout of your OSD more directly (you will if you want to make anything that looks remotely decent), you use **osdaddat** rather than osdadditem, providing X,Y, width and height for each item. | + | If you want to control the layout of your OSD more directly (you will if you want to make anything that looks remotely decent), you use **osdadd** rather than **osdaddauto**, providing X,Y, width and height for each item. |
e.g. | e.g. | ||
< | < | ||
| | ||
- | osdaddat(BUTTON, 200, 0, 200, 100, "Press", "Press me!" | + | osdadd(BUTTON, 200, 0, 200, 100, "But1", "Press me!" |
| | ||
</ | </ | ||
+ | That also allows you to arrange things programmatically, | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | .. and if you're full expert you'll put all data, names, descriptions (etc) into an array, then write a function that creates the UI automatically by looping through the elements in the array. (Then you only have one function to maintain & improve and you can get on with more important things). Like: | ||
+ | |||
+ | < | ||
+ | function | ||
+ | { | ||
+ | $lineY = 10 | ||
+ | $loop = 1 | ||
+ | while( $loop <= $numStocks) | ||
+ | { | ||
+ | $itemName = $aStocks[$loop] | ||
+ | $stocks = sysAmountInStocks( $itemName ) | ||
+ | $sellPrice = sysGetSellPrice( $itemName ) | ||
+ | |||
+ | $itemNum = sysGetItemNum( $itemName ) | ||
+ | osdadd(BUTTON, | ||
+ | osdadd(BIGTEXT, | ||
+ | if ( $sellPrice > 0 ) | ||
+ | { | ||
+ | $priceText = sysGetPriceText( $sellPrice ) | ||
+ | osdadd(BIGTEXT, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | osdadd(FADEDTEXT, | ||
+ | } | ||
+ | $lineY += 25 | ||
+ | $loop += 1 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // | ||
+ | $kNumFarmStocks = 6 | ||
+ | |||
+ | $maFarmStocksItems[] = | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | "Tea leaves", | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | |||
+ | Event( " | ||
+ | { | ||
+ | osdcreate(OSDLIST," | ||
+ | ShowStocks( $kNumFarmStocks, | ||
+ | osdactivate() | ||
+ | |||
+ | } | ||
+ | </ | ||
scripting/scriptedosd.1580306183.txt.gz · Last modified: 2020/01/29 07:56 by mit