User Tools

Site Tools


scripting:samples:basicbuilding

Simple 'Gather Building' Sample script

Here is a simple script for a 'Gather Building' - i.e. One where the user accesses a 'building' (doesn't have to be an actual building model of course, it could be a rock or a tree or a NPC..) and it gives the user a particular item (up to a defined limit).

To use it on your own world, set a building in the Buildings Editor to be a 'scripted-nowindow' type, then modify the '$kGatherBuildingNum' with the building-type number and '$kGatherItem' with the item you want to award.

$kMaxAmountOfItemToGather = 3
$kGatherBuildingNum = 5
$kGatherItem = "Berries"

//--------------------------------------------------
//------ Access building script
//--------------------------------------------------
Event( "AccessBuilding", "$kGatherBuildingNum" )
{
	$ret = StandardGatherDisplay( $kGatherItem );
}

//--------------------------------------------------
//  StandardGatherDisplay
//--------------------------------------------------
Function	StandardGatherDisplay( $itemName )
{
	$isInInv = sysPlayerInventory( $itemName )

	if ( $isInInv < kMaxAmountOfItemToGather )
	{
		$amountToAdd = kMaxAmountOfItemToGather - $isInInv
		*changeinventory %PLAYER% $amountToAdd $itemName
		*updateinventory %PLAYER%
		*notify %PLAYER% You collected $amountToAdd $itemName
	}
	else
	{
		*alert %PLAYER% You have all the $itemName you can carry right now
	}
}
scripting/samples/basicbuilding.txt · Last modified: 2020/02/01 19:44 by mit

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki