forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Revnpcsys] Revisioned Npc System v1.3 (otland#4747)
- Added `onSight` event, this has to be enabled with `NpcType:sight(x, y)` unless that is not set the event wont fire. This event triggers whenever a creature (monsters/npcs/players) steps into the sight range, will only re trigger once you walk out of idle range and back in again. - fixed event callbacks, they're now moved into `NpcCallbacks` they can be set like: `NpcType:callbacks().onSay/onSight/etc.` - fixed a crash which could occur if you had a npc disabled then enabled him and /reload npcs, this is now fixed - fixed a crash that if a xml npc is invalid on server startup that it throws an error instead of crashing - made all the functions in the lib overloadable, only the table data is protected, you can now change functions and they will be correctly changed on /reload npcs - changed everything related to focus from seconds into ms - changed focus so it works for all creatures not only players - changed NpcTalkQueue it now works for creatures not only for players - changed the onCreatureSay event, it now triggers for all creatures not only for players - selfSay has a new parameter now called talkType which is optional and falls back to TALKTYPE_SAY - added `onSpeechBubble` event, with this we can set the speech bubble for each player individual. example: Npc has a quest for the player he only shows for this player the quest speech bubble, once the quest is finished the npc wont have a quest speech bubble anymore --------- Co-authored-by: Evil Puncker <EPuncker@users.noreply.github.com> Co-authored-by: KrecikOnDexin <krecikondexin@gmail.com>
- Loading branch information
1 parent
00f4400
commit a490b34
Showing
19 changed files
with
1,774 additions
and
1,573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--[[ | ||
>> NpcCallbacks << | ||
Description: | ||
- It is used to store the callbacks for a specific NPC, and to check if a callback exists for a specific NPC. | ||
Functions: | ||
- NpcCallbacks:hasCallback(callback) | ||
- NpcCallbacks:onSay(npc, creature, messageType, message) | ||
- NpcCallbacks:onThink(npc) | ||
- NpcCallbacks:onMove(npc, oldPos, newPos) | ||
- NpcCallbacks:onAppear(npc, creature) | ||
- NpcCallbacks:onDisappear(npc, creature) | ||
- NpcCallbacks:onSight(npc, creature) | ||
- NpcCallbacks:onPlayerCloseChannel(npc, creature) | ||
- NpcCallbacks:onPlayerEndTrade(npc, creature) | ||
]] | ||
|
||
---@class NpcCallbacks | ||
---@field onSay fun(npc: Npc, creature: Creature, messageType: number, message: string) | ||
---@field onThink fun(npc: Npc) | ||
---@field onMove fun(npc: Npc, oldPos: Position, newPos: Position) | ||
---@field onAppear fun(npc: Npc, creature: Creature) | ||
---@field onDisappear fun(npc: Npc, creature: Creature) | ||
---@field onSight fun(npc: Npc, creature: Creature) | ||
---@field onPlayerCloseChannel fun(npc: Npc, creature: Creature) | ||
---@field onPlayerEndTrade fun(npc: Npc, creature: Creature) | ||
---@field hasCallback fun(callback: string): boolean | ||
|
||
if not NpcCallbacks then | ||
NpcCallbacks = {} | ||
|
||
setmetatable(NpcCallbacks, { | ||
__call = function(self, npc) | ||
if not self[npc:getName()] then | ||
self[npc:getName()] = {} | ||
end | ||
setmetatable(self[npc:getName()], {__index = NpcCallbacks}) | ||
-- The NpcCallbacks is returned | ||
return self[npc:getName()] | ||
end | ||
}) | ||
|
||
end | ||
|
||
---@param callback string The callback to check for. | ||
---@return boolean True if the callback exists, false otherwise. | ||
function NpcCallbacks:hasCallback(callback) | ||
return self[callback] ~= nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.