Coin 表用于操作账号的 WCoinC(Credits)和 GoblinPoint 余额。此版本不存在 WCoinP:其值始终为 0,增加 / 扣除时会被忽略。增加和扣除函数会立即保存数据库,并把新的余额发送给客户端的 Cash Shop。

增加 / 扣除函数要求角色正在游戏中(PLAYING),不在 onPlayerLogout 中,且脚本不处于受限模式。读取函数只要求角色已登录。

Coin.Get

读取账号的 coin 余额。

Coin.Get(aIndex) -> table
参数类型说明
aIndexinteger角色索引

返回值:包含 3 个数值字段的表:WCoinC、WCoinP(始终为 0)、GoblinPoint。如果角色无效,WCoinC 和 GoblinPoint 均为 0。简称:CashShopGetPoint(返回表);ObjectGetCoin(aIndex) 返回 3 个数值 WCoinC, WCoinP, GoblinPoint。

local c = Coin.Get(aIndex)
Message.Send(aIndex, 1, "WCoin: " .. c.WCoinC .. ", Goblin: " .. c.GoblinPoint)

Coin.Add

为账号增加 coin。

Coin.Add(aIndex, wcoinC, wcoinP, goblinPoint) -> boolean
参数类型说明
aIndexinteger角色索引
wcoinCinteger增加的 WCoinC 数量(负数或省略 = 0)
wcoinPinteger未使用(必须传入一个值,例如 0,以便 goblinPoint 位于第 4 个位置)
goblinPointinteger增加的 GoblinPoint 数量(负数或省略 = 0)

返回值:已执行则为 true(数量为 0 时也是);角色不符合条件则为 false。每种余额不超过 2147483647(增加量会被截断以适应上限)。简称:CashShopAddPoint、ObjectAddCoin。

Coin.Add(aIndex, 100, 0, 5)   -- +100 WCoinC, +5 GoblinPoint

Coin.Sub

扣除账号的 coin。如果余额不足则不扣除任何内容。

Coin.Sub(aIndex, wcoinC, wcoinP, goblinPoint) -> boolean
参数类型说明
aIndexinteger角色索引
wcoinCinteger需扣除的 WCoinC 数量(负数或省略 = 0)
wcoinPinteger未使用(传入 0)
goblinPointinteger需扣除的 GoblinPoint 数量(负数或省略 = 0)

返回值:已扣除则为 true;两种余额中任意一种不足,或角色不符合条件时为 false。简称:CashShopSubPoint、ObjectSubCoin。

if Coin.Sub(aIndex, 50, 0, 0) then
    Item.Give(aIndex, { Index = 7181, Count = 1 })
else
    Message.Send(aIndex, 1, "WCoin 不足")
end