• 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 TFS 1.2 - Remove item completely and add points based on amount of Charges

Eldora

Banned User
Joined
Oct 19, 2009
Messages
604
Reaction score
26
Right now, this .lua script removes 1 charge and adds 1 point per charge to the account.
I want the script to remove the item completely and add amount of points equal to the amount of charges that the item had when being used.

Basically, if (item1) has 50 charges, then on use, it should remove the item completely and add 50 points to the account.


Lua:
local addpoints = 1 -- amount of points to add

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isPlayer(player) and item:getCharges() and doRemoveItem(item.uid, 1) then
        db.query("UPDATE znote_accounts SET points = points + "..addpoints.." WHERE account_id = '" ..player:getAccountId().. "';")
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, ""..addpoints.." Points has been added to your account.")
        return true
    else
        return false
    end
end
 
Right now, this .lua script removes 1 charge and adds 1 point per charge to the account.
I want the script to remove the item completely and add amount of points equal to the amount of charges that the item had when being used.

Basically, if (item1) has 50 charges, then on use, it should remove the item completely and add 50 points to the account.


Lua:
local addpoints = 1 -- amount of points to add

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isPlayer(player) and item:getCharges() and doRemoveItem(item.uid, 1) then
        db.query("UPDATE znote_accounts SET points = points + "..addpoints.." WHERE account_id = '" ..player:getAccountId().. "';")
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, ""..addpoints.." Points has been added to your account.")
        return true
    else
        return false
    end
end
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local getPoints = (item:getCharges() * 1)
    if item:getCharges() >= 1 then
        db.query("UPDATE znote_accounts SET points = points + "..getPoints.." WHERE account_id = '" ..player:getAccountId().. "';")
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, ""..getPoints.." Points has been added to your account.")
        item:remove() -- remove item
        return true
    else
        return false
    end
end
 
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local getPoints = (item:getCharges() * 1)
    if item:getCharges() >= 1 then
        db.query("UPDATE znote_accounts SET points = points + "..getPoints.." WHERE account_id = '" ..player:getAccountId().. "';")
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, ""..getPoints.." Points has been added to your account.")
        item:remove() -- remove item
        return true
    else
        return false
    end
end

Hi @mano368, that did not work, only says "You cannot use this object." now.
No error in the console or anything, it just made the item not usable?
 
can you give me information like name and what the item does? I dont have acess to newer item id

The item is basically just a currency (copy of gold coin).
I want it to give the player shop points, based on the amount. The max amount per "stack" is 100.
So if it has 50 charges, then it should remove the item and give you 50 points basically.

Do you think you can modify the script to work?
 
The item is basically just a currency (copy of gold coin).
I want it to give the player shop points, based on the amount. The max amount per "stack" is 100.
So if it has 50 charges, then it should remove the item and give you 50 points basically.

Do you think you can modify the script to work?
Then its not charges like runes.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
      local getPoints = (item:getItemCount() * 1)

      db.query("UPDATE `znote_accounts` SET `points` = `points` + ".. getPoints .." WHERE `account_id` = '" ..player:getAccountId().. "';") -- add player points
      player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "".. getPoints .." Points has been added to your account.") -- send msg with information
      item:remove() -- remove item

      return true
end

if you doesnt have any "if" to let player dont add points, then this will work everytime well
 
Last edited:
Then its not charges like runes.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
      local getPoints = (item:getItemCount() * 1)

      db.query("UPDATE `znote_accounts` SET `points` = `points` + ".. getPoints .." WHERE `account_id` = '" ..player:getAccountId().. "';") -- add player points
      player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "".. getPoints .." Points has been added to your account.") -- send msg with information
      item:remove() -- remove item

      return true
end

if you doesnt have any "if" to let player dont add points, then this will work everytime well
1675111308823.png

It doesn't recognize "getItemCount"?
I'm using TFS 1.2
 
View attachment 73094

It doesn't recognize "getItemCount"?
I'm using TFS 1.2
oh, sorry, its getcount

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
      local getPoints = (item:getCount() * 1)

      db.query("UPDATE `znote_accounts` SET `points` = `points` + ".. getPoints .." WHERE `account_id` = '" ..player:getAccountId().. "';") -- add player points
      player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "".. getPoints .." Points has been added to your account.") -- send msg with information
      item:remove() -- remove item

      return true
end
 
oh, sorry, its getcount

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
      local getPoints = (item:getCount() * 1)

      db.query("UPDATE `znote_accounts` SET `points` = `points` + ".. getPoints .." WHERE `account_id` = '" ..player:getAccountId().. "';") -- add player points
      player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "".. getPoints .." Points has been added to your account.") -- send msg with information
      item:remove() -- remove item

      return true
end

Thank you very much, can I add you on Discord possibly?
 
Back
Top