Module char_proto

Functions for mob prototypes, including triggers

Class CharProto

charproto:getDescription () Gets the description for the mob prototype.
charproto:getName () Gets the name for the mob prototype.
charproto:onAct (message, callback) registers a function to run when the given action message is shown to the mob.
charproto:onBribe (amount, callback) registers a function to run when the given number of credits is given to the character.
charproto:onDamage (callback) registers a function to run each time the mob is damaged.
charproto:onDeath (callback) registers a function to run when a mob is killed.
charproto:onEnter (callback) registers a function to run whenever the mob itself enters a new room.
charproto:onFight (callback) registers a function to run during each combat round the mob is in.
charproto:onGive (callback) registers a function to run every time any object is given to this character.
charproto:onGreet (callback) registers a function to run when another character enters the room.
charproto:onLook (callback) registers a function to run when a character looks at this one.
charproto:onRandom (chance, callback) registers a function with a chance to run every mob tick (10 seconds).
charproto:onSayto (callback) registers a function to run when something is said to a mob using sayto
charproto:onSpawned (callback) registers a function to run when a mob is spawned via reset.
charproto:onSpeech (message, callback) registers a function to run when the given text is spoken in the room.
charproto:onTime (hour, callback) registers a function to run every time the hour changes to a certain value.
charproto:setDescription (desc) set the full description for a mob prototype.
charproto:setName (name) set the name for a mob prototype.


Class CharProto

Functions on character prototype variables
charproto:getDescription ()
Gets the description for the mob prototype.

Returns:

    string the description value
charproto:getName ()
Gets the name for the mob prototype.

Returns:

    string the name value
charproto:onAct (message, callback)
registers a function to run when the given action message is shown to the mob.

Parameters:

  • message string the message to trigger on
  • callback func the function to run, taking arguments: 1. this Character 2. the Character who did the action 3. the full text of the action message

Usage:

    self:onAct("begins drawing a bead on you!", function(self, actor, fullText)
      actor:echoAt("You can't aim at me!")
    end)
charproto:onBribe (amount, callback)
registers a function to run when the given number of credits is given to the character.

Parameters:

  • amount integer the number of credits required to trigger the bribe, exact match only
  • callback func the function to run, taking arguments: 1. this Character 2. the Character who gave the credits

Usage:

    self:onBribe(10000, function(self, ch)
      self:sayTo(ch, "Thank you for your patronage.")
      self:awardCredits(-10000) -- Clean up the credits
    end)
charproto:onDamage (callback)
registers a function to run each time the mob is damaged. This is called after the damage is applied.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character 2. the Character doing the damage (can be nil) 3. the amount of damage done (integer)

Usage:

    self:onDamage(function(self, ch, amount)
      self:sayTo(ch, "You hit me for "..amount.." damage")
    end)
charproto:onDeath (callback)
registers a function to run when a mob is killed. This is run while the mob technically still exists in the room where it died, so it can still interact with players and objects there.

Parameters:

  • callback func the function to run, taking arguments: 1. the Character being killed 2. the Character who killed it (can be nil)

Usage:

    self:onDeath(function(self, byChar)
      if not byChar then
        return
      end
      byChar:echoAt("Good job, you killed "..self:getShortDescription().."!")
    end)
charproto:onEnter (callback)
registers a function to run whenever the mob itself enters a new room.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character 2. the Room it came from

Usage:

    self:onEnter(function(self, oldRoom)
      -- Do stuff
    end)
charproto:onFight (callback)
registers a function to run during each combat round the mob is in. This runs every single round, so use math.rand in the function if you don't need it to happen every time.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character 2. the Character it's fighting

Usage:

    self:onFight(function(self, target)
      target:echoAt("I'll win this fight yet!")
    end)
charproto:onGive (callback)
registers a function to run every time any object is given to this character.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character 2. the Object given to the character 3. the Character who gave the object

Usage:

    self:onGive(function(self, obj, ch)
      if obj:getVNum() == 1000 then
        self:sayTo(ch, "Great, this is what I needed.")
      else
        self:sayTo(ch, "Huh? I don't want that.")
        self:emote("returns "..obj:getShortDescription()..".")
        obj:toChar(ch)
      end
    end)
charproto:onGreet (callback)
registers a function to run when another character enters the room.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character 2. the Character who entered 3. the Room they came from

Usage:

    self:onGreet(function(self, target, fromRoom)
      target:echoAt("You notice "..self:getShortDescription().." waving at you.")
    end)
charproto:onLook (callback)
registers a function to run when a character looks at this one.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character 2. the Character who looked at this one

Usage:

    self:onLook(function(self, ch)
      self:sayTo(ch, "What are you looking at?")
    end)
charproto:onRandom (chance, callback)
registers a function with a chance to run every mob tick (10 seconds).

Parameters:

  • chance integer the chance, 1-100, that the trigger will fire on a given tick
  • callback func the function to run, taking arguments: 1. this Character

Usage:

    self:onRandom(25, function(self)
      -- Do stuff
    end)
charproto:onSayto (callback)
registers a function to run when something is said to a mob using sayto

Parameters:

  • callback func the function to run, taking arguments: 1. the Character being said to 2. the Character doing the speaking 2. a string of what was said

Usage:

    self:onSayto(function(self, speaker, text)
      self:force("say You said "..text.." to me!")
    end)
charproto:onSpawned (callback)
registers a function to run when a mob is spawned via reset. Does not apply when it is invoked manually or via progs.

Parameters:

  • callback func the function to run, taking arguments: 1. this Character

Usage:

    self:onSpawned(function(self)
      Object.invoke(170050):toChar(self)
      self:force("wield sword")
    end)
charproto:onSpeech (message, callback)
registers a function to run when the given text is spoken in the room.

Parameters:

  • message string the message to trigger on
  • callback func the function to run, taking arguments: 1. this Character 2. the Character who spoke 3. the full text spoken

Usage:

    self:onSpeech("assistance", function(self, speaker, fullText)
      speaker:echoAt("Yeah, sure, I need some help with the womp rats in the warehouse.")
    end)
charproto:onTime (hour, callback)
registers a function to run every time the hour changes to a certain value.

Parameters:

  • hour integer the hour of day to trigger at, 0-23
  • callback func the function to run, taking arguments: 1. this Character

Usage:

    self:onTime(6, function(self)
      self:say("Good morning!")
    end)
charproto:setDescription (desc)
set the full description for a mob prototype.

Parameters:

  • desc string the new description
charproto:setName (name)
set the name for a mob prototype.

Parameters:

  • name string the new name
generated by LDoc 1.5.0 Last updated 2024-10-22 16:05:00