• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Add Premium point to acc by action (mystic spirit)

zerghel

Tsuni
Joined
Jul 1, 2008
Messages
299
Reaction score
9
as the title says
i would like to use a book and earn 1 premium point(book dissapear) i had it for crying damnson bout i'm using now mystic spirit for stability but i can't figure how to execute an sql query via lua script, im not a scripter myself but i've been looking this mystic spirit "deathlist" script and i can see it is executing an sql query to get the info, this script works properly so i think is possible to execute a sql query via action lua script, please i need this so bad, here's the script
Code:
function onSay(cid, words, param)
	dofile("./config.lua")
	if sqlType == "mysql" then
		env = assert(luasql.mysql())
		con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	else -- sqlite
		env = assert(luasql.sqlite())
		con = assert(env:connect(sqliteDatabase))
	end
	cur = assert(con:execute("SELECT `name`, `id` FROM `players` WHERE `name` = '" .. escapeString(param) .. "';"))
	row = cur:fetch ({}, "a")
	local targetName = ""
	local targetGUID = 0
	while row do
		targetName = row.name
		targetGUID = row.id
		row = cur:fetch (row, "a")
	end
	cur:close()
	if targetName == "" then
		doPlayerSendCancel(cid, "A player with that name does not exist.")
	else
		local str = ""
		local breakline = ""
		for time, level, killed_by, is_player in rows(con, "SELECT `time`, `level`, `killed_by`, `is_player` FROM `player_deaths` WHERE `player_id` = " .. targetGUID .. " ORDER BY `time` DESC;") do
			if str ~= "" then
				breakline = "\n"
			end
			local date = os.date("*t", time)

			local article = ""
			if is_player ~= TRUE then
				killed_by = string.lower(killed_by)
				article = getArticle(killed_by) .. " "
			end

			if date.day < 10 then	date.day = "0" .. date.day	end
			if date.hour < 10 then	date.hour = "0" .. date.hour	end
			if date.min < 10 then	date.min = "0" .. date.min	end
			if date.sec < 10 then	date.sec = "0" .. date.sec	end
			str = str .. breakline .. " " .. date.day .. getMonthDayEnding(date.day) .. " " .. getMonthString(date.month) .. " " .. date.year .. " " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. "   Died at Level " .. level .. " by " .. article .. killed_by .. "."
		end
		if str == "" then
			str = "No deaths."
		end
		doPlayerPopupFYI(cid, "Deathlist for player, " .. targetName .. ".\n\n" .. str)
	end
	con:close()
	env:close()
end

as you can see the query is there but im just too noob to script an action for premium points
 
LUA:
local cfg =  {
	points = 100,
	effect = CONST_ME_GIFT_WRAPS
}

dofile('./config.lua')

function addPoints(playerName, amount)
	local accNum = getAccountNumberByPlayerName(playerName)

	if accNum == 0 or amount == 0 then
		return
	end

	local env = assert(luasql.mysql())
	local con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	assert(con:execute('UPDATE `accounts` SET `premium_points` = `premium_points` + ' .. amount .. ' WHERE `id` = ' .. accNum .. ' LIMIT 1;'))
	con:close()
	env:close()
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if isPlayer(itemEx.uid) == FALSE then
		return FALSE
	end

	addPoints(getCreatureName(itemEx.uid), cfg.points)
	doCreatureSay(itemEx.uid, 'You have received ' .. cfg.points .. ' premium points!', TALKTYPE_ORANGE_1)
	doSendMagicEffect(toPosition, cfg.effect)
	doChangeTypeItem(item.uid, item.type - 1)
	return TRUE
end
 
for mystic spirit 0.2.7 i did
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + 1 WHERE `id` = ".. [COLOR="red"]getAccountNumberByPlayerName(name)[/COLOR] ..";")
	doRemoveItem(item.uid)
return TRUE
end
ok the item dissapear now, no errors in console, but is not updating prem points in database

i repeat: im not a scripter myself xD
 
Code:
local cfg = {
	points = 100,
	effect = CONST_ME_GIFT_WRAPS
}
 
dofile('./config.lua')
 
function addPoints(playerName, amount)
	local accNum = getAccountNumberByPlayerName(playerName)
 
	if accNum == 0 or amount == 0 then
		return
	end
 
	local env = assert(luasql.mysql())
	local con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	assert(con:execute('UPDATE `accounts` SET `premium_points` = `premium_points` + ' .. amount .. ' WHERE `id` = ' .. accNum .. ' LIMIT 1;'))
	con:close()
	env:close()
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if isPlayer(itemEx.uid) == FALSE then
		return FALSE
	end
 
	addPoints(getCreatureName(itemEx.uid), cfg.points)
	doCreatureSay(itemEx.uid, 'You have received ' .. cfg.points .. ' premium points!', TALKTYPE_ORANGE_1)
	doSendMagicEffect(toPosition, cfg.effect)
	doChangeTypeItem(item.uid, item.type - 1)
	return TRUE
end
i sends no error to console, but it says ingame, "you can not use this object"
 
Code:
local cfg = {
	points = 100,
	effect = CONST_ME_GIFT_WRAPS
}
 
dofile('./config.lua')
 
function addPoints(playerName, amount)
	local accNum = getAccountNumberByPlayerName(playerName)
 
	if accNum == 0 or amount == 0 then
		return
	end
 
	local env = assert(luasql.mysql())
	local con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	assert(con:execute('UPDATE `accounts` SET `premium_points` = `premium_points` + ' .. amount .. ' WHERE `id` = ' .. accNum .. ' LIMIT 1;'))
	con:close()
	env:close()
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if isPlayer(itemEx.uid) == FALSE then
		return FALSE
	end
 
	addPoints(getCreatureName(itemEx.uid), cfg.points)
	doCreatureSay(itemEx.uid, 'You have received ' .. cfg.points .. ' premium points!', TALKTYPE_ORANGE_1)
	doSendMagicEffect(toPosition, cfg.effect)
	doChangeTypeItem(item.uid, item.type - 1)
	return TRUE
end
i sends no error to console, but it says ingame, "you can not use this object"

I made it for items which are useable (with crosshairs/right click)

Use this for non-useable items:
LUA:
local cfg = {
	points = 100,
	effect = CONST_ME_GIFT_WRAPS
}
 
dofile('./config.lua')
 
function addPoints(playerName, amount)
	local accNum = getAccountNumberByPlayerName(playerName)
 
	if accNum == 0 or amount == 0 then
		return
	end
 
	local env = assert(luasql.mysql())
	local con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	assert(con:execute('UPDATE `accounts` SET `premium_points` = `premium_points` + ' .. amount .. ' WHERE `id` = ' .. accNum .. ' LIMIT 1;'))
	con:close()
	env:close()
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	addPoints(getCreatureName(cid), cfg.points)
	doCreatureSay(cid, 'You have received ' .. cfg.points .. ' premium points!', TALKTYPE_ORANGE_1)
	doSendMagicEffect(getThingPos(cid), cfg.effect)
	doChangeTypeItem(item.uid, item.type - 1)
	return TRUE
end
 
Back
Top