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

attempt to call global getMana

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
537
Reaction score
56
So im trying to make a code but it gives that error im pretty sure im using tfs 1.2 functions
Code:
function onUse(cid, item, frompos, item2, topos)
player1 = getThingfromPos(topos)
lol = getPlayerName(player1.uid)

local nick = getPlayerName(player1.uid)
local ki = getPlayerMagLevel(player1.uid)
local lvl = getPlayerLevel(player1.uid)
local mana = getMana(player1.uid)
local hp = getHealth(player1.uid)
local maxmana = getMaxMana(player1.uid)
local maxhp = getMaxHealth(player1.uid)
local access = getPlayerAccess(player1.uid)

if isPlayer(player1.uid) ~= 1 then
doPlayerSendCancel(cid,"You can only use on players.")


elseif access <= 3 then
doPlayerSendTextMessage(cid,22, 'Nick: '..nick..'')
doPlayerSendTextMessage(cid,22, 'Level: '..lvl..'')
doPlayerSendTextMessage(cid,22, 'Ki Level: '..ki..'')
doPlayerSendTextMessage(cid,22, 'Hp: '..hp..'/'..maxhp..'')
doPlayerSendTextMessage(cid,22, 'Ki Points: '..mana..'/'..maxmana..'')
else
return 0
end
return 1
end
 
Solution
try
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if type(target) ~= "userdata" or not target:isPlayer() then
        player:sendCancelMessage("You can only use on players.")
        return false
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Nick: " .. target:getName())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Level: " .. target:getLevel())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Health Points: " .. target:getHealth() .. "/" .. target:getMaxHealth())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Ki Points: " .. target:getMana() .. "/" .. target:getMaxMana())
    return true
end
these are not tfs 1.2 functions, your coding style is old < 1.x style. You should use objects (userdatas) and cast functions on them like

Lua:
local player = Player(playerId)
if player then
    local mana = player:getMana()
end

onUse actually uses player as parameter now, its object (userdata), you can use it like
Lua:
player:sendTextMessage()
player:getMana()
and so on.
 
these are not tfs 1.2 functions, your coding style is old < 1.x style. You should use objects (userdatas) and cast functions on them like

Lua:
local player = Player(playerId)
if player then
    local mana = player:getMana()
end

onUse actually uses player as parameter now, its object (userdata), you can use it like
Lua:
player:sendTextMessage()
player:getMana()
and so on.
I guess im still doing something wrong. No errors but it doesnt work.
Lua:
function onUse(cid, item, frompos, item2, topos)
player1 = getThingfromPos(topos)

local player = Player(playerId)
if player then
    local mana = player:getMana()
    local maxmana = player:getMaxMana()
end

if isPlayer(player1.uid) ~= 1 then
doPlayerSendCancel(cid,"You can scout only players.") 


elseif access <= 3 then
player:sendTextMessage(cid,22, 'Ki Points: '..mana..'/'..maxmana..'')
    else 
        return 0
    end
    return 1
end
 
I guess im still doing something wrong. No errors but it doesnt work.
Lua:
function onUse(cid, item, frompos, item2, topos)
player1 = getThingfromPos(topos)

local player = Player(playerId)
if player then
    local mana = player:getMana()
    local maxmana = player:getMaxMana()
end

if isPlayer(player1.uid) ~= 1 then
doPlayerSendCancel(cid,"You can scout only players.")


elseif access <= 3 then
player:sendTextMessage(cid,22, 'Ki Points: '..mana..'/'..maxmana..'')
    else
        return 0
    end
    return 1
end
bump
 
Sorry, I suck with TFS 1.2
Hope this works.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getGroup():getAccess() then
        return true
    end
    if type(target) == "userdata" and not target:isPlayer() then
        return true
    end
    local mana = target:getMana()
    local maxmana = target:getMaxMana()
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Ki Points: " .. mana .. "/" .. maxmana .. "")
    return true
end
 
Last edited:
Sorry, I suck with TFS 1.2
Hope this works.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getGroup():getAccess() then
        return true
    end
    if type(target) == "userdata" and not target:isPlayer() then
        return true
    end
    local mana = target:getMana()
    local maxmana = target:getMaxMana()
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Ki Points: " .. mana .. "/" .. maxmana .. "")
    return true
end
If not target is enough or target and not target:isPlayer()
If you wont gonna use mana and maxmana variables anywhere else, then its pointless to declare them into variables, concatenate them directly into string.
 
If not target is enough or target and not target:isPlayer()
If you wont gonna use mana and maxmana variables anywhere else, then its pointless to declare them into variables, concatenate them directly into string.
Sorry wasn't sure about the userdata part, since the tfs source on github was using it in the potions.lua file.
Figured it was required in case you misclicked on a floor tile or something.
 
Sorry, I suck with TFS 1.2
Hope this works.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getGroup():getAccess() then
        return true
    end
    if type(target) == "userdata" and not target:isPlayer() then
        return true
    end
    local mana = target:getMana()
    local maxmana = target:getMaxMana()
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Ki Points: " .. mana .. "/" .. maxmana .. "")
    return true
end
It says you cannot use this object, not sure if its dat/otb problem
 
try
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if type(target) ~= "userdata" or not target:isPlayer() then
        player:sendCancelMessage("You can only use on players.")
        return false
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Nick: " .. target:getName())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Level: " .. target:getLevel())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Health Points: " .. target:getHealth() .. "/" .. target:getMaxHealth())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Ki Points: " .. target:getMana() .. "/" .. target:getMaxMana())
    return true
end
 
Solution
try
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if type(target) ~= "userdata" or not target:isPlayer() then
        player:sendCancelMessage("You can only use on players.")
        return false
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Nick: " .. target:getName())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Level: " .. target:getLevel())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Health Points: " .. target:getHealth() .. "/" .. target:getMaxHealth())
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Ki Points: " .. target:getMana() .. "/" .. target:getMaxMana())
    return true
end
Works perfectly
Is there an error?
It was clean console.
 
Back
Top