Here's an example of the process.
First, we usually have a build skill of some kind and we react to the user selecting it via the "UseSkill" event. That event could trigger the construction directly, or it might add some OSD, such as in this example from Aramathea..
Code: Select all
$kBuildingNumSchool = 20
Event( "UseSkill", "Build Education" )
{
osdcreate(OSDLIST,"BuildEduOSD", "Build Education Skill" )
osdadditem(OSDMINHEIGHT, "", "180" )
osdaddat(OSDFADEDTEXT, 0, 10, 600, 0, "", "Select a building to begin construction" )
$lineY = 35
osdaddat(OSDIMAGE, 20, $lineY, 90, 90, "Build|$kBuildingNumSchool", "http://webspace.com/img.jpg")
osdaddat(OSDBIGTEXT, 120, $lineY, 0, 0, "", "School" )
$liney = $lineY + 20
osdaddat(OSDTEXT, 120, $liney, 0, 0, "", "(5 wood & 40 bricks)" )
$liney = $liney + 20
osdaddat(OSDFADEDTEXT, 120, $liney, 180, 45, "", "Allows players to learn new skills." )
osdaddat(OSDEXITBUTTON, 195, 150, 200, 20, "exit", "Close" )
osdactivate()
}
Code: Select all
$buildingNum = $kBuildingNumSchool
$buildingName = "%PLAYER%'s school"
*buildingconstruct %PLAYER% $buildingNum $buildingName
When the player has positioned their building and pressed 'construct' another event is triggered, and at this point we remove the required items from the user's inventory and confirm placement of the building using 'sysAddBuilding' or 'sysAddBuildingWorld'. (The latter uses more fine-grained 'world coordinates' rather than map tile numbers).
There are a couple of ways to handle the event of the player confirming construction... if you want to react to a specific building type being placed, you use the "PlaceBuilding" event. Here's an example that limits the number of schools in a town to 2 :
Code: Select all
Event( "PlaceBuilding", "$kBuildingNumSchool" ) // Construct School
{
$valid = sysIsBuildingPositionValid( $nBuildingCode )
if ( $valid = 1 )
{
$townNum = sysGetNearestTown( $gPlayerWorldX, $gPlayerWorldY )
$numSchoolsInTown = sysTownGetNumBuildingsOfType( $townNum, $kBuildingNumSchool )
if ( $numSchoolsInTown < 2 )
{
$didAdd = sysAddBuildingWorld( $kBuildingNumSchool, $gPlayerID, $gPlayerWorldX,$gPlayerWorldY, $buildingName,$constrAmount )
}
else
{
*msg %PLAYER% There are already 2 schools in this town
}
}
Here's the example from Aramathea that requires 5 wood to construct most types of building
Code: Select all
Event( "PlaceAnyBuilding", "" ) // Catch all
{
$nBuildingCode = $gParam[1]
$hasWood = sysPlayerInventory( "Wood" )
if ( $hasWood >= 5 )
{
$valid = sysIsBuildingPositionValid( $nBuildingCode )
if ( $valid = 1 )
{
$buildingName = sysGetTextEntry()
$constrAmount = -1
$didAdd = sysAddBuildingWorld( $nBuildingCode,$gPlayerID,$gPlayerWorldX,$gPlayerWorldY,$buildingName,$constrAmount )
if ( $didAdd != 0 )
{
*grantitem %PLAYER% -5 Wood
}
}
}
else
{
*msg %PLAYER% You need 5 wood to build
}
}