scripting:samples:functionbuilding
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:
$kConstructionStructSize = 6 Function ConstructionListOSD( $aConstructionList, $selectFunc ) { $index = 1 $lineY = 40 $imageX = 100 $textX = 200 $subtextWidth = 300 // Set root path for all the menu images.. osdadditem(HTTPSET, "", "http://gameislands.net/gamecontent/zion3/menus/" ) while( $aConstructionList[$index+1] >= 0 ) { $buildingName = $aConstructionList[$index] $buildingType = $aConstructionList[$index+1] $price = $aConstructionList[$index+2] $imageName = $aConstructionList[$index+4] $desc = $aConstructionList[$index+5] $buildTechLevel = sysGetBuildingTypeTechLevel( $buildingType ) $matReqd = sysGetConstructionMaterialsAmount( $buildingType ) $price = sysGetSecondaryConstructionPrice( $buildingType ) osdadd(IMAGE, $imageX, $lineY, 90, 90, "$selectFunc|$buildingType|$price", "$imageName") $textY = $lineY osdadd(BIGTEXT, $textX, $textY, 0, 0, "", "$buildingName" ) $textY += 20 $priceText = sysGetPriceText( $price ) osdadd(SMALLTEXT, $textX, $textY, 0, 0, "", "Cost: $priceText ( + town tax )" ) $textY += 15 osdadd(SMALLTEXT, $textX, $textY, 0, 0, "", "Req: $matReqd Wood" ) $subtextY = $textY + 20 osdadd(FADEDSMALLTEXT, $textX, $subtextY, $subtextWidth, 0, "", "$desc" ) $lineY += 100 $index += $kConstructionStructSize } }
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 buildID Price builditem graphic desc "Small House", 68, 100, "Wood", "stdhouse1.jpg", "50 item capacity", "Medium House", 69, 200, "Wood", "stdhouse2.jpg", "100 item capacity", "Barn conversion", 70, 100, "Wood", "barn.jpg", "200 item capacity", "Large House", 71, 100, "Wood", "stdhouse3.jpg", "500 item capacity", "", -1, -1, "", "" } Event( "UseSkill", "Build Houses" ) { osdcreate(OSDWINDOW,"BuildHousesOSD", "Build Houses" ) osdadditem(OSDMINHEIGHT, "", "400" ) osdadd(BIGTEXT, 0, 0, 600, 0, "", "Choose a building to construct:" ) ConstructionListOSD( $maConstructionListBuildHouses, "Construct" ) osdadd(EXITBUTTON, 200, 360, 200, 30, "", "Cancel") osdactivate() } Event( "OSDSelect", "BuildHousesOSD:Construct" ) { $buildingType = $gParam[1] $buildingTypeName = sysGetBuildingTypeName( $buildingType ) $buildingName = "%PLAYER%'s $buildingTypeName" *buildingconstruct %PLAYER% $buildingType $buildingName }
scripting/samples/functionbuilding.txt · Last modified: 2023/02/28 07:04 by mit