Gothic Online Forums
[0.1.3] [client/server] Utility Scripts - Printable Version

+- Gothic Online Forums (https://archive.gothic-online.com)
+-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html)
+--- Forum: Resources (https://archive.gothic-online.com/forum-14.html)
+---- Forum: Scripts (https://archive.gothic-online.com/forum-17.html)
+---- Thread: [0.1.3] [client/server] Utility Scripts (/thread-2300.html)



[0.1.3] [client/server] Utility Scripts - HammelGammel - 28.12.2017

Description:

Library with various, hopefully useful utility functions written in Squirrel. Required for some of my other scripts.

Please report any problems you find here: Issue Tracker



Installation:

  1. Extract G2O_Module_Util.7z
  2. Move resulting folder in the root folder of your server
  3. Add the following to your config.xml:
Code:
<!-- Module Util -->
<import src="G2O_Module_Util/scripts.xml" />




Util.nut

Static class with miscellaneous utility methods

Code:
getAngleDelta(angle1, angle2)
reverseTable(table)
round(value, decimalPlaces)isFirstWord(string, word)
lerp(val1, val2, delta)
lerpAngle(from, to, delta)
moveOnAngle(x, y, z, angle, delta)
integerToBool(value)
stringToBool(inString)
tableToString(inTable)
stringToTable(inString)
valueToString(value)
stringToValue(inString)
splitString(string, delimiter)
addToTime(date, dateDelta)
isTimeLater(date1, date2)
getDeltaGameTimeMinutes(startTime, endTime)
isTimeBetween(startTime, endTime, currentTime)
cloneArray(inArray)
getNearestPlayer(x, y, z, maxDistance)

CellSystem.nut

Allows adding elements to a grid of cells by their position. This can be used to then get all elements in grids around a given position. When lots of elements exist that have to do distancechecks to all other elements, this can reduce the amount of elements to check and thus decrease overhead.

Example: 1000 bots are scattered around the map. Normally, distancechecks would have to be done from all bots to all other bots to check if bot is within viewing distance. With a CellSystem, only bots in surrounding cells have to even be considered for a refined distancecheck.

Code:
getAdjacentCells(x, z, radius)
getContentNear(x, z, radius)
getIndexByPos(x, z)
addToCellByPos(x, z, identifier, value)
addToCell(index, identifier, value)
removeFromCell(index, identifier)
clearCell(index)

constructor(gridSize)

Factions.nut

Allows creating factions and relations between them

Code:
isEnemyNameFaction(name)
isEnemyFaction(fac)
addEnemyFaction(fac)
getFaction(name)
areFactionsEnemies(fac1, fac2)
getName()
getEnemyFactions()

constructor(name)

RealTimeEvent.nut

Static class that allows creating events that are executed at a given real world time. For example: replenish appletree after 10 hours, save serverstate every hour.

Code:
add(date, function, reschedule, repeat)
remove(tag)
check()




Download

Repository


RE: [0.1.3] [client/server] Squirrel Utility Scripts - HammelGammel - 27.01.2018

Update with a bunch of fixes