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 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 MakeEnemy(obj Obj)
- func MakeFriendly(obj Obj)
- func Music(music int, volume int)
- func MusicEvent()
- func MusicPopEvent()
- func MusicPushEvent()
- func NoWallSound(noWallSound bool)
- 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 DialogAnswer
- type DialogType
- type Direction
- type Duration
- type EntryType
- type EqualClass
- type Func
- type Game
- type HalberdLevel
- type Handle
- type HasAllClasses
- type HasClass
- type HasType
- type HasTypeName
- type Implementation
- type InCirclef
- type InRectf
- type NOT
- type OR
- type Obj
- func AsObj(h ObjHandle) Obj
- func CreateObject(typ string, pos Positioner) Obj
- func FindAllObjects(conditions ...ObjCond) []Obj
- func FindClosestObject(from Positioner, conditions ...ObjCond) Obj
- func FindObject(conditions ...ObjCond) Obj
- func GetCaller() Obj
- func GetHost() Obj
- func GetTrigger() 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 ObjType
- type ObjectEvent
- type Player
- type Pointf
- type Positioner
- type StringID
- type TimeSource
- type Timer
- type TimerHandle
- type TrapSpell
- type WallGroupHandle
- type WallGroupObj
- type WallHandle
- type WallObj
- 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 )
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 ¶ added in v4.5.0
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 ¶ added in v4.4.0
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 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 ¶ added in v4.2.0
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 ¶ added in v4.2.0
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 ¶ added in v4.2.0
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 MusicEvent ¶
func MusicEvent()
func MusicPopEvent ¶
func MusicPopEvent()
func MusicPushEvent ¶
func MusicPushEvent()
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 ¶ added in v4.2.0
func PrintStr(message string)
PrintStr displays a string on the screen of Other. It does not localize the string.
func PrintStrToAll ¶ added in v4.2.0
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 ¶ added in v4.2.0
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 ¶ added in v4.2.0
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 ¶ added in v4.2.0
func WithRuntime(ctx context.Context, g Implementation) context.Context
WithRuntime stores Implementation in the context.
Types ¶
type AND ¶ added in v4.4.0
type AND []ObjCond
AND matches an object if all conditions match an object.
type DialogAnswer ¶
type DialogAnswer int
type DialogType ¶
type DialogType string
type Duration ¶ added in v4.3.0
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 ¶ added in v4.3.1
func NowWithSource(s TimeSource) Duration
NowWithSource returns current timestamp of the time source.
type EqualClass ¶ added in v4.4.0
EqualClass checks that class of object exactly matches this value.
func (EqualClass) Matches ¶ added in v4.4.0
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 ¶ added in v4.4.0
HasAllClasses checks that class of object matches all of provided classes.
func (HasAllClasses) Matches ¶ added in v4.4.0
func (c HasAllClasses) Matches(obj Obj) bool
type HasClass ¶ added in v4.4.0
HasClass checks that class of object matches any of provided classes.
type HasType ¶ added in v4.4.0
type HasType []ObjType
HasType checks that object matches any of provided types.
type HasTypeName ¶ added in v4.4.0
type HasTypeName []string
HasTypeName checks that object matches any of provided type names.
func (HasTypeName) Matches ¶ added in v4.4.0
func (arr HasTypeName) Matches(obj Obj) bool
type Implementation ¶
type Implementation interface { 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 string) ObjType ObjectTypeByInd(ind int) ObjType ObjectByHandle(h ObjHandle) Obj Object(name string) Obj ObjectGroupByHandle(h ObjGroupHandle) ObjGroup ObjectGroup(name string) ObjGroup CreateObject(typ string, pos Positioner) Obj FindObjects(fnc func(obj Obj) bool, conditions ...ObjCond) int 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) 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 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 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 ¶ added in v4.2.0
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 ¶ added in v4.4.0
type InCirclef struct { Center Positioner R float64 }
InCirclef filters objects that are inside a circle on the map.
type InRectf ¶ added in v4.4.0
type InRectf struct {
Min, Max Pointf
}
InRectf filters objects that are inside a given map rectangle.
type NOT ¶ added in v4.4.0
type NOT struct {
Cond ObjCond
}
NOT matches an object if any other condition returns false.
type OR ¶ added in v4.4.0
type OR []ObjCond
OR matches an object if any of the conditions matches an object.
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) // 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 // HasEnchant gets whether object has an enchant. HasEnchant(enchant enchant.Enchant) bool // Direction gets object direction. // // See LookWithAngle. Direction() Direction // 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) // SetColor sets NPC or player color, given its index. // // Example: // // obj.SetColor(0, color.NRGBA{R:80, A: 255}) // dark red, 100% opacity SetColor(ind int, cl color.Color) // GetGold gets amount of gold for player object. GetGold() int // ChangeGold changes amount of gold for player 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) // 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 the item is in the object's inventory. HasItem(item Obj) bool // 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. // // 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. GetPreviousItem() Obj // Items returns all items in the object's inventory. // // 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() []Obj // 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 up 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 // 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) // 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 // 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. OnEvent(event ObjectEvent, fnc Func) }
func CreateObject ¶
func CreateObject(typ string, pos Positioner) Obj
CreateObject creates an object given a type and a starting location.
Example: spider := CreateObject("SmallAlbinoSpider", Waypoint("SpiderHole"))
func FindAllObjects ¶ added in v4.4.0
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 FindClosestObject ¶ added in v4.4.0
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 FindObject ¶ added in v4.4.0
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 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 NewTrap ¶ added in v4.5.0
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 ¶ added in v4.5.0
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 ¶ added in v4.4.0
type ObjCond interface { // Matches returns true if objects matches a condition. // It must not modify the object. Matches(obj Obj) bool }
ObjCond checks if object matches a certain condition.
type ObjCondFunc ¶ added in v4.4.0
ObjCondFunc is a function that implements ObjCond.
func (ObjCondFunc) Matches ¶ added in v4.4.0
func (f ObjCondFunc) Matches(obj Obj) bool
type ObjGroup ¶
type ObjGroup interface { ObjGroupHandle // 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) // 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 ObjType ¶ added in v4.2.0
type ObjType interface { // Name returns object type name. Name() string // 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 // Create and object of this type. Create(pos Positioner) Obj }
func ObjectType ¶ added in v4.2.0
ObjectType looks up an object type by name.
func ObjectTypeByInd ¶ added in v4.2.0
ObjectTypeByInd looks up an object type by index.
type ObjectEvent ¶
type ObjectEvent int
type Player ¶ added in v4.2.0
type Player interface { // Name returns player's name. Name() string // Unit returns player's character unit. Unit() Obj // GetScore gets player's score. GetScore() int // ChangeScore changes player's score. 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) }
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 StringID ¶
type StringID = string
StringID is an ID of a localized string in the string database.
type TimeSource ¶ added in v4.3.0
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 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 // Destroy breaks a wall. Destroy() }
WallObj is a pointer to a wall.
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 ¶ added in v4.4.0
func NewWaypoint(name string, pos Pointf) WaypointObj
NewWaypoint creates a new waypoint with a given name and position.
func Waypoints ¶ added in v4.2.0
func Waypoints() []WaypointObj
Waypoints returns a list of all waypoints.