Hello Peoples,
Since I saw this requested by a guy I'll just release it here since it's nothing really hard to do.
but you need 2 certain functions to get it work.
Credits: Remere for the functions
Copy paste those at the bottom of your functions/global.lua
Here is the main Script
this is what you have to add into creaturescripts.xml
This one goes into login.lua
If there are any Questions, feel free to ask.
kind regards, Evil Hero
Since I saw this requested by a guy I'll just release it here since it's nothing really hard to do.
but you need 2 certain functions to get it work.
Credits: Remere for the functions
Code:
_warpzone = 2147483648 -- start storing strings here (THIS IS THE ABSOLUTE MAXIMUM VALUE FOR THIS)
_maxlength = 1024 -- multiply by 3 to get the true length.
setPlayerStorageInteger = setPlayerStorageValue
getPlayerStorageInteger = getPlayerStorageValue
function setPlayerStorageString(cid, key, value)
if #value > (_maxlength-1) * 3 - 1 then -- Last word is reserved for 0 termination of the string.
error("Storage string is too long")
end
if key > _warpzone / _maxlength then
error("Storage string key is too large (" .. key .. ")")
end
key = _warpzone + key * _maxlength
local word = 0
local wordwrap = 0
local wordcount = 0
local i = 1
while i <= #value do
local byte = string.byte(string.sub(value, i, i))
word = bit.bor(word, bit.lshift(byte, wordwrap))
wordwrap = wordwrap + 8
if wordwrap == 24 then
--[[
In the ideal world we would be able to store 4 characters per word,
however, as the default return value for getPlayerStorageValue is
-1, we can't use the last bit.
]]--
setPlayerStorageInteger(cid, key + wordcount, word)
word = 0
wordwrap = 0
wordcount = wordcount + 1
end
i = i + 1
end
-- store the last word
setPlayerStorageInteger(cid, key + wordcount, word)
end
function getPlayerStorageString(cid, key)
if key > _warpzone / _maxlength then
error("Storage string key is too large (" .. key .. ")")
end
key = _warpzone + key * _maxlength
local wordcount = 0
local str = ""
while true do
if wordcount >= _maxlength then
break
end
local word = getPlayerStorageInteger(cid, key + wordcount)
if word == -1 then
-- end of string
break
else
-- Extract the 3 characters from the value
byte = bit.band(word, 255)
if byte == 0 then break else str = str .. string.char(byte) end
byte = bit.rshift(bit.band(word, 65280), 8)
if byte == 0 then break else str = str .. string.char(byte) end
byte = bit.rshift(bit.band(word, 16711680), 16)
if byte == 0 then break else str = str .. string.char(byte) end
end
wordcount = wordcount + 1
end
return str
end
Here is the main Script
Code:
-- Monster Counter
-- Made by Evil Hero, thanks to Remere for the functions
function onKill(cid, target)
local monster = getCreatureName(target)
local killed = getPlayerStorageString(cid,monster)
if isMonster(target) == TRUE then
if getPlayerStorageString(cid,monster) < 1 then
setPlayerStorageString(cid,monster,1)
doPlayerSendTextMessage(cid,22,"Congratulations, You killed your first ".. monster ..".")
else
setPlayerStorageString(cid,monster,killed + 1)
doPlayerSendTextMessage(cid,22,"You have killed ".. killed .." ".. monster .."s.")
end
end
return TRUE
end
this is what you have to add into creaturescripts.xml
Code:
<event type="kill" name="Monster Counter" script="monstercounter.lua"/>
This one goes into login.lua
Code:
registerCreatureEvent(cid, "Monster Counter")
If there are any Questions, feel free to ask.
kind regards, Evil Hero
Last edited: