Page 1 of 1

various cross-user script bits?

Posted: Thu Jun 05, 2014 10:59 pm
by zaroba
Couple different things I'm wonder if possible.

Sell to building script - storage capacity effected by different building.
Player A owns Building 1 and Building 2
Player B wants to sell something to Building 1
Can the script somehow see if the owner of Building 1 also owns Building 2?


To go along with this.
Production Script - Automated storage in external building
When the production script for Building 1 runs, can it see if the owner of Building 1 also owns a Building 2 and then remove items from Building 1 and add them to Building 2?

Ideally building proximity would also play a roll in all this, either same town or tile distance. Don't need somebody having main buildings in one city and all the support buildings halfway across the map.


Something that I'm hoping to do for zoric is that players can build separate storage buildings which will be used by buildings they own to basically increasestorage capacity for both demanded and produced items. Along with having many other cross-building effects, like increasing qty produced or decreasing time to produce or resources needed. Even needing to own a certain building before a different building can produce items. Like needing to build a Hen House before a farm can produce Eggs.

Posted: Fri Jun 06, 2014 8:41 am
by Mit
mm, well, theoretically you could do that with existing stuff by running a *eventallbuildings custom event, checking each building to see if its owned by the player and in the right place, then storing the results in the original building's or player's vars - but that'd be really unpleasant and the script would take a long time to run once you got a lot of buildings on the world. I really wouldn't recommend it :].

For 0.66.4 i've added a (rather verbosively named) sys function : sysPlayerGetNearestOwnedBuildingOfType( [PlayerID], [BuildingType], [WorldX], [WorldY] ) which may be a bit more practical.
That will return a buildingID if the player owns a particular building type within 1km of the world coord. (0 otherwise).

I've also added sysGetPlayerOwnedBuilding( [PlayerID], [Index] ) which (combined with the new while loops) could be used to get the building IDs for all the buildings owned by the player.

Posted: Fri Jun 06, 2014 9:17 am
by Mit
p.s. I've updated the current full list of sys functions at :
http://theuniversal.net/worldmanual/dok ... _functions and am working through documenting some more of 'em.

Here's a wee example of the latter :

Code: Select all

Function	SendOwnedBuildingsList( $playerID )
{
	$playerName = sysGetPlayerName( $playerID )

    $loop = 1
	while( $loop < 10 )
	{
	   $buildingID = sysPlayerGetOwnedBuilding( $playerID, $loop )
		// No more buildings
       if ( $buildingID == 0 )
	   {
		   return
	   }
	 
	   $buildingName = sysGetBuildingName( $buildingID )
	   *msg $playerName Building $loop : ID = $buildingID ( $buildingName )
	   $loop += 1
	}
}

Event( "Custom", "TestFunc" )
{
	SendOwnedBuildingsList( $gPlayerID )
}