data\scripts\creaturescripts\others\bestiary_kill.lua
local bestiaryOnKill = CreatureEvent("BestiaryOnKill")
function bestiaryOnKill.onKill(player, creature, lastHit)
if not player:isPlayer() or not creature:isMonster() or creature:hasBeenSummoned() or creature:isPlayer() then
return true
end
for cid, damage in pairs(creature:getDamageMap()) do
local participant = Player(cid)
if participant and participant:isPlayer() then
local bestAmount = 5 --how much will increase after kill a monter in bestiary
for i = bestAmount, 1, -1 do
participant:addBestiaryKill(creature:getName())
end
end
end
return true
end
bestiaryOnKill:register()
local bestAmount variable
Server Version, Script that you currently have and/or the specific variable or situation you're trying to create.
Server version: 12.64 (OTSERVBR)
Script: Above
Tfs: 1.3
I see.Oh sorry.
Lemme explain then ;-)
How it works at the moment:
Lua:local bestiaryOnKill = CreatureEvent("BestiaryOnKill") function bestiaryOnKill.onKill(player, creature, lastHit) if not player:isPlayer() or not creature:isMonster() or creature:hasBeenSummoned() or creature:isPlayer() then return true end for cid, damage in pairs(creature:getDamageMap()) do local participant = Player(cid) if participant and participant:isPlayer() then local bestAmount = 5 --how much will increase after kill a monter in bestiary for i = bestAmount, 1, -1 do participant:addBestiaryKill(creature:getName()) end end end return true end bestiaryOnKill:register()
So, I'd like to change theto a variable where I would edit on config.lua.Code:local bestAmount variable
data/lib/core/
customLibs.lua
core.lua
(same directory)customLibs.lua
put your variable without the local.bestAmount = 5
yes it is possible, just add a new entry in configmanager.cpp/h and luascript.cpp and recompile your server and you will be able to use configManager.getNumber(configKeys.WHATEVER_YOU_WANT)
forgottenserver/src/configmanager.cpp at 8404edeff822799f444f0b4621165eb620af9234 · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.comforgottenserver/src/configmanager.h at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
local bestiaryOnKill = CreatureEvent("BestiaryOnKill")
function bestiaryOnKill.onKill(player, creature, lastHit)
if not player:isPlayer() or not creature:isMonster() or creature:hasBeenSummoned() or creature:isPlayer() then
return true
end
for cid, damage in pairs(creature:getDamageMap()) do
local participant = Player(cid)
if participant and participant:isPlayer() then
local bAmount = configManager.getNumber(configKeys.WHATEVER_YOU_WANT) --how much will increase after kill a monter in bestiary
for i = bAmount, 1, -1 do
participant:addBestiaryKill(creature:getName())
end
end
end
return true
end
bestiaryOnKill:register()
Looks right.Lua:local bestiaryOnKill = CreatureEvent("BestiaryOnKill") function bestiaryOnKill.onKill(player, creature, lastHit) if not player:isPlayer() or not creature:isMonster() or creature:hasBeenSummoned() or creature:isPlayer() then return true end for cid, damage in pairs(creature:getDamageMap()) do local participant = Player(cid) if participant and participant:isPlayer() then local bAmount = configManager.getNumber(configKeys.WHATEVER_YOU_WANT) --how much will increase after kill a monter in bestiary for i = bAmount, 1, -1 do participant:addBestiaryKill(creature:getName()) end end end return true end bestiaryOnKill:register()
The .lua file should be like this?
I see.
config.lua is a poor choice for this in my opinion, though.
I'd suggest creating a new file in
data/lib/core/
Name it whatever you want, an example might becustomLibs.lua
Then register that file incore.lua
(same directory)
Inside of that filecustomLibs.lua
put your variable without the local.
So in your case, put it like
Lua:bestAmount = 5
Then you can call it from any script using the variable name.
Needing to modify the source and recompile every time you want to add a new variable is a waste of time, when a much easier alternative is available.Why do you think it's a bad idea? I mean, could you explain? Thanks.