Random script example
Posted: Thu Apr 12, 2012 9:30 pm
A very very basic scripted 'farm' building that demonstrates a few of the newer features in the server & scripting language..
Code: Select all
$sWheatFarmSelectionDisplay = 0
Function WheatFarmDisplayMainOSD( )
{
$wheatAmount = AmountInStocks("Wheat")
osdcreate(OSDBUILDING,"WheatFarmOSDMain", "" )
osdadditem(OSDTEXT, "", "Farm test script" )
if ( $sWheatFarmSelectionDisplay == 1 )
{
osdadditem(OSDTEXT, "", "You did some farming" )
}
else if ( $sWheatFarmSelectionDisplay == 2 )
{
osdadditem(OSDTEXT, "", "You harvested some wheat" )
}
else
{
osdadditem(OSDTEXT, "", "$gBuildingVar[1] visits to this building so far" )
}
osdadditem(OSDTEXT, "", "")
osdadditem(OSDTEXT, "", "In stocks: $wheatAmount wheat" )
osdaddat(OSDBUTTON, 100, 235, 200, 25, "Farm", "Click to Farm")
osdaddat(OSDBUTTON, 350, 235, 200, 25, "Harvest", "Click to Harvest")
osdaddat(OSDEXITBUTTON, 400, 270, 120, 20, "", "Exit")
osdactivate()
}
//-------------------------------------------------------
// WheatFarmOSDMain - OSDSelect : Farm
//-------------------------------------------------------
Event( "OSDSelect", "WheatFarmOSDMain:Farm" )
{
$sWheatFarmSelectionDisplay = 1
*addtostocks $gBuildingAccessNum,1,Wheat
$ret = WheatFarmDisplayMainOSD()
}
//-------------------------------------------------------
// WheatFarmOSDMain - OSDSelect : Harvest
//-------------------------------------------------------
Event( "OSDSelect", "WheatFarmOSDMain:Harvest" )
{
$sWheatFarmSelectionDisplay = 2
*removefromstocks $gBuildingAccessNum,1,Wheat
*grantitem %PLAYER% 1 Wheat
$ret = WheatFarmDisplayMainOSD()
}
//-------------------------------------------------------
// WheatFarmAccessInit - Custom Event
// Called from BuildingAccess event for our scripted farm building type
//-------------------------------------------------------
Event( "Custom", "WheatFarmAccessInit" )
{
$sWheatFarmSelectionDisplay = 0
$ret = WheatFarmDisplayMainOSD()
$gBuildingVar[1] = $gBuildingVar[1] + 1
}