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

Talkaction command (Database connect) Rep+ to the one help me!

RealSoft

Banned User
Joined
Feb 3, 2009
Messages
4,381
Reaction score
92
Location
There I sleep
I would love if someone could help me out a bit before I go all crazy about this one..

This error is from Avesta 0.6.3
helps.jpg


This is the script make the error:
PHP:
local COST = 20
local ADD_ITEM = "yes"


function onSay(cid, words, param, channel)

   if getPlayerLevel(cid) > 1 then
        local query = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        local points = query:getDataInt("premium_points")
        if points >= COST then
            local update = db.executeQuery("UPDATE `accounts` SET `premium_points`= "..(points - COST).." WHERE `id`= " .. getPlayerAccountId(cid) .. "; ")
            if (update == true) then            
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your red skull has been taken off!\nRemaining premium points: " .. (points - COST))
                doCreatureSetSkullType(cid, SKULL_NONE)
                if (ADD_ITEM == "yes") then
                    doPlayerAddItem(cid,2181,1)
                end

				
            else
                doPlayerSendCancel(cid, "Database error")
            end
           
        else
            doPlayerSendCancel(cid, "You need " ..COST.. " premium points to remove red skull")
        end
    else
        doPlayerSendCancel(cid, "You need to be level 2 or above to use this command!")
    end
   
    query:free()
    return TRUE
   
end

Rep++ to the one help me out!
 
Code:
local COST = 20
local ADD_ITEM = true

function onSay(cid, words, param, channel)
	if getPlayerLevel(cid) > 1 then
		dofile("./config.lua")
		local env = assert(luasql.mysql())
		local con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
		local cur = assert(con:execute("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. ";"))
		local row = cur:fetch({})
		cur:close()
		if row ~= nil then
			points = row.premium_points
		end
		con:close()
		env:close()
		if points >= COST then
			env = assert(luasql.mysql())
			con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
			local update = assert(con:execute("UPDATE `accounts` SET `premium_points`= "..(points - COST).." WHERE `id`= " .. getPlayerAccountId(cid) .. ";"))
			con:close()
			env:close()
			if(update) then            
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your red skull has been taken off!\nRemaining premium points: " .. (points - COST))
				doCreatureSetSkullType(cid, SKULL_NONE)
				if(ADD_ITEM) then
					doPlayerAddItem(cid,2181,1)
				end
			else
				doPlayerSendCancel(cid, "Database error")
			end
		else
			doPlayerSendCancel(cid, "You need " ..COST.. " premium points to remove red skull")
		end
	else
		doPlayerSendCancel(cid, "You need to be level 2 or above to use this command!")
	end
	return TRUE
end
I'll optimize later, if it even works.
 
Back
Top Bottom