Documentation ¶
Overview ¶
Package ns implements NoxScript 4 used in OpenNox maps.
NS4 is based on NoxScript 3 but provides a more Go-friendly object-oriented API.
These changes include:
- Most functions became methods on the corresponding object types. - Functions have a more generic signature, using interfaces where appropriate. - Similar methods were renamed, e.g. ObjectOn and WaypointOn is now called Enable for both types. - Type safety was improved. Package defines more names types for enums. - All enum constants were moved to their own sub-packages.
Package is compatible with NS3: methods like AsObj convert NS3 objects into NS4 objects.
Index ¶
- Constants
- func AudioEvent(audio audio.Name, p Positioner)
- func AutoSave()
- func BecomeEnemy(obj Obj)
- func BecomePet(obj Obj)
- func Blind()
- func CancelDialog(obj Obj)
- func CastSpell(spell spell.Spell, source, target Positioner)
- func CastSpellLvl(spell spell.Spell, lvl int, source, target Positioner)
- func ClearMessages(player Obj)
- func DeathScreen(which int)
- func DestroyEveryChat()
- func Effect(effect effect.Effect, p1, p2 Positioner)
- func EndGame(class player.Class)
- func FindObjects(fnc func(it Obj) bool, conditions ...ObjCond) int
- func FindWalls(fnc func(it WallObj) bool, conditions ...WallCond) int
- func Frame() int
- func FrameRate() int
- func GetCharacterData(field int) int
- func GetQuestStatus(name string) int
- func GetQuestStatusFloat(name string) float32
- func ImmediateBlind()
- func IsCaller(obj Obj) bool
- func IsCrown(obj Obj) bool
- func IsGameBall(obj Obj) bool
- func IsSummoned(obj Obj) bool
- func IsTalking() bool
- func IsTrading() bool
- func IsTrigger(obj Obj) bool
- func JournalDelete(obj Obj, message StringID)
- func JournalDeleteStr(obj Obj, message string)
- func JournalEdit(obj Obj, message StringID, typ EntryType)
- func JournalEditStr(obj Obj, message string, typ EntryType)
- func JournalEntry(obj Obj, message StringID, typ EntryType)
- func JournalEntryStr(obj Obj, message string, typ EntryType)
- func LoadMap(name string, opts *LoadMapOptions)
- func MakeEnemy(obj Obj)
- func MakeFriendly(obj Obj)
- func Music(music int, volume int)
- func MusicEvent()
- func MusicPopEvent()
- func MusicPushEvent()
- func NoWallSound(noWallSound bool)
- func Now() time.Duration
- func OnChat(fnc ChatFunc)
- func OnEachFrame(each int, fnc FrameFunc)
- func OnFrame(fnc FrameFunc)
- func OnMapEvent(typ MapEvent, fnc MapEventFunc)
- func OnPlayerDeath(fnc PlayerDeathFunc)
- func OnPlayerJoin(fnc PlayerJoinFunc)
- func OnPlayerLeave(fnc PlayerLeaveFunc)
- func Print(message StringID)
- func PrintStr(message string)
- func PrintStrToAll(message string)
- func PrintToAll(message StringID)
- func Random(min int, max int) int
- func RandomFloat(min float32, max float32) float32
- func ResetQuestStatus(name string)
- func SetDialog(obj Obj, typ DialogType, start Func, end Func)
- func SetHalberd(upgrade HalberdLevel)
- func SetQuestStatus(status int, name string)
- func SetQuestStatusFloat(status float32, name string)
- func SetRuntime(r Implementation)
- func SetShopkeeperText(obj Obj, text StringID)
- func SetShopkeeperTextStr(obj Obj, text string)
- func StartDialog(obj Obj, other Obj)
- func StartupScreen(which int)
- func StopScript(value any)
- func StoryPic(obj Obj, name string)
- func TellStory(audio audio.Name, story StringID)
- func TellStoryStr(audio audio.Name, story string)
- func UnBlind()
- func Unknownb8(id int) bool
- func Unknownb9(id int) bool
- func Unknownc4()
- func Unused1f(id int)
- func Unused20(id int)
- func Unused50()
- func Unused58(arg1 int, arg2 int)
- func Unused59(arg1 int, arg2 int)
- func Unused5a(arg1 int, arg2 int)
- func Unused5b(arg1 int, arg2 int)
- func Unused5c(arg1 int, arg2 int)
- func Unused5d(arg1 int, arg2 int)
- func Unused5e(str string) int
- func Unused74(arg1 int, arg2 int)
- func WideScreen(enable bool)
- func WithRuntime(ctx context.Context, g Implementation) context.Context
- type AND
- type ChatFunc
- type Color
- type DialogAnswer
- type DialogType
- type Direction
- type Duration
- func (d Duration) Add(d2 Duration) Duration
- func (d Duration) Frames() (int, bool)
- func (d Duration) IsFrames() bool
- func (d Duration) IsInfinite() bool
- func (d Duration) IsTime() bool
- func (d Duration) LessOrEq(d2 Duration) bool
- func (d Duration) Sub(d2 Duration) Duration
- func (d Duration) Time() (time.Duration, bool)
- type EntryType
- type EqualClass
- type FrameFunc
- type Func
- type Game
- type HalberdLevel
- type Handle
- type HasAllClasses
- type HasAllObjFlags
- type HasClass
- type HasObjFlags
- type HasTeam
- type HasType
- type HasTypeName
- type HasWallFlags
- type Implementation
- type InCirclef
- type InRectf
- type LoadMapOptions
- type MapEvent
- type MapEventFunc
- type NOT
- type OR
- type Obj
- func AsObj(h ObjHandle) Obj
- func CreateGold(pos Positioner, amount int) Obj
- func CreateGoldChest(pos Positioner, amount int) Obj
- func CreateGoldPile(pos Positioner, amount int) Obj
- func CreateObject(typ ObjTypeName, pos Positioner) Obj
- func FindAllObjects(conditions ...ObjCond) []Obj
- func FindAllObjectsIn(s ObjSearcher, conditions ...ObjCond) []Obj
- func FindClosestObject(from Positioner, conditions ...ObjCond) Obj
- func FindClosestObjectIn(from Positioner, s ObjSearcher, conditions ...ObjCond) Obj
- func FindObject(conditions ...ObjCond) Obj
- func FindObjectIn(s ObjSearcher, conditions ...ObjCond) Obj
- func GetCaller() Obj
- func GetHost() Obj
- func GetTrigger() Obj
- func NewAbilityBook(pos Positioner, abil abil.Ability) Obj
- func NewEnchantUseItem(typ ObjTypeName, pos Positioner, enc enchant.Enchant, dur Duration) Obj
- func NewFieldGuide(pos Positioner, creature ObjTypeName) Obj
- func NewGold(pos Positioner, amount int) Obj
- func NewGoldChest(pos Positioner, amount int) Obj
- func NewGoldPile(pos Positioner, amount int) Obj
- func NewHealthPotion(pos Positioner, amount int) Obj
- func NewManaPotion(pos Positioner, amount int) Obj
- func NewSpellBook(pos Positioner, spell spell.Spell) Obj
- func NewSpellUseItem(typ ObjTypeName, pos Positioner, spell spell.Spell, lvl int) Obj
- func NewTrap(pos Positioner, spells ...spell.Spell) Obj
- func NewTrapAdv(pos Positioner, spells []TrapSpell) Obj
- func Object(name string) Obj
- type ObjCond
- type ObjCondFunc
- type ObjGroup
- type ObjGroupHandle
- type ObjHandle
- type ObjSearcher
- type ObjType
- type ObjTypeName
- type ObjectEvent
- type Objects
- type Persistent
- type Player
- type PlayerDeathFunc
- type PlayerJoinFunc
- type PlayerLeaveFunc
- type Point
- type Pointf
- type Positioner
- type Session
- type Storage
- type StorageType
- type StringID
- type Team
- type TimeSource
- type Timer
- type TimerHandle
- type TrapSpell
- type WallCond
- type WallGroupHandle
- type WallGroupObj
- type WallHandle
- type WallObj
- func AsWall(h WallHandle) WallObj
- func FindAllWalls(conditions ...WallCond) []WallObj
- func FindAllWallsIn(s WallSearcher, conditions ...WallCond) []WallObj
- func FindClosestWall(from Positioner, conditions ...WallCond) WallObj
- func FindClosestWallIn(from Positioner, s WallSearcher, conditions ...WallCond) WallObj
- func FindWall(conditions ...WallCond) WallObj
- func FindWallIn(s WallSearcher, conditions ...WallCond) WallObj
- func Wall(x int, y int) WallObj
- type WallSearcher
- type WaypointGroupHandle
- type WaypointGroupObj
- type WaypointHandle
- type WaypointObj
Constants ¶
const ( DialogNormal = DialogType("NORMAL") DialogNext = DialogType("NEXT") DialogYesNo = DialogType("YESNO") DialogYesNoNext = DialogType("YESNONEXT") DialogFalse = DialogType("FALSE") )
const ( AnswerGoodbye = DialogAnswer(0) AnswerYes = DialogAnswer(1) AnswerNo = DialogAnswer(2) )
const ( EventEnemySighted = ObjectEvent(3) EventLookingForEnemy = ObjectEvent(4) EventDeath = ObjectEvent(5) EventChangeFocus = ObjectEvent(6) EventIsHit = ObjectEvent(7) EventRetreat = ObjectEvent(8) EventCollision = ObjectEvent(9) EventEnemyHeard = ObjectEvent(10) EventEndOfWaypoint = ObjectEvent(11) EventLostEnemy = ObjectEvent(13) )
const ( OblivionHalberd = HalberdLevel(0) OblivionHeart = HalberdLevel(1) OblivionWierdling = HalberdLevel(2) OblivionOrb = HalberdLevel(3) )
const ( EntryGreen1 = EntryType(0) // green text, no sound EntryWhite = EntryType(1) // white text EntryRed = EntryType(2) // red text with quest label EntryGreen2 = EntryType(3) // green text EntryGrey = EntryType(4) // grey text with completed label EntryYellow = EntryType(8) // yellow text with hint label )
const ( MapInitialize = MapEvent(iota + 1) MapEntry MapExit MapShutdown )
Variables ¶
This section is empty.
Functions ¶
func AudioEvent ¶
func AudioEvent(audio audio.Name, p Positioner)
AudioEvent play an audio event at a location.
func CastSpell ¶
func CastSpell(spell spell.Spell, source, target Positioner)
CastSpell casts a spell from source to target.
Example:
ns.CastSpell(spell.DEATH_RAY, ns.Object("CruelDude"), ns.GetHost()) ns.CastSpell(spell.DEATH_RAY, ns.Ptf(10, 5), ns.Waypoint("Target"))
func CastSpellLvl ¶
func CastSpellLvl(spell spell.Spell, lvl int, source, target Positioner)
CastSpellLvl casts a spell from source to target with a given level.
Example:
ns.CastSpell(spell.DEATH_RAY, 1, ns.Object("CruelDude"), ns.GetHost()) ns.CastSpell(spell.DEATH_RAY, 3, ns.Ptf(10, 5), ns.Waypoint("Target"))
func ClearMessages ¶
func ClearMessages(player Obj)
ClearMessages clears messages on player's screen.
func Effect ¶
func Effect(effect effect.Effect, p1, p2 Positioner)
Effect triggers an effect from point p1 to p2. Some effects only have one point, in which case p2 is ignored.
func FindObjects ¶
FindObjects calls fnc for all map objects matching all the conditions. It returns a number of objects matched. If fnc returns false, the function stops the search. If fnc is nil, the function only counts a number of objects matching a condition.
Example:
// Find and damage all monsters in a 100px circle around obj. ns.FindObjects( func(it ns.Obj) bool { it.Damage(obj, 10, damage.FLAME) return true }, ns.InCirclef{Center: obj, R: 100}, ns.HasClass(object.ClassMonster), )
func FindWalls ¶
FindWalls calls fnc for all map walls matching all the conditions. It returns a number of walls matched. If fnc returns false, the function stops the search. If fnc is nil, the function only counts a number of walls matching a condition.
Example:
// Find and disable walls with a window in a 100px circle around obj. g.FindWalls( func(it ns.WallObj) bool { it.Enable(false) return true }, ns.InCirclef{Center: obj, R: 100}, ns.HasWallFlags(ns.WallFlagWindow), )
func FrameRate ¶
func FrameRate() int
FrameRate returns current server update rate (aka server frame rate).
func GetCharacterData ¶
GetCharacterData gets information about the loaded character.
func GetQuestStatusFloat ¶
GetQuestStatusFloat gets quest status (float).
func IsSummoned ¶
IsSummoned gets whether object is a summoned creature.
func IsTrading ¶
func IsTrading() bool
IsTrading returns whether the host is currently talking to shopkeeper.
func JournalDelete ¶
JournalDelete deletes entry from player's journal.
If the player object is nil, then it will delete the journal entry for all players.
func JournalDeleteStr ¶
JournalDeleteStr deletes entry from player's journal. It does not localize the string.
If the player object is nil, then it will delete the journal entry for all players.
func JournalEdit ¶
JournalEdit edits entry in player's journal.
If the player object is nil, then it will edit the journal entry for all players.
func JournalEditStr ¶
JournalEditStr edits entry in player's journal. It does not localize the string.
If the player object is nil, then it will edit the journal entry for all players.
func JournalEntry ¶
JournalEntry adds entry to player's journal.
If the player object is nil, then it will add the journal entry to all players.
func JournalEntryStr ¶
JournalEntryStr adds entry to player's journal. It does not localize the string.
If the player object is nil, then it will add the journal entry to all players.
func LoadMap ¶
func LoadMap(name string, opts *LoadMapOptions)
LoadMap loads a map with a given name and options. Name should not contain .map suffix or any other path elements.
func MusicEvent ¶
func MusicEvent()
func MusicPopEvent ¶
func MusicPopEvent()
func MusicPushEvent ¶
func MusicPushEvent()
func OnChat ¶
func OnChat(fnc ChatFunc)
OnChat registers a callback function that will be called when each chat message is received. See ChatFunc for details.
func OnEachFrame ¶
OnEachFrame registers a callback function that will be called each N-th server frame. See FrameFunc for details.
func OnFrame ¶
func OnFrame(fnc FrameFunc)
OnFrame registers a callback function that will be called each server frame. See FrameFunc for details.
func OnMapEvent ¶
func OnMapEvent(typ MapEvent, fnc MapEventFunc)
OnMapEvent registers a callback function that will be called each server map event.
See MapEvent for a list of events and MapEventFunc for callback type.
func OnPlayerDeath ¶
func OnPlayerDeath(fnc PlayerDeathFunc)
OnPlayerDeath registers a callback function that will be called when player dies.
func OnPlayerJoin ¶
func OnPlayerJoin(fnc PlayerJoinFunc)
OnPlayerJoin registers a callback function that will be called when player joins the server.
func OnPlayerLeave ¶
func OnPlayerLeave(fnc PlayerLeaveFunc)
OnPlayerLeave registers a callback function that will be called when player leaves the server.
func Print ¶
func Print(message StringID)
Print displays a localized string on the screen of Other.
If the string is not in the string database, it will instead print an error message with "MISSING:".
func PrintStr ¶
func PrintStr(message string)
PrintStr displays a string on the screen of Other. It does not localize the string.
func PrintStrToAll ¶
func PrintStrToAll(message string)
PrintStrToAll displays a string to everyone. It does not localize the string.
func PrintToAll ¶
func PrintToAll(message StringID)
PrintToAll displays a localized string to everyone.
If the string is not in the string database, it will instead print an error message with "MISSING:".
func RandomFloat ¶
RandomFloat generates random float.
func ResetQuestStatus ¶
func ResetQuestStatus(name string)
ResetQuestStatus deletes a quest status.
The name can be a wildcard with an asterisk or with a map name.
func SetDialog ¶
func SetDialog(obj Obj, typ DialogType, start Func, end Func)
SetDialog sets up a conversation with object.
The type of conversation is one of: DialogNormal, DialogNext, DialogYesNo, DialogYesNoNext. The start and end are script functions that are called at the start and end of the conversation.
If using a DialogYesNo conversation, the end script function should use GetAnswer to retrieve the result.
func SetQuestStatus ¶
SetQuestStatus sets quest status (int).
func SetQuestStatusFloat ¶
SetQuestStatusFloat sets quest status (float).
func SetRuntime ¶
func SetRuntime(r Implementation)
SetRuntime is used by the script host to bind runtime for the script package. Scripts must not call this functions.
func SetShopkeeperText ¶
SetShopkeeperText sets localized shopkeeper text.
func SetShopkeeperTextStr ¶
SetShopkeeperTextStr sets shopkeeper text. It does not localize the string.
func StartDialog ¶
StartDialog starts a conversation between two objects.
This requires that SetDialog has already been used to set up the conversation on the object.
func TellStory ¶
TellStory causes the telling of a story.
This will cause a story to be told. It relies on Self and Other to be particular values, which limits this to being used in the SetDialog callbacks.
Example:
TellStory(audio.SwordsmanHurt, "Con05:OgreTalk07")
func TellStoryStr ¶
TellStoryStr causes the telling of a story. It does not localize the string.
This will cause a story to be told. It relies on Self and Other to be particular values, which limits this to being used in the SetDialog callbacks.
Example:
TellStoryStr(audio.SwordsmanHurt, "Hello there!")
func WideScreen ¶
func WideScreen(enable bool)
WideScreen enables or disables cinematic wide-screen effect.
func WithRuntime ¶
func WithRuntime(ctx context.Context, g Implementation) context.Context
WithRuntime stores Implementation in the context.
Types ¶
type ChatFunc ¶
ChatFunc is a callback type for OnChat. It returns a modified message. If message is empty, it will be ignored (muted).
A nil player will be passed to the callback for non-player messages (e.g. ones sent via Obj.Chat).
For team chat a team will be passed to the callback. It will be nil for regular chat.
type DialogAnswer ¶
type DialogAnswer int
type DialogType ¶
type DialogType string
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration for script events.
It's separate from time.Duration because it can be expressed in game frames.
func NowWithSource ¶
func NowWithSource(s TimeSource) Duration
NowWithSource returns current timestamp of the time source.
func (Duration) IsInfinite ¶
IsInfinite checks if duration is infinite.
type EqualClass ¶
EqualClass checks that class of object exactly matches this value.
func (EqualClass) Matches ¶
func (c EqualClass) Matches(obj Obj) bool
type Game ¶
type Game interface { // NoxScript returns implementation of NoxScript runtime. NoxScript() Implementation }
Game is an optional interface for the engine that exposes NoxScript runtime.
type HalberdLevel ¶
type HalberdLevel int
type Handle ¶
type Handle interface { // ScriptID returns internal script ID for the object. ScriptID() int }
type HasAllClasses ¶
HasAllClasses checks that class of object matches all of provided classes.
func (HasAllClasses) Matches ¶
func (c HasAllClasses) Matches(obj Obj) bool
type HasAllObjFlags ¶
HasAllObjFlags checks that object's flags match all of provided flags.
func (HasAllObjFlags) Matches ¶
func (c HasAllObjFlags) Matches(obj Obj) bool
type HasObjFlags ¶
HasObjFlags checks that object's flags match any of provided flags.
func (HasObjFlags) Matches ¶
func (c HasObjFlags) Matches(obj Obj) bool
type HasTypeName ¶
type HasTypeName []ObjTypeName
HasTypeName checks that object matches any of provided type names.
func (HasTypeName) Matches ¶
func (arr HasTypeName) Matches(obj Obj) bool
type HasWallFlags ¶
HasWallFlags checks that wall's flags match any of provided flags.
func (HasWallFlags) WallMatches ¶
func (c HasWallFlags) WallMatches(obj WallObj) bool
type Implementation ¶
type Implementation interface { TimeSource FrameRate() int Store(typ StorageType) Storage TimerByHandle(h TimerHandle) Timer NewTimer(dt Duration, fnc Func, args ...any) Timer RandomFloat(min float32, max float32) float32 Random(min int, max int) int StopScript(value any) AutoSave() StartupScreen(which int) DeathScreen(which int) ObjectType(name ObjTypeName) ObjType ObjectTypeByInd(ind int) ObjType ObjectByHandle(h ObjHandle) Obj Object(name string) Obj ObjectGroupByHandle(h ObjGroupHandle) ObjGroup ObjectGroup(name string) ObjGroup CreateObject(typ ObjTypeName, pos Positioner) Obj ObjSearcher GetTrigger() Obj GetCaller() Obj GetHost() Obj IsTrigger(obj Obj) bool IsCaller(obj Obj) bool IsGameBall(obj Obj) bool IsCrown(obj Obj) bool IsSummoned(obj Obj) bool MakeFriendly(obj Obj) MakeEnemy(obj Obj) BecomePet(obj Obj) BecomeEnemy(obj Obj) Teams() []Team HostPlayer() Player Players() []Player GetCharacterData(field int) int Print(message StringID) PrintStr(message string) PrintToAll(message StringID) PrintStrToAll(message string) ClearMessages(player Obj) UnBlind() Blind() ImmediateBlind() WideScreen(enable bool) IsTalking() bool IsTrading() bool SetHalberd(upgrade HalberdLevel) EndGame(class player.Class) DestroyEveryChat() SetShopkeeperText(obj Obj, text StringID) SetShopkeeperTextStr(obj Obj, text string) SetDialog(obj Obj, typ DialogType, start Func, end Func) CancelDialog(obj Obj) StoryPic(obj Obj, name string) TellStory(audio audio.Name, story StringID) TellStoryStr(audio audio.Name, story string) StartDialog(obj Obj, other Obj) GetAnswer(obj Obj) DialogAnswer AudioEvent(audio audio.Name, p Positioner) Music(music int, volume int) MusicPushEvent() MusicPopEvent() MusicEvent() Effect(effect effect.Effect, p1, p2 Positioner) CastSpell(spell spell.Spell, source, target Positioner) CastSpellLvl(spell spell.Spell, lvl int, source, target Positioner) NewTrap(pos Positioner, spells []TrapSpell) Obj NewHealthPotion(pos Positioner, health int) Obj NewManaPotion(pos Positioner, mana int) Obj NewSpellBook(pos Positioner, spell spell.Spell) Obj NewAbilityBook(pos Positioner, abil abil.Ability) Obj NewFieldGuide(pos Positioner, creature string) Obj NewEnchantUseItem(typ ObjTypeName, pos Positioner, enc enchant.Enchant, dur Duration) Obj NewSpellUseItem(typ ObjTypeName, pos Positioner, spell spell.Spell, lvl int) Obj GetQuestStatus(name string) int GetQuestStatusFloat(name string) float32 SetQuestStatus(status int, name string) SetQuestStatusFloat(status float32, name string) ResetQuestStatus(name string) JournalEntry(obj Obj, message StringID, typ EntryType) JournalEdit(obj Obj, message StringID, typ EntryType) JournalDelete(obj Obj, message StringID) JournalEntryStr(obj Obj, message string, typ EntryType) JournalEditStr(obj Obj, message string, typ EntryType) JournalDeleteStr(obj Obj, message string) Waypoints() []WaypointObj WaypointByHandle(h WaypointHandle) WaypointObj Waypoint(name string) WaypointObj NewWaypoint(name string, pos Pointf) WaypointObj WaypointGroupByHandle(h WaypointGroupHandle) WaypointGroupObj WaypointGroup(name string) WaypointGroupObj NoWallSound(noWallSound bool) WallByHandle(h WallHandle) WallObj Wall(x int, y int) WallObj WallGroupByHandle(h WallGroupHandle) WallGroupObj WallGroup(name string) WallGroupObj FindWalls(fnc func(it WallObj) bool, conditions ...WallCond) int LoadMap(name string, opts *LoadMapOptions) OnFrame(fnc FrameFunc) OnMapEvent(typ MapEvent, fnc MapEventFunc) OnChat(fnc ChatFunc) OnPlayerJoin(fnc PlayerJoinFunc) OnPlayerLeave(fnc PlayerLeaveFunc) OnPlayerDeath(fnc PlayerDeathFunc) Unused1f(id int) Unused20(id int) Unused50() Unused58(arg1 int, arg2 int) Unused59(arg1 int, arg2 int) Unused5a(arg1 int, arg2 int) Unused5b(arg1 int, arg2 int) Unused5c(arg1 int, arg2 int) Unused5d(arg1 int, arg2 int) Unused5e(str string) int Unused74(arg1 int, arg2 int) Unknownb8(id int) bool Unknownb9(id int) bool Unknownc4() }
Implementation of the script runtime. Only used in the engine itself.
func GetRuntime ¶
func GetRuntime(ctx context.Context) Implementation
GetRuntime loads Implementation from the context.
func Runtime ¶
func Runtime() Implementation
Runtime returns implementation of all the accessible functions as an interface.
type InCirclef ¶
type InCirclef struct { Center Positioner R float64 }
InCirclef filters objects that are inside a circle on the map.
func (InCirclef) WallMatches ¶
type InRectf ¶
type InRectf struct {
Min, Max Pointf
}
InRectf filters objects that are inside a given map rectangle.
func (InRectf) WallMatches ¶
type LoadMapOptions ¶
type LoadMapOptions struct { // IgnoreMapType allows bypassing regular map loading rules. // Setting this allows loading maps with a different game mode, switching to/from solo maps, etc. IgnoreMapType bool // HideScores hides scores screen when switching from Quest or other similar map. HideScores bool // HideTitleScreen hides boot/title screen of the map when loading it. HideTitleScreen bool }
LoadMapOptions is a set of options for LoadMap.
type NOT ¶
type NOT struct {
Cond ObjCond
}
NOT matches an object if any other condition returns false.
type Obj ¶
type Obj interface { ObjHandle // Type returns object type. Type() ObjType // Pos returns current position of the object. Pos() Pointf // SetPos instantly moves object to a given position. SetPos(p Pointf) // Z returns current Z offset for the object. Z() float32 // SetZ sets Z offset for the object. SetZ(z float32) // Vel returns current velocity of the object. Vel() Pointf // IsEnabled checks if object is currently enabled. IsEnabled() bool // Enable or disable the object. Enable(enable bool) // Toggle the object's enabled state. // It returns the new state after toggling the object. Toggle() bool // IsLocked checks if object is currently locked. IsLocked() bool // Lock or unlock the object. Lock(lock bool) // Class returns object class. Class() object.Class // HasClass checks whether object has a class. // It uses string values instead of enum as Class does. HasClass(class class.Class) bool // HasSubclass tests whether an object has a specific subclass. // The subclass overlaps, so you should probably test for the class first (via HasClass). HasSubclass(subclass subclass.SubClass) bool // Flags returns object flags. Flags() object.Flags // SetFlags sets object flags to the given value. // For switching individual flags see FlagsEnable and FlagsDisable. SetFlags(v object.Flags) // FlagsEnable enables specific object flags. FlagsEnable(v object.Flags) // FlagsDisable disables specific object flags. FlagsDisable(v object.Flags) // HasTeam checks if an object belongs to a team. HasTeam(t Team) bool // Team returns current team of an object, if any. Team() Team // SetTeam sets team of an object. SetTeam(t Team) // DisplayName returns current display name for an object (if any). DisplayName() string // SetDisplayName sets a display name for an object, with an optional color. // Passing nil color resets it to a default value. SetDisplayName(name string, cl Color) // MonsterStatus returns monster/NPC status flags. // It returns 0 if object's class is not a monster/NPC. MonsterStatus() object.MonsterStatus // SetMonsterStatus sets monster status flags to the given value. // For switching individual statuses see MonsterStatusEnable and MonsterStatusDisable. // It does nothing if object's class is not a monster/NPC. SetMonsterStatus(v object.MonsterStatus) // MonsterStatusEnable enables specific monster status flags. // It does nothing if object's class is not a monster/NPC. MonsterStatusEnable(v object.MonsterStatus) // MonsterStatusDisable disables specific monster status flags. // It does nothing if object's class is not a monster/NPC. MonsterStatusDisable(v object.MonsterStatus) // HasEnchant gets whether object has an enchant. HasEnchant(enchant enchant.Enchant) bool // Direction gets object direction. // // See LookWithAngle. Direction() Direction // CursorPos returns aim cursor position for the object. Only valid for players. CursorPos() types.Pointf // CursorObj returns target under the aim cursor for the object. Only valid for players. CursorObj() Obj // CurrentHealth gets object's health. CurrentHealth() int // MaxHealth gets object's maximum health. MaxHealth() int // RestoreHealth restores object's health. RestoreHealth(amount int) // SetHealth sets current object health. SetHealth(v int) // SetMaxHealth sets maximum object health. SetMaxHealth(v int) // CurrentMana gets object's mana. Only works on players. CurrentMana() int // MaxMana gets object's maximum mana. Only works on players. MaxMana() int // SetMana sets current object mana. Only works on players. SetMana(v int) // SetMaxMana sets maximum object mana. Only works on players. SetMaxMana(v int) // SetHealthRegenToMaxDur sets "classical" health regen for an object. // It will restore a percent of the health each frame, so that full health can be restored in a given time interval. // // Setting it to -1 restores the default. // // To disable regeneration completely, use SetHealthRegenPerFrame(0). SetHealthRegenToMaxDur(t time.Duration) // SetHealthRegenPerFrame sets per-frame health regen for an object. // Each frame a given amount of health will be restored. // // To disable health regen, set it to 0. // // To use "classic" health regen, set it to -1. SetHealthRegenPerFrame(v float32) // Mass of the object. Mass() float32 // SetMass sets mass of the object. SetMass(v float32) // CurrentSpeed returns current speed of the object. CurrentSpeed() float32 // BaseSpeed returns base speed of the object. BaseSpeed() float32 // SetBaseSpeed sets base speed of the object. SetBaseSpeed(v float32) // Strength returns strength of the unit. Strength() int // SetStrength sets strength of the unit. SetStrength(v int) // SetColor sets NPC or player color, given its index. // // Example: // // obj.SetColor(0, ns.RGB(80, 0, 0)) // dark red SetColor(ind int, cl Color) // GetGold gets amount of gold for object. GetGold() int // SetGold sets amount of gold for object. SetGold(amount int) // ChangeGold changes amount of gold for object. ChangeGold(delta int) // GiveXp grants experience to a player. GiveXp(xp float32) // GetLevel gets player's level. GetLevel() int // GetClass gets player's character class. GetClass() player.Class // Player returns player associated with the object. Player() Player // GetScore gets player's score. // // Deprecated: use Player.GetScore. GetScore() int // ChangeScore changes player's score. // // Deprecated: use Player.ChangeScore. ChangeScore(score int) // HasOwner checks whether target is owned by object. HasOwner(owner Obj) bool // HasOwnerIn checks whether target is owned by any object in the group. HasOwnerIn(owners ObjGroup) bool // SetOwner makes an object the owner of the target. This will make the target // friendly to the owner, and it will accredit the target's kills to the owner. // // Passing nil will clear the owner. // // For example, in a multiplayer map, you might have a switch that activates a // hazard. You can use this so that if the hazard kills anyone, the player who // activated the hazard gets the credit. SetOwner(owner Obj) // SetOwners is the same as SetOwner but with an object group as the owner. SetOwners(owners ObjGroup) // Freeze or unfreeze an object in place. Freeze(freeze bool) // Pause an object temporarily. Pause(dt Duration) // Move an object to a waypoint. The object must be movable or attached to a "Mover". // // If the waypoint is linked, the object will continue to move once it reaches the first waypoint. Move(wp WaypointObj) // WalkTo causes an object to walk to a location. WalkTo(p Pointf) // LookAtDirection causes object to look in a direction. LookAtDirection(dir Direction) // LookWithAngle sets an object's direction. The direction is an angle represented as an integer between 0 and 255. // Due east is 0, and the angle increases as the object turns clock-wise. LookWithAngle(angle int) // LookAtObject sets direction of object so it is looking at another object. LookAtObject(target Positioner) // CanSee first checks if the location of the objects are within 512 of each other coordinate-wise. It not, it returns false. // // It then checks whether the first object can see the second object. CanSee(obj Obj) bool // ApplyForce applies a force vector to an object. ApplyForce(force Pointf) // PushTo calculate a unit vector from the object's location to the specified // location, and multiply it by the specified magnitude. This vector will be // applied as a force via ApplyForce. PushTo(pos Positioner, force float32) // Damage the target with a given source object, amount, and damage type. Damage(source Obj, amount int, typ damage.Type) bool // Delete an object. Delete() // DeleteAfter delete object after a delay. DeleteAfter(dt Duration) // Idle causes creature to idle. Idle() // Wander causes an object to wander. Wander() // Hunt causes creature to hunt. Hunt() // Return cause object to move to its starting location. Return() // Follow causes a creature to follow target, and it won't attack anything unless disrupted or instructed to. Follow(target Positioner) // Guard causes a creature to move to a location, guard a nearby location, // and attack any enemies that move within range of the guarded location. Guard(p1, p2 Pointf, distance float32) // Attack a target. Attack(target Positioner) // IsAttackedBy gets whether object is being attacked by another object. IsAttackedBy(by Obj) bool // HitMelee causes object to melee attacks a location. HitMelee(p Pointf) // HitRanged causes object to ranged attacks a location. HitRanged(p Pointf) // Flee causes creature to run away from target. Flee(target Positioner, dt Duration) // HasItem gets whether this specific item is in the object's inventory. // For searching items by object type or other properties, see InItems().FindObjects(...). HasItem(item Obj) bool // HasEquipment gets whether this specific item is in the object's inventory and is equipped. // For searching items by object type or other properties, see InEquipment().FindObjects(...). HasEquipment(item Obj) bool // FindItems calls fnc for all items matching all the conditions. // It returns a number of items matched. If fnc returns false, the function stops the search. // If fnc is nil, the function only counts a number of objects matching a condition. // // Example: // // // Check if unit has at least one apple // if obj.FindItems(nil, ns.HasTypeName{"RedApple"}) != 0 { // fmt.Println("Has an apple!") // } // // // Drop all armor // obj.FindItems( // func(it ns.Obj) { // obj.Drop(it) // return true // }, // ns.EqualClass(object.ClassArmor), // ) // // Deprecated: use InItems().FindObjects(...) FindItems(fnc func(obj Obj) bool, conditions ...ObjCond) int // GetLastItem returns the object of the last item in the object's inventory. If the inventory is empty, it returns nil. // // This is used with GetPreviousItem to iterate through an object's inventory. // // Deprecated: Use Items instead. // // Example: // // for it := obj.GetLastItem(); it != nil; it = it.GetPreviousItem() { // // ... // } GetLastItem() Obj // GetPreviousItem returns the object of the previous item in the inventory from the given object. // If the specified object is not in an inventory, or there are no more items in the inventory, it returns nil. // // This is used with GetLastItem to iterate through an object's inventory. // // Deprecated: Use Items instead. GetPreviousItem() Obj // Items returns all items in the object's inventory. // An optional list of conditions can be specified for filtering returned items. // // Resulting slice is read-only, changes to it won't be reflected on the object. // Use Pickup or Drop for adding or removing items. Items(conditions ...ObjCond) []Obj // Equipment returns all equipped items in the object's inventory. // An optional list of conditions can be specified for filtering returned items. // // Resulting slice is read-only, changes to it won't be reflected on the object. // Use Equip or Unequip for changing equipment. Equipment(conditions ...ObjCond) []Obj // InItems returns an ObjSearcher that can be used in FindObjectIn and FindAllObjectsIn or searched directly. // // Calling InItems().FindObjects() will call fnc for all items matching all the conditions. // It returns a number of items matched. If fnc returns false, the function stops the search. // If fnc is nil, the function only counts a number of objects matching a condition. // // Example: // // // Check if unit has at least one apple // if obj.InItems().FindObjects(nil, ns.HasTypeName{"RedApple"}) != 0 { // fmt.Println("Has an apple!") // } // // // Drop all armor // obj.InItems().FindObjects( // func(it ns.Obj) { // obj.Drop(it) // return true // }, // ns.EqualClass(object.ClassArmor), // ) InItems() ObjSearcher // InEquipment returns an ObjSearcher that can be used in FindObjectIn and FindAllObjectsIn or searched directly. // // Calling InEquipment().FindObjects() will call fnc for all equipped items matching all the conditions. // It returns a number of items matched. If fnc returns false, the function stops the search. // If fnc is nil, the function only counts a number of objects matching a condition. // // Example: // // // Check if unit has sword equipped // if obj.InEquipment().FindObjects(nil, ns.HasTypeName{"Sword"}) != 0 { // fmt.Println("Has an apple!") // } // // // Drop all equipped armor // obj.InEquipment().FindObjects( // func(it ns.Obj) { // obj.Drop(it) // return true // }, // ns.EqualClass(object.ClassArmor), // ) InEquipment() ObjSearcher // GetHolder returns the object that contains the item in its inventory. GetHolder() Obj // Pickup cause object to pick up an item. // // Returns false if object cannot pick up the item. Pickup(item Obj) bool // Drop cause object to drop an item. // // Returns false if object cannot drop the item. Drop(item Obj) bool // Equip cause object to equip an item. // // If an item is not in object's inventory, it will be transferred to it. // // Returns false if object cannot pick up or equip the item. Equip(item Obj) bool // Unequip cause object to unequip an item. // // If an item is not in object's inventory, it will do nothing. // // Returns false if object cannot unequip the item. Unequip(item Obj) bool // ZombieStayDown sets zombie to stay down. ZombieStayDown() // RaiseZombie raises a zombie. Also clears stay down state. RaiseZombie() // Chat displays a localized string in a speech bubble. // // If the string is not in the string database, it will instead print an error message with "MISSING:". Chat(message StringID) // ChatTimer displays a localized string in a speech bubble for a given duration (in seconds or frames). // // If the string is not in the string database, it will instead print an error message with "MISSING:". ChatTimer(message StringID, dt Duration) // ChatStr displays a string in a speech bubble. // It does not localize the string. ChatStr(message string) // ChatStrTimer displays a string in a speech bubble for a given duration (in seconds or frames). // It does not localize the string. ChatStrTimer(message string, dt Duration) // SetShopText sets shopkeeper test for this object. SetShopText(message StringID) // DestroyChat destroys object's speech bubble. DestroyChat() // CreateMover creates a Mover for an object. CreateMover(wp WaypointObj, speed float32) Obj // GetElevatorStatus gets elevator status. GetElevatorStatus() int // SetSightRange sets a creature's sight level. Default value for NPCs is 150. SetSightRange(val float32) // Weight returns weight of this object when placed in the inventory. Weight() int // InventoryWeight returns total weight of all inventory items. InventoryWeight() int // CarryMaxWeight returns total items weight that an object can carry. CarryMaxWeight() int // SetCarryMaxWeight sets total items weight that an object can carry. SetCarryMaxWeight(v int) // AggressionLevel sets a creature's aggression level. The most commonly used value is 0.83. AggressionLevel(level float32) // SetRoamFlag sets roaming flags for object. Default is 0x80. SetRoamFlag(flags int) // RetreatLevel causes the creature to retreat if its health falls below the specified percentage (0.0 - 1.0). RetreatLevel(percent float32) // ResumeLevel causes the creature to stop retreating if its health is above the specified percentage (0.0 - 1.0). ResumeLevel(percent float32) // AwardSpell awards spell level to object. // // This will raise the spell level of the object. // If the object can not cast this spell then it will have no effect. AwardSpell(spell spell.Spell) bool // Enchant grants object an enchantment of a specified duration. Enchant(enchant enchant.Enchant, dt Duration) // EnchantOff removes enchant from an object. EnchantOff(enchant enchant.Enchant) // TrapSpells sets spells on a bomber or a wizard trap. TrapSpells(spells ...spell.Spell) // TrapSpellsAdv sets spells on a bomber or a wizard trap. It's an advanced version of TrapSpells. TrapSpellsAdv(spells []TrapSpell) // OnEvent sets a function script to call for an event. // This function overrides previous event of the same type set on an object. OnEvent(event ObjectEvent, fnc Func) }
func CreateGold ¶ added in v4.24.0
func CreateGold(pos Positioner, amount int) Obj
CreateGold creates gold item with a given amount of gold.
func CreateGoldChest ¶ added in v4.24.0
func CreateGoldChest(pos Positioner, amount int) Obj
CreateGoldChest creates gold chest item with a given amount of gold.
func CreateGoldPile ¶ added in v4.24.0
func CreateGoldPile(pos Positioner, amount int) Obj
CreateGoldPile creates gold pile item with a given amount of gold.
func CreateObject ¶
func CreateObject(typ ObjTypeName, pos Positioner) Obj
CreateObject creates an object given a type and a starting location.
Example: spider := CreateObject("SmallAlbinoSpider", Waypoint("SpiderHole"))
func FindAllObjects ¶
FindAllObjects is similar to FindObjects, but returns all objects as an array/slice.
Example:
// Find and return all missiles in a 50px circle around obj. arr := ns.FindAllObjects( ns.InCirclef{Center: obj, R: 50}, ns.HasClass(object.ClassMissile), )
func FindAllObjectsIn ¶
func FindAllObjectsIn(s ObjSearcher, conditions ...ObjCond) []Obj
FindAllObjectsIn iterates over objects, and returns all matched objects as an array/slice.
Example:
// Find and return missiles in a 50px circle around obj. arr := ns.FindAllObjects(g, ns.InCirclef{Center: obj, R: 50}, ns.HasClass(object.ClassMissile), )
func FindClosestObject ¶
func FindClosestObject(from Positioner, conditions ...ObjCond) Obj
FindClosestObject searches the map for closest object that matches all conditions. If no objects are found, it returns nil.
Example:
// Find monster or player closest to obj. found := ns.FindClosestObject(obj, ns.HasClass(object.ClassMonster | object.ClassPlayer))
func FindClosestObjectIn ¶
func FindClosestObjectIn(from Positioner, s ObjSearcher, conditions ...ObjCond) Obj
FindClosestObjectIn searches the set for closest object that matches all conditions. If no objects are found, it returns nil.
Example:
// Find monster or player closest to obj. found := ns.FindClosestObjectIn(obj, g, ns.HasClass(object.ClassMonster | object.ClassPlayer))
func FindObject ¶
FindObject searches the map for any object that matches all conditions. If object is not found it returns nil.
Example:
// Find exit on the map. found := ns.FindObject(ns.EqualClass(object.ClassExit))
func FindObjectIn ¶
func FindObjectIn(s ObjSearcher, conditions ...ObjCond) Obj
FindObjectIn searches the set for any object that matches all conditions. If object is not found it returns nil.
Example:
// Find exit on the map. found := ns.FindObject(ns.EqualClass(object.ClassExit))
func GetCaller ¶
func GetCaller() Obj
GetCaller returns object that was the target of an event, if valid.
func GetTrigger ¶
func GetTrigger() Obj
GetTrigger returns object which triggered an event, if valid.
func NewAbilityBook ¶ added in v4.25.0
func NewAbilityBook(pos Positioner, abil abil.Ability) Obj
NewAbilityBook creates an ability book.
func NewEnchantUseItem ¶ added in v4.25.0
func NewEnchantUseItem(typ ObjTypeName, pos Positioner, enc enchant.Enchant, dur Duration) Obj
NewEnchantUseItem creates an item that applies an enchant on use.
func NewFieldGuide ¶ added in v4.25.0
func NewFieldGuide(pos Positioner, creature ObjTypeName) Obj
NewFieldGuide creates a field guide (beast scroll) for a given creature.
func NewGold ¶ added in v4.25.0
func NewGold(pos Positioner, amount int) Obj
NewGold creates gold item with a given amount of gold.
func NewGoldChest ¶ added in v4.25.0
func NewGoldChest(pos Positioner, amount int) Obj
NewGoldChest creates gold chest item with a given amount of gold.
func NewGoldPile ¶ added in v4.25.0
func NewGoldPile(pos Positioner, amount int) Obj
NewGoldPile creates gold pile item with a given amount of gold.
func NewHealthPotion ¶ added in v4.25.0
func NewHealthPotion(pos Positioner, amount int) Obj
NewHealthPotion creates a health potion that restores a given amount.
func NewManaPotion ¶ added in v4.25.0
func NewManaPotion(pos Positioner, amount int) Obj
NewManaPotion creates a mana potion that restores a given amount.
func NewSpellBook ¶ added in v4.25.0
func NewSpellBook(pos Positioner, spell spell.Spell) Obj
NewSpellBook creates a spell book.
func NewSpellUseItem ¶ added in v4.25.0
func NewSpellUseItem(typ ObjTypeName, pos Positioner, spell spell.Spell, lvl int) Obj
NewSpellUseItem creates an item that casts a spell on use.
func NewTrap ¶
func NewTrap(pos Positioner, spells ...spell.Spell) Obj
NewTrap creates a trap at a given point.
Example:
ns.NewTrap(ns.Ptf(10, 5), spell.DEATH_RAY) ns.NewTrap(ns.GetHost(), spell.DEATH_RAY, spell.SPELL_CONFUSE)
func NewTrapAdv ¶
func NewTrapAdv(pos Positioner, spells []TrapSpell) Obj
NewTrapAdv creates a trap at a given point. It's an advanced version of NewTrap.
Example:
ns.NewTrapAdv(ns.Ptf(10, 5), ns.TrapSpell{Spell: spell.DEATH_RAY, Level: 3}) ns.NewTrapAdv(ns.GetHost(), []ns.TrapSpell{ {Spell: spell.DEATH_RAY, Level: 1}, {Spell: spell.SPELL_CONFUSE}, // default level }...)
type ObjCond ¶
type ObjCond interface { // Matches returns true if object matches a condition. // It must not modify the object. Matches(obj Obj) bool }
ObjCond checks if object matches a certain condition.
type ObjCondFunc ¶
ObjCondFunc is a function that implements ObjCond.
func (ObjCondFunc) Matches ¶
func (f ObjCondFunc) Matches(obj Obj) bool
type ObjGroup ¶
type ObjGroup interface { ObjGroupHandle ObjSearcher // Name returns object group name. Name() string // Enable or disable the object. Enable(enable bool) // Toggle the object's enabled state. // It returns the new state after toggling the object. Toggle() bool // HasOwner checks whether any object in target group is owned by object. HasOwner(owner Obj) bool // HasOwnerIn checks whether any object in target is owned by any object in the group. HasOwnerIn(owners ObjGroup) bool // SetOwner sets the owner for each object in a group. See Obj.SetOwner for details. SetOwner(owner Obj) // SetOwners is the same as SetOwner but with an object group as the owner. SetOwners(owners ObjGroup) // Pause objects of a group temporarily. Pause(dt Duration) // Move moves the objects in a group to a waypoint. The objects must be movable or attached to a "Mover". // // If the waypoint is linked, the objects will continue to move once they reach the first waypoint. Move(wp WaypointObj) // WalkTo causes objects in a group to walk to a location. WalkTo(p Pointf) // LookAtDirection causes objects in a group to look in a direction. LookAtDirection(dir Direction) // Damage damages the target objects with a given source object, amount, and damage type. Damage(source Obj, amount int, typ damage.Type) // Delete deletes objects in a group. Delete() // Idle causes creatures in a group to idle. Idle() // Wander cause objects in a group to wander. Wander() // Hunt causes creatures in a group to hunt. Hunt() // Follow causes the creatures to follow target, and they won't attack anything unless disrupted or instructed to. Follow(target Positioner) // Guard is the same as CreatureGuard but applies to creatures in a group. Guard(p1, p2 Pointf, distance float32) // Flee causes creatures to run away from target. Flee(target Positioner, dt Duration) // HitMelee causes objects in a group to melee attacks a location. HitMelee(p Pointf) // HitRanged causes objects in a group to ranged attacks a location. HitRanged(p Pointf) // Attack causes objects in a group to attack a target. Attack(target Positioner) // ZombieStayDown sets group of zombies to stay down. ZombieStayDown() // RaiseZombie raises a zombie group. Also clears stay down state. RaiseZombie() // CreateMover creates a Mover for every object in a group. CreateMover(wp WaypointObj, speed float32) // AggressionLevel sets a group of creature's aggression level. The most commonly used value is 0.83. AggressionLevel(level float32) // SetRoamFlag sets roaming flags for objects in a group. Default is 0x80. SetRoamFlag(flags int) // RetreatLevel causes the creatures to retreat if its health falls below the specified percentage (0.0 - 1.0). RetreatLevel(percent float32) // ResumeLevel causes the creatures to stop retreating if its health is above the specified percentage (0.0 - 1.0). ResumeLevel(percent float32) // AwardSpell awards spell level to objects in a group. // // This will raise the spell level of the objects in the group. // If an object can not cast this spell then it will have no effect on that object. AwardSpell(spell spell.Spell) // Enchant grants objects in a group an enchantment of a specified duration. Enchant(enchant enchant.Enchant, dt Duration) // AllObjects returns all objects as a list. AllObjects() Objects // EachObject calls fnc for all objects in the group. // If fnc returns false, the iteration stops. // If recursive is true, iteration will include items from nested groups. EachObject(recursive bool, fnc func(obj Obj) bool) }
func AsObjGroup ¶
func AsObjGroup(h ObjGroupHandle) ObjGroup
AsObjGroup looks up a ObjGroup for a given handle.
func ObjectGroup ¶
ObjectGroup looks up object group by name.
type ObjGroupHandle ¶
type ObjSearcher ¶
type ObjSearcher interface { // FindObjects calls fnc for all objects in a set matching all the conditions. // It returns a number of objects matched. If fnc returns false, the function stops the search. // If fnc is nil, the function only counts a number of objects matching a condition. // // Example: // // // Find and damage monsters in a 100px circle around obj. // g.FindObjects( // func(it ns.Obj) bool { // it.Damage(obj, 10, damage.FLAME) // return true // }, // ns.InCirclef{Center: obj, R: 100}, // ns.HasClass(object.ClassMonster), // ) FindObjects(fnc func(it Obj) bool, conditions ...ObjCond) int }
ObjSearcher is an interface for iterating and filtering over objects.
type ObjType ¶
type ObjType interface { // Name returns object type name. Name() ObjTypeName // Index returns an index of the type in the game's database. // It can be used to quickly compare object types, or as a map key for them. // // It is strongly advised against comparing it with hardcoded values, since mods may add/remove object types. // Use ObjectType to find object types instead. Index() int // Class returns object type class. Class() object.Class // HasClass checks whether object type has a class. // It uses string values instead of enum as Class does. HasClass(class class.Class) bool // HasSubclass tests whether an object has a specific subclass. // The subclass overlaps, so you should probably test for the class first (via HasClass). HasSubclass(subclass subclass.SubClass) bool // Flags returns object type flags. Flags() object.Flags // Create and object of this type. Create(pos Positioner) Obj }
func ObjectType ¶
func ObjectType(name ObjTypeName) ObjType
ObjectType looks up an object type by name.
func ObjectTypeByInd ¶
ObjectTypeByInd looks up an object type by index.
type ObjTypeName ¶ added in v4.25.0
type ObjTypeName = string
type ObjectEvent ¶
type ObjectEvent int
type Objects ¶
type Objects []Obj
Objects is a list of objects. It can be searched.
func (Objects) FindObjects ¶
FindObjects calls fnc for all objects in the list. See ObjSearcher.
func (Objects) SetOwner ¶
SetOwner sets the owner for each object in a list. See Obj.SetOwner for details.
type Persistent ¶
type Persistent struct {
Name string
}
Persistent returns a persistent storage with a given name. It will persist between OpenNox restarts.
type Player ¶
type Player interface { Positioner // proxies player's unit // Name returns player's name. Name() string // Unit returns player's character unit. Unit() Obj // GetScore gets player's score. GetScore() int // ChangeScore adds or removes player's score(s). ChangeScore(score int) // Print displays a localized string on the screen of the player. // // If the string is not in the string database, it will instead print an error message with "MISSING:". Print(message StringID) // PrintStr displays a string on the screen of the player. It does not localize the string. PrintStr(message string) // Blind or unblind the player. Blind(blind bool) // HasTeam checks if a player belongs to a team. HasTeam(t Team) bool // Team returns current team of a player, if any. Team() Team // CursorPos returns aim cursor position for the player. CursorPos() types.Pointf // Store returns a player storage with a given type. Store(typ StorageType) Storage }
type PlayerDeathFunc ¶
PlayerDeathFunc is a callback type for OnPlayerDeath.
type PlayerJoinFunc ¶
PlayerJoinFunc is a callback type for OnPlayerJoin.
type PlayerLeaveFunc ¶
type PlayerLeaveFunc func(p Player)
PlayerLeaveFunc is a callback type for OnPlayerLeave.
type Positioner ¶
type Positioner interface { // Pos returns current position of the object. Pos() Pointf }
Positioner is an interface for objects that have position on the map.
type Session ¶
type Session struct {
Name string
}
Session is a game session storage with a given name. It will persist as long as a single game session runs.
type Storage ¶
type Storage interface { // Get fetches a custom object or value from the storage with a given key. // Argument must be a pointer to a value of the same type as used during Set. Get(key string, obj any) error // Set stores a custom object or value into the storage with a given key. Set(key string, obj any) error }
type StorageType ¶
type StorageType interface {
// contains filtered or unexported methods
}
type StringID ¶
type StringID = string
StringID is an ID of a localized string in the string database.
type Team ¶
type Team interface { // Name of the team. Name() string // Players returns a list of players belonging to the team. Players() []Player // GetScore returns the current team score. GetScore() int // ChangeScore adds or removes team's score(s). ChangeScore(score int) // Color returns team color. Color() Color }
Team is an interface for game teams.
type TimeSource ¶
type TimeSource interface { // Frame returns current server tick/frame number. Frame() int // Time returns relative time from server start. Time() time.Duration }
TimeSource is an interface for getting relative time.
type Timer ¶
type Timer interface { TimerHandle // Cancel a timer. Returns true if successful. Cancel() bool }
func NewTimer ¶
NewTimer creates a timer that calls the given script function after a given delay.
Example:
// Trigger by function reference: NewTimer(Frames(10), myCallback) // Trigger by function name (can call original NoxScript as well): NewTimer(Seconds(10), "myCallback") // Passing arguments to the callback: NewTimer(Time(3*time.Second), "myCallback", obj)
type TimerHandle ¶
type WallCond ¶
type WallCond interface { // WallMatches returns true if wall matches a condition. // It must not modify the wall. WallMatches(obj WallObj) bool }
WallCond checks if wall matches a certain condition.
type WallGroupHandle ¶
type WallGroupObj ¶
type WallGroupObj interface { WallGroupHandle // Name returns wall group name. Name() string // Enable or disable the object. Enable(enable bool) // Toggle the object's enabled state. // It returns the new state after toggling the object. Toggle() bool // Destroy breaks walls in a group. Destroy() // EachWall calls fnc for all walls in the group. // If fnc returns false, the iteration stops. // If recursive is true, iteration will include items from nested groups. EachWall(recursive bool, fnc func(obj WallObj) bool) }
WallGroupObj is a group of walls.
func AsWallGroup ¶
func AsWallGroup(h WallGroupHandle) WallGroupObj
AsWallGroup looks up a WallGroupObj for a given handle.
type WallHandle ¶
type WallObj ¶
type WallObj interface { WallHandle // IsEnabled checks if object is currently enabled. IsEnabled() bool // Enable or disable the object. Enable(enable bool) // Toggle the object's enabled state. // It returns the new state after toggling the object. Toggle() bool // Flags returns wall flags. Flags() wall.Flags // Pos returns position of the wall in object coordinates. Pos() Pointf // GridPos returns wall grid position. GridPos() Point // Destroy breaks a wall. Destroy() }
WallObj is a pointer to a wall.
func FindAllWalls ¶
FindAllWalls is similar to FindWalls, but returns all walls as an array/slice.
Example:
// Find and return all walls in a 50px circle around obj. arr := ns.FindAllWalls( ns.InCirclef{Center: obj, R: 50}, )
func FindAllWallsIn ¶
func FindAllWallsIn(s WallSearcher, conditions ...WallCond) []WallObj
FindAllWallsIn iterates over walls, and returns all matched walls as an array/slice.
Example:
// Find and return missiles in a 50px circle around obj. arr := ns.FindAllWalls( ns.InCirclef{Center: obj, R: 50}, )
func FindClosestWall ¶
func FindClosestWall(from Positioner, conditions ...WallCond) WallObj
FindClosestWall searches the map for closest wall that matches all conditions. If no walls are found, it returns nil.
Example:
// Find window closest to obj. found := ns.FindClosestWall(obj, ns.HasWallFlags(ns.WallFlagWindow))
func FindClosestWallIn ¶
func FindClosestWallIn(from Positioner, s WallSearcher, conditions ...WallCond) WallObj
FindClosestWallIn searches the set for closest wall that matches all conditions. If no walls are found, it returns nil.
Example:
// Find window closest to obj. found := ns.FindClosestWall(obj, ns.HasWallFlags(ns.WallFlagWindow))
func FindWall ¶
FindWall searches the map for any wall that matches all conditions. If wall is not found it returns nil.
Example:
// Find window on the map. found := ns.FindWall(ns.HasWallFlags(ns.WallFlagWindow))
func FindWallIn ¶
func FindWallIn(s WallSearcher, conditions ...WallCond) WallObj
FindWallIn searches the set for any walls that matches all conditions. If wall is not found it returns nil.
Example:
// Find window on the map. found := ns.FindWall(ns.HasWallFlags(ns.WallFlagWindow))
type WallSearcher ¶
type WallSearcher interface { // FindWalls calls fnc for all walls in a set matching all the conditions. // It returns a number of walls matched. If fnc returns false, the function stops the search. // If fnc is nil, the function only counts a number of walls matching a condition. // // Example: // // // Find and disable walls with a window in a 100px circle around obj. // g.FindWalls( // func(it ns.WallObj) bool { // it.Enable(false) // return true // }, // ns.InCirclef{Center: obj, R: 100}, // ns.HasWallFlags(ns.WallFlagWindow), // ) FindWalls(fnc func(it WallObj) bool, conditions ...WallCond) int }
WallSearcher is an interface for iterating and filtering over walls.
type WaypointGroupHandle ¶
type WaypointGroupObj ¶
type WaypointGroupObj interface { WaypointGroupHandle // Name returns waypoint group name. Name() string // Enable or disable the object. Enable(enable bool) // Toggle the object's enabled state. // It returns the new state after toggling the object. Toggle() bool // EachWaypoint calls fnc for all waypoints in the group. // If fnc returns false, the iteration stops. // If recursive is true, iteration will include items from nested groups. EachWaypoint(recursive bool, fnc func(obj WaypointObj) bool) }
func AsWaypointGroup ¶
func AsWaypointGroup(h WaypointGroupHandle) WaypointGroupObj
AsWaypointGroup looks up a WaypointGroupObj for a given handle.
func WaypointGroup ¶
func WaypointGroup(name string) WaypointGroupObj
WaypointGroup looks up waypoint group by name.
type WaypointHandle ¶
type WaypointObj ¶
type WaypointObj interface { WaypointHandle // Name returns waypoint name. Name() string // Pos returns current position of the object. Pos() Pointf // SetPos instantly moves object to a given position. SetPos(p Pointf) // IsEnabled checks if object is currently enabled. IsEnabled() bool // Enable or disable the object. Enable(enable bool) // Toggle the object's enabled state. // It returns the new state after toggling the object. Toggle() bool }
func AsWaypoint ¶
func AsWaypoint(h WaypointHandle) WaypointObj
AsWaypoint looks up a WaypointObj for a given handle.
func NewWaypoint ¶
func NewWaypoint(name string, pos Pointf) WaypointObj
NewWaypoint creates a new waypoint with a given name and position.