• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X All players start with VIP - Add VIP Time all accounts

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,402
Solutions
17
Reaction score
150
Location
Brazil
Hi, I have a VIP by accounts system that works perfectly for me, based on these functions:

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if query:getID() == -1 then
    return func("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. getPlayerAccountId(cid) ..", ".. key ..", ".. value ..")")
  end
  return func("UPDATE `account_storage` SET `value` = ".. value .." WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
end

function isVIP(cid)
  return getAccountVIP(cid) > 0
end

function getAccountVIP(cid)
  return (getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() > 0) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() or 0
end

function setAccountVIP(cid, days)
  return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (60 * 60 * 24 * days) + (getAccountVIP(cid) > 0 and  getAccountVIP(cid) or 0))
end

I have two requests: how do I get all accounts created to start with two days of VIP? Another question is, how to give two days of VIP to all accounts already created?
 
Solution
For new accounts;

inside login.lua, where a character logs in for the first time, add

Lua:
if getAccountStorage(cid, VIP_ACCOUNT_STORAGE) == -1 then
    setAccountVIP(cid, 2)
end

For existing accounts, you'd have to do a database query/execution.
I know this is the correct way, but I don't work with sql queries enough to accurately write what you're looking to do.
For new accounts;

inside login.lua, where a character logs in for the first time, add

Lua:
if getAccountStorage(cid, VIP_ACCOUNT_STORAGE) == -1 then
    setAccountVIP(cid, 2)
end

For existing accounts, you'd have to do a database query/execution.
I know this is the correct way, but I don't work with sql queries enough to accurately write what you're looking to do.
 
Solution
For new accounts;

inside login.lua, where a character logs in for the first time, add

Lua:
if getAccountStorage(cid, VIP_ACCOUNT_STORAGE) == -1 then
    setAccountVIP(cid, 2)
end

For existing accounts, you'd have to do a database query/execution.
I know this is the correct way, but I don't work with sql queries enough to accurately write what you're looking to do.
Could this script inside login.lua not bug? As my VIP is per account, would each character created within that account not add 2 days of VIP?
 
Could this script inside login.lua not bug? As my VIP is per account, would each character created within that account not add 2 days of VIP?
You could figure that out yourself by testing my proposed solution.
 
For new accounts;

inside login.lua, where a character logs in for the first time, add

Lua:
if getAccountStorage(cid, VIP_ACCOUNT_STORAGE) == -1 then
    setAccountVIP(cid, 2)
end

For existing accounts, you'd have to do a database query/execution.
I know this is the correct way, but I don't work with sql queries enough to accurately write what you're looking to do.
Worked, in storage keep a value greather then 16.... (timestamp), thanks @Xikini
 

Similar threads

Back
Top