scripting:reference:system_functions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
scripting:reference:system_functions [2020/01/29 04:33] – mit | scripting:reference:system_functions [2020/02/17 19:10] (current) – mit | ||
---|---|---|---|
Line 5: | Line 5: | ||
(Note also the list of [[Scripting: | (Note also the list of [[Scripting: | ||
+ | [[Scripting: | ||
[[Scripting: | [[Scripting: | ||
[[Scripting: | [[Scripting: | ||
+ | [[Scripting: | ||
+ | [[Scripting: | ||
+ | [[Scripting: | ||
+ | [[Scripting: | ||
[[Scripting: | [[Scripting: | ||
- | [[Scripting: | + | [[Scripting: |
- | [[Scripting: | + | [[Scripting: |
+ | [[Scripting: | ||
+ | [[Scripting: | ||
+ | For a full(ish) alphabetical list of script functions : [[Scripting: | ||
- | ===== Building Functions ===== | + | [[Scripting:Reference: |
- | + | [[Scripting:Reference:system_functions: | |
- | ==== sysAmountInStocks ==== | + | [[Scripting: |
- | ^ Format | sysAmountInStocks( | + | Add items and wealth to the player |
- | ^ Description | Returns the amount of the item currently in the building' | + | [[Scripting: |
- | ^ Parameters | Item Name or number | | + | [[Scripting:Reference: |
- | ^ Example | '' | + | [[Scripting: |
- | + | For construction | |
- | ==== sysGetBuyPrice ==== | + | [[Scripting: |
- | ^ Format | sysGetBuyPrice | + | System for creating and controlling subgames which groups |
- | ^ Description | Returns the 'Buy Price' set for this item in the currently accessed building | | + | [[Scripting:Reference:system_functions: |
- | ^ Parameters | Item name or number | + | Querying and controlling the ownership status of buildings |
- | ^ Returns | 'Buy Price' of the item in denari | | + | [[Scripting:Reference: |
- | ^ Notes | Related commands: *setbuyprice [BuildingID] [Item] [Price] | | + | Info about towns and functions to modify the status of town buildings |
- | //Example//:< | + | [[Scripting: |
- | < | + | Maths functions such as rand, sin, cos etc \\ |
- | { | + | [[Scripting:Reference: |
- | $buyPrice = sysGetBuyPrice( " | + | System for creating ' |
- | $buyPriceText = sysGetPriceText( $buyPrice ) | + | [[Scripting: |
- | + | General | |
- | osdcreate( OSDBUILDING, | + | |
- | osdaddat( 200, 100, 200, 40, "Sell|Flour", | + | |
- | osdactivate() | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysGetSellPrice ==== | + | |
- | ^ Format | sysGetSellPrice( [Item_Name or Num] )| | + | |
- | ^ Description | Returns the price that the item is currently set for sale at (Or 0 if it is not currently for sale) | | + | |
- | ^ Parameters | Item Name or number | | + | |
- | // | + | |
- | < | + | |
- | < | + | |
- | { | + | |
- | osdcreate( OSDBUILDING, " | + | |
- | $woodSellPrice = sysGetSellPrice( " | + | |
- | if ( $woodSellPrice == 0 ) | + | |
- | { | + | |
- | osdaddat( TEXT, 100, 100, 400, 0, "", | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | $woodSellPriceText = sysGetPriceText( $woodSellPrice ) | + | |
- | osdaddat( TEXT, 100, 100, 400, 0, "", | + | |
- | } | + | |
- | osdactivate() | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | ==== sysGetEmployeeID ==== | + | |
- | ^ Format | sysGetEmployeeID( | + | |
- | ^ Description | Returns the employee player ID for the currently accessed building. Buildings can have up to 16 employees. | | + | |
- | ^ Parameters | Index (0 - 15) | | + | |
- | ^ Returns | PlayerID of the employee or 0 if none is set for this index | | + | |
- | //Example//:< | + | |
- | < | + | |
- | { | + | |
- | osdcreate( OSDBUILDING, | + | |
- | $employeeID = sysGetEmployeeID( 0 ) | + | |
- | if ( $employeeID != 0 ) | + | |
- | { | + | |
- | $employeeName = sysGetPlayerName( $employeeID ) | + | |
- | osdaddat( TEXT, 100, 100, 400, 0, "", | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | osdaddat( TEXT, 100, 100, 400, 0, "", | + | |
- | } | + | |
- | osdactivate() | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== sysGetBuildingName ==== | + | |
- | ^ Format | + | |
- | ^ Description | Returns | + | |
- | ^ Parameters | Building ID number | + | |
- | ^ Returns | The building name | | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $nearestTownID = sysGetNearestTown( $gPlayerWorldX, $gPlayerWorldY ) | + | |
- | $nearestTownName = sysGetBuildingName( $nearestTownID ) | + | |
- | *msg %PLAYER% The nearest town is $nearestTownName | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== sysGetMaxJobs ==== | + | |
- | TBD\\ | + | |
- | + | ||
- | + | ||
- | ===== Construction ===== | + | |
- | ==== sysIsBuildingPositionValid ==== | + | |
- | ^ Format | + | |
- | ^ Description | Checks whether | + | |
- | ^ Parameters | Building Type number | + | |
- | ^ Returns | 1 if the position is valid, 0 if not | | + | |
- | //Example//:< | + | |
- | < | + | |
- | { | + | |
- | $buildingType = $gParam[1] | + | |
- | $isValid = sysIsBuildingPositionValid( $buildingType ) | + | |
- | if ( $isValid == 1 ) | + | |
- | { | + | |
- | $buildingName = sysGetTextEntry() | + | |
- | $constrAmount = -1 | + | |
- | $didAdd = sysAddBuildingWorld( $buildingType, | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysAddBuilding ==== | + | |
- | ^ Format | + | |
- | ^ Description | Used to add a new building to your world | | + | |
- | ^ Parameters | Building Type number | | + | |
- | ^ | Owner player ID | | + | |
- | ^ | Map Coordinate X | | + | |
- | ^ | Map Coordinate Y | | + | |
- | ^ | (Optional) Building Name | | + | |
- | ^ | (Optional) Construction Amount 1 | | + | |
- | ^ | (Optional) Construction Amount 2 | | + | |
- | ^ Returns | 1 if the building | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $nBuildingType = $gParam[1] | + | |
- | + | ||
- | $valid = sysIsBuildingPositionValid( $nBuildingType ) | + | |
- | if ( $valid = 1 ) | + | |
- | { | + | |
- | $buildingName = sysGetTextEntry() | + | |
- | $didAdd = sysAddBuilding( nBuildingType, | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysAddBuildingWorld ==== | + | |
- | TBD\\ | + | |
- | ==== sysGetBuildingTypeName ==== | + | |
- | TBD // | + | |
- | // | + | |
- | ==== sysGetConstructionMaterialsAmount ==== | + | |
- | TBD // | + | |
- | // | + | |
- | ==== sysAddLocalBackgroundModel ==== | + | |
- | TBD\\ | + | |
- | ==== sysDeleteLocalBackgroundModel ==== | + | |
- | TBD\\ | + | |
- | ==== sysDeleteAllLocalBackgroundModels ==== | + | |
- | TBD\\ | + | |
- | ==== sysAddBackgroundModels ==== | + | |
- | TBD\\ | + | |
- | + | ||
- | ===== Town Functions ===== | + | |
- | ==== sysGetNearestTown ==== | + | |
- | ==== sysTownGetRelationship ==== | + | |
- | ==== sysTownGetNumBuildingsOfType ==== | + | |
- | ^ Format | sysTownGetNumBuildingsOfType( | + | |
- | ^ Description | Returns the number of buildings of this type currently exist within the specified town. Useful for when you want to script a system that limits the number of a particular type of building per town | | + | |
- | ^ Parameters | BuildingID of the town to query | | + | |
- | ^ | Type number of the building to check | | + | |
- | ^ Returns | Number of this type of building in the town | | + | |
- | //Example//: < | + | |
- | < | + | |
- | { | + | |
- | $nBuildingType = $gParam[1] | + | |
- | + | ||
- | $nearestTownID = sysGetNearestTown( $gPlayerWorldX, | + | |
- | $numInTown = sysTownGetNumBuildingsOfType( $nearestTownID, | + | |
- | if ( $numInTown >= 3 ) | + | |
- | { | + | |
- | *msg %PLAYER% There can only be 3 of each type of building in each town | + | |
- | | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | $valid = sysIsBuildingPositionValid( $nBuildingType ) | + | |
- | if ( $valid = 1 ) | + | |
- | { | + | |
- | $buildingName = sysGetTextEntry() | + | |
- | $constrAmount = -1 | + | |
- | $didAdd = sysAddBuildingWorld( $nBuildingType, | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== World / Map Functions ===== | + | |
- | + | ||
- | ==== sysGetTileCenter ==== | + | |
- | ^ Format | + | |
- | ^ Description | Returns the world coordinate value for the center of the map tile nearest to the specified position| | + | |
- | ^ Parameters | **[World X or Y]** - World coordinate value | | + | |
- | ^ Returns | World coordinate of tile center | | + | |
- | //Example//: < | + | |
- | < | + | |
- | { | + | |
- | $tileCenterX = sysGetTileCenter( $gPlayerWorldX ) | + | |
- | $tileCenterY = sysGetTileCenter( $gPlayerWorldY ) | + | |
- | *setposworld %PLAYER% $tileCenterX $tileCenterY | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | ==== sysMapToWorld ==== | + | |
- | ^ Format | sysMapToWorld ( [Map X or Y] )| | + | |
- | ^ Description | Converts a map coordinate to a world coordinate| | + | |
- | ^ Parameters | **[Map X or Y]** - Map coordinate value | | + | |
- | ^ Returns | World coordinate | | + | |
- | //Notes//: There are 2 coordinate systems used in the game ; Map Coordinates range from 0 to 255 (for the default map size), 0 to 511 or 0 to 1023 (if using a larger | + | |
- | ==== sysWorldToMap ==== | + | |
- | ^ Format | sysWorldToMap ( [Map X or Y] )| | + | |
- | ^ Description | Converts a world coordinate to a map coordinate| | + | |
- | ^ Parameters | **[World X or Y]** - World coordinate value | | + | |
- | ^ Returns | Nearest map coordinate value | | + | |
- | ==== sysGetBuildingAtWorldPos ==== | + | |
- | ==== sysWorldGetNumBuildingsOfType ==== | + | |
- | ^ Format | sysWorldGetNumBuildingsOfType( [BuildingType] )| | + | |
- | ^ Description | Returns the number | + | |
- | ^ Parameters | Type number of the building to check | | + | |
- | ^ Returns | Number | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $nBuildingType = $gParam[1] | + | |
- | + | ||
- | $numInWorld = sysWorldGetNumBuildingsOfType( $nBuildingType ) | + | |
- | if ( $numInWorld >= 1 ) | + | |
- | { | + | |
- | *msg %PLAYER% There can only be 1 of each type of building | + | |
- | CancelTransaction() | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | $valid = sysIsBuildingPositionValid( $nBuildingType ) | + | |
- | if ( $valid = 1 ) | + | |
- | { | + | |
- | $buildingName = sysGetTextEntry() | + | |
- | $constrAmount = -1 | + | |
- | $didAdd = sysAddBuildingWorld( $nBuildingType, | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysGetNearestForest ==== | + | |
- | + | ||
- | ===== Text Functions ===== | + | |
- | + | ||
- | ==== sysGetPlayerName ==== | + | |
- | ^ Format | sysGetPlayerName( | + | |
- | ^ Description | Returns the name of the specified player| | + | |
- | ^ Parameters | Player ID | | + | |
- | ^ Returns | Player Name | | + | |
- | //Example//: < | + | |
- | < | + | |
- | { | + | |
- | $targetName = sysGetPlayerName( $gTargetID ) | + | |
- | *msg %PLAYER% You used the potion while targeting $targetName | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysGetItemName ==== | + | |
- | Example | + | |
- | TBD\\ | + | |
- | + | ||
- | ==== sysGetSkillName ==== | + | |
- | Example | + | |
- | TBD\\ | + | |
- | + | ||
- | ==== sysGetItemNum ==== | + | |
- | ^ Format | + | |
- | ^ Description | Gets an item number from a name| | + | |
- | ^ Parameters | Item Name | | + | |
- | ^ Returns | Item number | | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $itemNum = sysGetItemNum( " | + | |
- | *msg %PLAYER% The item number is $itemNum | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysGetSkillNum ==== | + | |
- | TBD\\ | + | |
- | + | ||
- | ==== sysGetPriceText ==== | + | |
- | ^ Format | sysGetPriceText ( [Price] )| | + | |
- | ^ Description | Returns a text string displaying the price value expressed in a short format - e.g 2s 3d | | + | |
- | ^ Parameters | Price value (in denari) | | + | |
- | ^ Returns | Price text | | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $price = 20 | + | |
- | if ( $gPlayerCash < $price ) | + | |
- | { | + | |
- | $priceText = sysGetPriceText( $price ) | + | |
- | *alert %PLAYER% You need at least $priceText to use the potion | + | |
- | CancelTransaction() | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | *grantcash %PLAYER% -$price | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | ==== sysGetDateText ==== | + | |
- | ^ Format | sysGetDateText( | + | |
- | ^ Description | Returns a text string displaying the date and time | | + | |
- | ^ Parameters | Unix time (Number of seconds since 1 Jan 1970) | | + | |
- | ^ Returns | Text of the date and time (e.g. "31st December 2014 18:00" ) | | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $nextUsePotionTime = $gServerTimeVar[0] | + | |
- | | + | |
- | if ( $currTime < $nextUsePotionTime ) | + | |
- | { | + | |
- | $useDateText = sysGetDateText( $nextUsePotionTime ) | + | |
- | *msg %PLAYER% You cannot use the potion until $useDateText | + | |
- | CancelTransaction() | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | // Set server variable to store the next time the potion can be used - one hour from now | + | |
- | $kOneHourInSeconds = 60 * 60 | + | |
- | $gServerTimeVar[0] = $currTime + $kOneHourInSeconds | + | |
- | } | + | |
- | } | + | |
- | </code> | + | |
- | </ | + | |
- | + | ||
- | ==== sysGetTimeText ==== | + | |
- | TBD // | + | |
- | // | + | |
- | + | ||
- | ==== sysGetRealTimeTextForDays ==== | + | |
- | ^ Format | sysGetRealTimeTextForDays ( [Number of game days] )| | + | |
- | ^ Description | Returns a text description of the time that will pass for the specified number of game days | | + | |
- | ^ Parameters | Number of game days | | + | |
- | ^ Returns | Time text | | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $daysSinceLastUsed = $gGameDay - $gPlayerKey[LastUsedPotionDay] | + | |
- | if ( $daysSinceLastUsed < 10 ) | + | |
- | { | + | |
- | $daysUntilCanUse = 10 - $daysSinceLastUsed | + | |
- | $timeText = sysGetRealTimeTextForDays( $daysUntilCanUse ) | + | |
- | *say You must wait $timeText until you can use the Magic Potion again | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | *effect %PLAYER% 10 | + | |
- | $gPlayerKey[LastUsedPotionDay] = $gGameDay | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | ===== Battle game Functions ===== | + | |
- | + | ||
- | ==== BattleSetPreludeTime ==== | + | |
- | + | ||
- | ==== BattleSetNumRounds ==== | + | |
- | + | ||
- | ==== BattleSetRoundTime ==== | + | |
- | + | ||
- | ==== BattleSetRoundScore ==== | + | |
- | + | ||
- | ==== BattleSendChallenge ==== | + | |
- | + | ||
- | + | ||
- | ===== Maths Functions ===== | + | |
- | + | ||
- | ==== sysRand ==== | + | |
- | ^ Format | sysRand ( [MAX_NUM] )| | + | |
- | ^ Description | Returns a random number between 1 and the value specified | | + | |
- | ^ Example | '' | + | |
- | + | ||
- | ==== sysSin ==== | + | |
- | ^ Format | sysSin ( [ANGLE], | + | |
- | ^ Description | Returns a sine value| | + | |
- | ^ Parameters | Angle - 0 to 360 degrees | | + | |
- | ^ | Scale - Scale applied to the result from the sine function (which normally returns a value from -1 to 1 | | + | |
- | ^ Returns | Scaled sine value | | + | |
- | //Example//: < | + | |
- | < | + | |
- | { | + | |
- | $angle = 0 | + | |
- | while ( $angle < 360 ) | + | |
- | { | + | |
- | $posX = sysSin( $angle, 100 ) | + | |
- | $posY = sysCos( $angle, 100 ) | + | |
- | $posX += $gPlayerWorldX | + | |
- | $posY += $gPlayerWorldY | + | |
- | *addtree 1, | + | |
- | $angle += 36 | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== sysCos ==== | + | |
- | ^ Format | + | |
- | ^ Description | Returns a cosine value| | + | |
- | ^ Parameters | Angle - 0 to 360 degrees | | + | |
- | ^ | Scale - Scale applied to the result from the cosine function (which normally returns a value from -1 to 1 | | + | |
- | ^ Returns | Scaled cosine value | | + | |
- | // | + | |
- | \\ | + | |
- | + | ||
- | ==== sysGetDist ==== | + | |
- | ^ Format | sysGetDist ( [X1], [Y1], [X2], [Y2] )| | + | |
- | ^ Description | Calculates the distance between two points| | + | |
- | ^ Parameters | Point 1 X,Y | | + | |
- | ^ | Point 2 X,Y | | + | |
- | ^ Returns | Distance | | + | |
- | // | + | |
- | < | + | |
- | { | + | |
- | $dist = sysGetDist( $gPlayerWorldX, | + | |
- | *msg %PLAYER% You accessed the building from $dist cm away | + | |
- | } | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== Misc other functions ===== | + | |
- | ==== sysRealTime ==== | ||
- | ^ Format | sysRealTime ( [Type] )| | ||
- | ^ Description | Returns details of the current real time (according to the server clock)| | ||
- | ^ Parameters | Type field specifying the date or time to fetch | | ||
- | ^ Returns | Depending on the type field: | | ||
- | ^ | **Year** - returns the current year (e.g. 2014) | | ||
- | ^ | **Month** - returns the current month number (1 to 12) | | ||
- | ^ | **Day** - returns the current day number (1 to 31) | | ||
- | ^ | **Hour** - returns the current hour (0 to 23) | | ||
- | ^ | **Minute** - returns the current minute (0 to 59) | | ||
- | ^ | **Second** - returns the current second (0 to 59) | | ||
- | ^ | **UnixTime** - number of seconds passed since 1st Jan, 1970 | | ||
- | // | ||
- | < | ||
- | { | ||
- | $hour = sysRealTime( " | ||
- | if ( $hour < 18 ) | ||
- | { | ||
- | *msg %PLAYER% Tea can only be used at tea-time (6pm - 8pm) | ||
- | } | ||
- | else if ( $hour >= 20 ) | ||
- | { | ||
- | *msg %PLAYER% Tea can only be used at tea-time (6pm - 8pm) | ||
- | } | ||
- | else | ||
- | { | ||
- | *notifylarge %PLAYER% Tea-time! | ||
- | } | ||
- | } | ||
- | </ | ||
- | </ | ||
- | ==== sysRaceIsActive ==== | ||
- | TBD \\ | ||
- | \\ |
scripting/reference/system_functions.1580294000.txt.gz · Last modified: 2020/01/29 04:33 by mit