• 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!

Lua DoAccountAddPremium_points??

Ataro

Member
Joined
Oct 28, 2010
Messages
689
Reaction score
19
Location
Netherlands
Is there an lua script for that?
I want that if you say example: !test
you loose 5 premium points.
This is not working:
Lua:
  if doPlayerAccountAddPremium_Points(cid, -5) == true then
Neither is:
Lua:
  if doAccountAddPremium_Points(cid, -5) == true then
Full script:
Lua:
function onSay(cid, words, param)

local test = 8931

  if doPlayerAccountAddPremium_Points(cid, -5) == true then
	doPlayerPopupFYI(cid, "Working :O ")
	doPlayerAddItem(cid, test, 1)
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
  else
	doPlayerSendCancel(cid, "Sorry, test error xD .")
  end
return true
end
Someone can help me?
 
Last edited:
Premium days and premium points are not the same though. There's no function like that in the original TFS revs as of yet (if ever. Remember that the premium points field is not an official database field).
 
You can create a new function, creating a database connection (unless there's a global one? doubt it though) and run a query to remove the number of days specified through a parameter.
 
I'm afraid I do not have a script for it, sorry.
It would look something like this though (I'm not actually creating the script, so do not try to use the following code, it is merely an example):
Lua:
function doAddAccountPremiumPoints(account, points)
     local db = databaseConnectionHere
     if not db.query("query here") then
          doSendCancel(cid, "Sorry, it failed")
     end

     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It worked!")
     return TRUE
end
 
so for me it would be like:
Lua:
function doAddAccountPremiumPoints(account, points)
     local db = databaseConnectionHere
     if not db.query("premium_points") then
          doSendCancel(cid, "Sorry, it failed")
     end
 
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It worked!")
     return TRUE
end


where to put it? xDD
??
 
I'm not sure how the database connection works with LUA as I haven't really used it. And I haven't done any LUA scripts for slightly over a year. It might not even be db.query to execute a query. As I stated in my above post, this was merely an example. Not an actual functioning script.
 
Code:
function doAddAccountPremiumPoints(account, points)
	local p = ""
	if tostring(points):sub(1, 2) == "-" then
		p = "-";
	elseif tostring(points):sub(1, 2) == "+" then
		p = "+";
	end
	local query = "UPDATE `accounts` SET `premdays` = `premdays` " .. p .. " " .. tostring(points):sub(2) .. " WHERE `account` = " .. account .. ";"
	if not db.executeQuery(query) then
		return false
	end
	return true
end
not tested
 
open lib/function.lua
and add this code
Lua:
function addpremiumpoint(cid,amount)
local getpoint = getPlayerAccount(cid)
local Info = db.getResult("SELECT * FROM `accounts` WHERE `name` = '"..getpoint.."'")
point = tonumber(Info:getDataInt("premium_points"))
name = tonumber(Info:getDataInt("name"))
newpoint = point + amount 
db.executeQuery("UPDATE `accounts` SET `premium_points` ='"..newpoint.."' WHERE `name` = '"..name.."'")
return true 
end
function removepremiumpoint(cid,amount)
local getpoint = getPlayerAccount(cid)
local Info = db.getResult("SELECT * FROM `accounts` WHERE `name` = '"..getpoint.."'")
point = tonumber(Info:getDataInt("premium_points"))
name = tonumber(Info:getDataInt("name"))
newpoint = point - amount 
db.executeQuery("UPDATE `accounts` SET `premium_points` ='"..newpoint.."' WHERE `name` = '"..name.."'")
return true 
end
now to add premium point to player use this
Lua:
addpremiumpoint(cid, amount)
and to remove point use this
Lua:
removepremiumpoint(cid, amount)
 
Last edited:
Code:
function doAddAccountPremiumPoints(account, points)
	local p = ""
	if tostring(points):sub(1, 2) == "-" then
		p = "-";
	elseif tostring(points):sub(1, 2) == "+" then
		p = "+";
	end
	local query = "UPDATE `accounts` SET `premdays` = `premdays` " .. p .. " " .. tostring(points):sub(2) .. " WHERE `account` = " .. account .. ";"
	if not db.executeQuery(query) then
		return false
	end
	return true
end
not tested
Now this is more like it! Although, I would change elseif tostring(points):sub(1, 2) == "+" then to else. Otherwise he would have to do +1, +2, +3 whenever he would like to actually add points.
 
Or simply this instead..
Lua:
function doAddPremiumPoints(accountName, points)
	points = tostring(points)
	return db.executeQuery('UPDATE `accounts` SET `premium_points` = `premium_points` ' .. (not points:find('^%-') and '+' or '-') .. points:sub(points:find('%d+')) .. ' WHERE `name` = ' .. accountName .. ' LIMIT 1;')
end
To remove, just place a - in front of the number.
 

Similar threads

Back
Top