scripting:samples:functionbuilding
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| scripting:samples:functionbuilding [2020/02/12 22:23] – created mit | scripting:samples:functionbuilding [2025/05/28 18:58] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | [code]$kConstructionStructSize = 6 | + | Here's an example of using a function to create a custom display that can be used to provide a range of standard data-driven interfaces. In this case, the function generates a display offering the user a set of different buildings to construct: |
| + | |||
| + | <code> | ||
| + | $kConstructionStructSize = 6 | ||
| Function ConstructionListOSD( $aConstructionList, | Function ConstructionListOSD( $aConstructionList, | ||
| { | { | ||
| Line 7: | Line 10: | ||
| $textX = 200 | $textX = 200 | ||
| $subtextWidth = 300 | $subtextWidth = 300 | ||
| - | $index = 1 | + | // Set root path for all the menu images.. |
| - | $count = 0 | + | osdadditem(HTTPSET, |
| while( $aConstructionList[$index+1] >= 0 ) | while( $aConstructionList[$index+1] >= 0 ) | ||
| Line 21: | Line 24: | ||
| $matReqd = sysGetConstructionMaterialsAmount( $buildingType ) | $matReqd = sysGetConstructionMaterialsAmount( $buildingType ) | ||
| $price = sysGetSecondaryConstructionPrice( $buildingType ) | $price = sysGetSecondaryConstructionPrice( $buildingType ) | ||
| - | osdaddat(IMAGE, $imageX, $lineY, 90, 90, " | + | osdadd(IMAGE, $imageX, $lineY, 90, 90, " |
| $textY = $lineY | $textY = $lineY | ||
| - | osdaddat(BIGTEXT, $textX, $textY, 0, 0, "", | + | osdadd(BIGTEXT, $textX, $textY, 0, 0, "", |
| $textY += 20 | $textY += 20 | ||
| $priceText = sysGetPriceText( $price ) | $priceText = sysGetPriceText( $price ) | ||
| - | osdaddat(SMALLTEXT, $textX, $textY, 0, 0, "", | + | osdadd(SMALLTEXT, $textX, $textY, 0, 0, "", |
| $textY += 15 | $textY += 15 | ||
| - | + | osdadd(SMALLTEXT, $textX, $textY, 0, 0, "", | |
| - | if ( $buildTechLevel == 0 ) | + | |
| - | { | + | |
| - | osdaddat(SMALLTEXT, | + | |
| - | } | + | |
| - | else if ( $buildTechLevel == 1) | + | |
| - | { | + | |
| - | osdaddat(SMALLTEXT, $textX, $textY, 0, 0, "", | + | |
| - | } | + | |
| $subtextY = $textY + 20 | $subtextY = $textY + 20 | ||
| - | osdaddat(FADEDSMALLTEXT, | + | osdadd(FADEDSMALLTEXT, |
| $lineY += 100 | $lineY += 100 | ||
| $index += $kConstructionStructSize | $index += $kConstructionStructSize | ||
| - | $count += 1 | ||
| } | } | ||
| } | } | ||
| - | [/code] | + | </code> |
| + | |||
| + | And to use this function, another part of the script calls it with a data table set up to fill in the names, items and building types involved : | ||
| + | |||
| + | < | ||
| + | $maConstructionListBuildHouses[] = | ||
| + | { // Building Name | ||
| + | " | ||
| + | " | ||
| + | "Barn conversion", | ||
| + | " | ||
| + | "", | ||
| + | } | ||
| + | |||
| + | Event( " | ||
| + | { | ||
| + | osdcreate(OSDWINDOW," | ||
| + | osdadditem(OSDMINHEIGHT, | ||
| + | osdadd(BIGTEXT, | ||
| + | |||
| + | ConstructionListOSD( $maConstructionListBuildHouses, | ||
| + | |||
| + | osdadd(EXITBUTTON, | ||
| + | osdactivate() | ||
| + | } | ||
| + | |||
| + | Event( " | ||
| + | { | ||
| + | $buildingType = $gParam[1] | ||
| + | $buildingTypeName = sysGetBuildingTypeName( $buildingType ) | ||
| + | $buildingName = " | ||
| + | *buildingconstruct %PLAYER% $buildingType $buildingName | ||
| + | } | ||
| + | </ | ||
| + | |||
scripting/samples/functionbuilding.1581546205.txt.gz · Last modified: (external edit)
