User Tools

Site Tools


scripting:scriptedosd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
scripting:scriptedosd [2020/01/28 17:50] – external edit 127.0.0.1scripting:scriptedosd [2023/02/28 07:02] (current) mit
Line 1: Line 1:
 ===== Scripted OSD Overview ===== ===== Scripted OSD Overview =====
  
-The ScriptedOSD 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.  +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 'Scripted' building type - When the player accesses the building, your script is run and it generates the display window for the building.+<note tip>One common use for ScriptedOSD is in conjunction with the 'Scripted' building type - When the player accesses the building, your script is run ( ''Event( "AccessBuilding", "[BUILDING_TYPE]" )''and it generates the display window for the building.
 </note> </note>
  
-For details of all the OSD commands and parameters available see the [[scripting:reference:scriptedosd|Reference section]]+For details of all the OSD commands and parameters available see the [[scripting:reference:scriptedosd|Reference section]]
 + 
 +If you are looking to override or extend parts of the main UI layout with script, refer to the [[scripting:reference:ScriptingMainUI|Scripting Main UI]] section. 
  
 ===== 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.
  
-<codedoc>+<code>
 Event( "Custom", "HelloWorld" Event( "Custom", "HelloWorld"
  
    osdcreate(OSDLIST,"Main","Hello World"    osdcreate(OSDLIST,"Main","Hello World"
-   osdadditem(TEXT, "", "How would you like to respond")  +   osdaddauto(TEXT, "", "How would you like to respond")  
-   osdadditem(BUTTON, "Option1", "Positively")  +   osdaddauto(BUTTON, "Option1", "Positively")  
-   osdadditem(BUTTON, "Option2", "Negatively"+   osdaddauto(BUTTON, "Option2", "Negatively"
    osdactivate()     osdactivate() 
  
Line 30: Line 33:
    *notify %PLAYER% You responded negatively    *notify %PLAYER% You responded negatively
  
-</codedoc>+</code>
 The first block - which is run when a custom event called 'HelloWorld' is run (for instance by entering ''*event {YourName} HelloWorld'') - lays out the initial menu of the OSD, a bit of text with two buttons.  The first block - which is run when a custom event called 'HelloWorld' is run (for instance by entering ''*event {YourName} HelloWorld'') - lays out the initial menu of the OSD, a bit of text with two buttons. 
 <note> <note>
 The second parameter of the OSDCreate function 'names' your OSD screen, and is important when dealing with the OSDSELECT response The second parameter of the OSDCreate function 'names' your OSD screen, and is important when dealing with the OSDSELECT response
 </note>  </note> 
-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 ''OSDNAME:OSDBUTTONNAME''.+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 ''OSDNAME:OSDBUTTONNAME''.
  
-If you want to control the layout of your OSD more directly, 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.
-<codedoc>   +<code>   
    osdcreate(OSDLOWER,"Main","Big Button"    osdcreate(OSDLOWER,"Main","Big Button"
-   osdaddat(BUTTON, 200, 0, 200, 100, "Press", "Press me!"+   osdadd(BUTTON, 200, 0, 200, 100, "But1", "Press me!"
    osdactivate()     osdactivate() 
-</codedoc>+</code> 
 + 
 +That also allows you to arrange things programmatically, so you'll probably end up with osd code like: 
 + 
 +<code>    
 +   $buttonX = 200 
 +   $buttonY = 100 
 +   $buttonW = 200 
 +   $buttonH = 30 
 +   osdcreate(OSDLOWER,"Main","Big Button")  
 +   osdadd(BUTTON, $buttonX, $buttonY, $buttonW, $buttonH, "But1", "Press me!")  
 +   $buttonY += $buttonH + 10 
 +   osdadd(BUTTON, $buttonX, $buttonY, $buttonW, $buttonH, "But2", "No press me!")  
 +   $buttonY += $buttonH + 10 
 +   osdactivate()  
 +</code> 
 + 
 +.. 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: 
 + 
 +<code> 
 +function    ShowStocks( $numStocks, $aStocks ) 
 +
 +$lineY = 10 
 +$loop = 1 
 +while( $loop <= $numStocks) 
 +
 +    $itemName = $aStocks[$loop] 
 +    $stocks = sysAmountInStocks( $itemName ) 
 +    $sellPrice = sysGetSellPrice( $itemName ) 
 + 
 +    $itemNum = sysGetItemNum( $itemName ) 
 +    osdadd(BUTTON, 70, $lineY, 150, 22, "selectItem|$itemNum", "$itemName")  
 +    osdadd(BIGTEXT, 255, $lineY, 80, 0, "", "$stocks ")  
 +    if ( $sellPrice > 0 ) 
 +    { 
 + $priceText = sysGetPriceText( $sellPrice ) 
 + osdadd(BIGTEXT, 390, $lineY, 100, 0, "", "$priceText")  
 +    } 
 +    else 
 +    { 
 + osdadd(FADEDTEXT, 400, $lineY, 0, 0, "", "Not selling")  
 +    } 
 +    $lineY += 25 
 +    $loop += 1 
 +
 +
 + 
 +//---------------------------------- 
 +$kNumFarmStocks = 6 
 + 
 +$maFarmStocksItems[] =  
 +
 + "Wheat", 
 + "Hops", 
 + "Tea leaves", 
 + "Coffee beans", 
 + "Potatoes", 
 + "Sugar Cane", 
 +}
  
 +Event( "AccessBuilding", "$kFarmBuildingType" )
 +{
 +    osdcreate(OSDLIST,"Farm","Farm Stocks"
 +    ShowStocks( $kNumFarmStocks, $maFarmStocksItems )
 +    osdactivate() 
  
 +}
 +</code>
  
scripting/scriptedosd.1580255404.txt.gz · Last modified: 2020/01/28 17:50 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki