Hey! This great system will allow you to save "settings" into a players storage value using ONLY 1 STORAGE VALUE! However this will only store boolean values (true/false).
So, if you use storage value 82000 for your settings, then you will be able to store an infinite amount of settings in just that single storage value!
For example, if you want to check if a player has clicked on a door before, or whatever! Couldn't figure any example hehe
However, here goes the code!
First, go to data/lib folder, create new file called "settings.lua", in it write:
In there you will place yours! Those were only examples!
Now create another new file, in same folder, called "setting_system.lua", in it paste:
Now open data.lua and add the following lines:
That's it! Now how to use them ?
Example, talkaction.
This will turn on/off each time you use it. Because it will always toggle. But you can use only setPlayerSettingStatus(cid, MY_TEST_SETTING, true) and it will be on, and you write false to turn it off.
Hope you understood!
Regards,
Colandus
So, if you use storage value 82000 for your settings, then you will be able to store an infinite amount of settings in just that single storage value!
For example, if you want to check if a player has clicked on a door before, or whatever! Couldn't figure any example hehe
However, here goes the code!
First, go to data/lib folder, create new file called "settings.lua", in it write:
Lua:
--##############################--
--##SETTING SYSTEM BY COLANDUS##--
--##############################--
-- Settings storage value
SETTINGS_STORAGE_VALUE = 32444
-- Put all settings here. Always put new settings in BOTTOM, or you will fuck it all up!
_SETTINGS = {
-- HAS_FINISHED_ANIHILATOR = 1,
-- HAS_CLICKED_DOOR = 2,
-- CAN_ACCESS_QUEST = 3
MY_TEST_SETTING = 1
}
In there you will place yours! Those were only examples!
Now create another new file, in same folder, called "setting_system.lua", in it paste:
Lua:
--##############################--
--##SETTING SYSTEM BY COLANDUS##--
--##############################--
-- Returns true/false if player has the setting
function getPlayerSettingStatus(cid, settingId)
-- Make sure player exist
if(not isPlayer(cid)) then
return false
end
-- Make settingId to binary
settingId = settingId ^ 2
-- Retrieve players current settings
local settings = getPlayerStorageValue(cid, SETTINGS_STORAGE_VALUE)
-- Return and check whether player has this setting enabled
return bit.band(settings, settingId) == settingId
end
-- Set a players setting status; "status" should be true/false
function setPlayerSettingStatus(cid, settingId, status)
-- Make sure player exist
if(not isPlayer(cid)) then
return false
end
-- Set only if he don't currently have this status already
if(getPlayerSettingStatus(cid, settingId) ~= status) then
-- Toggle setting status
doPlayerToggleSettingStatus(cid, settingId)
-- Success, return true
return true
end
-- Everything was done without errors
return false
end
-- Toggle a players setting status.
function doPlayerToggleSettingStatus(cid, settingId)
-- Make sure player exist
if(not isPlayer(cid)) then
return false
end
-- Make settingId to binary
settingId = settingId ^ 2
-- Retrieve players current settings
local settings = getPlayerStorageValue(cid, SETTINGS_STORAGE_VALUE)
-- Reset settings if -1
if(settings < 0) then
settings = 0
end
-- Toggle setting status
settings = bit.bxor(settings, settingId)
-- Save settings
setPlayerStorageValue(cid, SETTINGS_STORAGE_VALUE, settings)
-- Everything was done without errors
return true
end
Now open data.lua and add the following lines:
Lua:
dofile(getDataDir() .. "lib/settings.lua")
dofile(getDataDir() .. "lib/setting_system.lua")
That's it! Now how to use them ?
Example, talkaction.
Lua:
function onSay(cid)
doPlayerToggleSettingStatus(cid, MY_TEST_SETTING)
doCreatureSay(cid, "Setting is: " .. getPlayerSettingStatus(cid, MY_TEST_SETTING and "ON" or "OFF", 1)
return TRUE
end
This will turn on/off each time you use it. Because it will always toggle. But you can use only setPlayerSettingStatus(cid, MY_TEST_SETTING, true) and it will be on, and you write false to turn it off.
Hope you understood!
Regards,
Colandus
Last edited: