• 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 Database script?

mayel

New Member
Joined
Sep 11, 2009
Messages
174
Reaction score
2
Location
Stockholm, Sweden
Does anyone know how I, simply as possible can edit columns in tables in my mysql database with scripts in the game.
Like u press a lever and a column in the "players" table called vipdays changes to 30.
And if you know how to make it to change to +30,(add 30 days to current value)
I'm supposed to use this right? ---db.executeQuery(query)---
it's even better.
Btw how do i make random numbers in lua?
Thanks in advance... :)
I'm sure theres a lot of errors in this code but please tell me what's wrong:

function onUse(cid, item, frompos, itemEx, topos)
db.executeQuery(UPDATE players SET level = 8; WHERE name = "Test"; )
return true
end
 
Last edited:
UPDATE `players` SET `vipdays` = `vipdays` + '30'....... something like that, and just a tip, wouldn't be better to have the vip for the whole acc instead of the character?
 
Here is the correct query you need to execute in an action script.

Code:
local days = 10
db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")

Database:

EACH Account VIP:
Code:
ALTER TABLE `accounts` ADD `vipdays` INT NOT NULL DEFAULT 0;

To put it in an action script (use item and get days) you simply change it to this.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local days = 10
	return db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";") and doRemoveItem(item.uid)
end

Adding Magic Effects:

Change:
Code:
return db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";") [COLOR="red"]and doRemoveItem(item.uid)[/COLOR]

To:
Code:
return db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";") [COLOR="red"]and doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS) and doRemoveItem(item.uid)[/COLOR]

Adding a Message or Orange Letters:

Change:
Code:
return db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";") [COLOR="red"]and doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS) and doRemoveItem(item.uid)[/COLOR]

To:
Code:
return db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";") [COLOR="red"]and doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS) and doCreatureSay(cid, "You have received " .. days .. " VIP days!", TALKTYPE_ORANGE_1) doRemoveItem(item.uid)[/COLOR]

Final Product:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local days = 10
	return db.executeQuery("UPDATE `accounts` SET `vipdays` = `vipdays` + " .. days .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";") and doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS) and doCreatureSay(cid, "You have received " .. days .. " VIP days!", TALKTYPE_ORANGE_1) and doRemoveItem(item.uid)
end
 
rand = math.random(1,2,3,4)
doSendMagicEffect(getThingPos(cid) CONST_ME_rand)
end
 
Back
Top