Random script example

Forum Archive - from http://theuniversal.net
Locked
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Random script example

Post by Mit »

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
}
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

neat boss. um. with this addto/remove from stocks, does the same as buying from/selling to/stocking conventional building types in the bdat except done via command? Do buildings still work as we know them to?
Locked