Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Revscriptsys] RevNpcSys version 1.0 (lua npcs / NpcType / new npc system) #4671

Merged
merged 52 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5539c3f
lua Npc's
EvilHero90 Apr 30, 2024
1c181d5
tree handling talkstate
EvilHero90 Apr 30, 2024
860580e
Merge branch 'master' into npc-system
EvilHero90 May 1, 2024
7814076
Merge branch 'master' into npc-system
EvilHero90 May 1, 2024
ad194ec
added callback
EvilHero90 May 1, 2024
30ea721
requirements
EvilHero90 May 1, 2024
e2aa611
documentation and splitting in files
EvilHero90 May 2, 2024
cb5d1da
optimizations & better documentation
EvilHero90 May 2, 2024
226419c
requirements, modules & documentation
EvilHero90 May 3, 2024
d004a07
remove unused function & other improvements
EvilHero90 May 3, 2024
d788476
annotations
EvilHero90 May 4, 2024
eac6ea2
Merge branch 'master' into npc-system
EvilHero90 May 5, 2024
683b96b
annotation fixes
EvilHero90 May 5, 2024
81fc9f3
NpcType class
EvilHero90 May 6, 2024
7b15f62
improvements
EvilHero90 May 7, 2024
fe9fb0f
~NpcEventsHandler()
EvilHero90 May 7, 2024
d45354c
clang
EvilHero90 May 7, 2024
29a4605
removing not necessary check
EvilHero90 May 7, 2024
ea11545
improvements on keywords & responses
EvilHero90 May 7, 2024
5acc33f
Merge branch 'master' into npc-system
EvilHero90 May 7, 2024
ffa54e8
added the missing events & callbacks
EvilHero90 May 7, 2024
df23ff9
shop works with item name aswell
EvilHero90 May 8, 2024
4467f40
error handling for shop items
EvilHero90 May 8, 2024
477731a
more functionality and slight fixes
EvilHero90 May 11, 2024
4824668
spelling mistake
EvilHero90 May 11, 2024
3b85b28
changing pointers from shared_ptr to unique_ptr
EvilHero90 May 11, 2024
bf967d4
added NpcVoices & few other things
EvilHero90 May 12, 2024
b580581
sub-keywords
EvilHero90 May 12, 2024
69cd124
re work on requirements
EvilHero90 May 13, 2024
de5c7bc
greeting re work
EvilHero90 May 13, 2024
c74fb12
code cleanup & keyword fix
EvilHero90 May 15, 2024
b629df4
adding onAnswer() & money transfer dupe
EvilHero90 May 15, 2024
2b71c28
check for answer
EvilHero90 May 15, 2024
8dae802
renamed get/add/reset answers into data
EvilHero90 May 16, 2024
eba30a3
code cleanup
EvilHero90 May 16, 2024
17d11e0
clang
EvilHero90 May 16, 2024
37be7c5
Update modules.lua
EvilHero90 May 19, 2024
331e15e
idle rework
EvilHero90 May 19, 2024
42b6302
slight optimizations
EvilHero90 May 19, 2024
f82770e
adding resetData where needed
EvilHero90 May 21, 2024
cbfe62c
reworked NpcType class
EvilHero90 May 23, 2024
75d3c85
improvement on voices
EvilHero90 May 23, 2024
53dbb16
syncing players money on transfer
EvilHero90 May 24, 2024
e6a1c43
renaming folder
EvilHero90 May 26, 2024
4a409f6
Merge branch 'master' into npc-system
EvilHero90 May 27, 2024
ab9c994
merging conflicts
EvilHero90 May 27, 2024
a3a3e66
another merging conflict
EvilHero90 May 27, 2024
21ad5bf
add NpcType to cpplinter.lua
EvilHero90 May 27, 2024
80a793c
correcting parameters in onMove
EvilHero90 May 27, 2024
ff98732
NpcFocus fix
EvilHero90 May 27, 2024
0e4362b
adding vocation requirements
EvilHero90 May 28, 2024
cc3b704
final version 1.0 commit
EvilHero90 May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions data/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,42 @@ do
rawgetmetatable("Action").__newindex = ActionNewIndex
end

do
local function NpcTypeNewIndex(self, key, value)
if key == "onSay" then
self:eventType("say")
self:onSay(value)
return
elseif key == "onDisappear" then
self:eventType("disappear")
self:onDisappear(value)
return
elseif key == "onAppear" then
self:eventType("appear")
self:onAppear(value)
return
elseif key == "onMove" then
self:eventType("move")
self:onMove(value)
return
elseif key == "onPlayerCloseChannel" then
self:eventType("closechannel")
self:onPlayerCloseChannel(value)
return
elseif key == "onPlayerEndTrade" then
self:eventType("endtrade")
self:onPlayerEndTrade(value)
return
elseif key == "onThink" then
self:eventType("think")
self:onThink(value)
return
end
ranisalt marked this conversation as resolved.
Show resolved Hide resolved
rawset(self, key, value)
end
rawgetmetatable("NpcType").__newindex = NpcTypeNewIndex
end

do
local function TalkActionNewIndex(self, key, value)
if key == "onSay" then
Expand Down Expand Up @@ -588,8 +624,6 @@ function isPremium(cid) local p = Player(cid) return p and p:isPremium() or fals

STORAGEVALUE_EMPTY = -1
function Player:getStorageValue(key)
print("[Warning - " .. debug.getinfo(2).source:match("@?(.*)") .. "] Invoking Creature:getStorageValue will return nil to indicate absence in the future. Please update your scripts accordingly.")
ranisalt marked this conversation as resolved.
Show resolved Hide resolved

local v = Creature.getStorageValue(self, key)
return v or STORAGEVALUE_EMPTY
end
Expand Down
2 changes: 2 additions & 0 deletions data/lib/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function Player.transferMoneyTo(self, target, amount)
end

self:setBankBalance(self:getBankBalance() - amount)
-- incase server crashes that we do not duplicate money
db.query("UPDATE `players` SET `balance` = " .. self:getBankBalance() .. " WHERE `id` = '" .. self:getGuid() .. "'")
EvilHero90 marked this conversation as resolved.
Show resolved Hide resolved
return true
end

Expand Down
113 changes: 113 additions & 0 deletions data/npc/lib/evilnpcsystem/constants.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
--[[
>> Constants <<

Description:
- This file contains all the constants used in the NPC System.
]]

-- MESSAGE_TAGS
---@class MESSAGE_TAGS
---@type table<string, table<string, string|number|function>>
MESSAGE_TAGS = {
playerName = { tag = "|PLAYERNAME|", func = function(params) return params.playerName or "" end },
playerLevel = { tag = "|PLAYERLEVEL|", func = function(params) return params.playerLevel or "" end },
itemCount = { tag = "|ITEMCOUNT|", func = function(params) return params.amount or "" end },
totalCost = { tag = "|TOTALCOST|", func = function(params) return params.total or "" end },
itemName = { tag = "|ITEMNAME|", func = function(params) return params.itemName or "" end },
storageKey = { tag = "|STORAGEKEY|", func = function(params) return params.storage and params.storage.key or "" end },
storageValue = { tag = "|STORAGEVALUE|", func = function(params) return params.storage and params.storage.value or "" end }
}

-- MESSAGE_LIST
---@class MESSAGE_LIST
---@type table<string, string>
MESSAGE_LIST = {
-- shop messages
needMoney = "You need more money",
needSpace = "You do not have enough capacity.",
needMoreSpace = "You do not have enough capacity for all items.",
bought = "You bought |ITEMCOUNT| |ITEMNAME|(s) for |TOTALCOST| gold.",
sold = "You sold |ITEMCOUNT| |ITEMNAME|(s) for |TOTALCOST| gold.",
-- requirement cancel messages
storage = "You do not meet the storage requirement.",
storageNotEqual = "You do not meet the storage requirement.",
storageToLow = "You do not meet the storage requirement.",
storageToHigh = "You do not meet the storage requirement.",
level = "You need to be exactly level |PLAYERLEVEL|.",
levelNotEqual = "You can't be exactly level |PLAYERLEVEL|.",
levelToLow = "You need to be atleast level |PLAYERLEVEL|.",
levelToHigh = "You need to be under level |PLAYERLEVEL|.",
premium = "You need to be premium to do this.",
money = "You do not have enough money, it costs |TOTALCOST| gold.",
item = "You do not have atleast |ITEMCOUNT| |ITEMNAME|(s).",
infight = "You need to be in fight.",
notInfight = "You have to be out of fight.",
pzLocked = "You need to be pz locked",
notPzLocked = "You are not allowed to be pz locked"
}

-- KEYWORDS_GREET
---@type string[]
KEYWORDS_GREET = {
"hi",
"hello",
"hey",
"greetings"
}

-- MESSAGES_GREET
---@type string[]
MESSAGES_GREET = {
"Hello |PLAYERNAME| how can I help you?",
"Greetings |PLAYERNAME|, what can I do for you?",
"Hi |PLAYERNAME|, what's your desire today?"
}

-- KEYWORDS_FAREWELL
---@type string[]
KEYWORDS_FAREWELL = {
"bye",
"goodbye",
"farewell",
"cya",
"ciao"
}

-- MESSAGES_FAREWELL
---@type string[]
MESSAGES_FAREWELL = {
"Goodbye |PLAYERNAME|, have a nice day!",
"Farewell |PLAYERNAME|, see you soon!",
"See you later |PLAYERNAME|, take care!"
}

-- FOCUS
---@class FOCUS
---@type table<string, any>
FOCUS = {
-- how long the npc will focus the player in seconds
time = 60,
-- how far the player can step away until the npc loses focus
distance = 5,
-- how near the player has to be to greet the npc
greetDistance = 3
}

-- TALK
---@class TALK
---@type table<string, any>
TALK = {
-- how long in ms the npc will wait before responding
defaultDelay = 1000
}

REQUIREMENTS = {
storage = 1,
level = 2,
premium = 3,
money = 4,
item = 5,
inFight = 6,
pzLocked= 7,
removeItem = 8
}
Loading
Loading