• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.2 [data/logs]

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,051
Solutions
2
Reaction score
260
Location
United States
So i am trying to make it so it shows the logs when a GM/God makes an item, but when ever i do /i 2160 for example it does not show in the logs :|

This is my logs folder: Logs

Any ideas?
 
commands in commands.xml in xml folder has the option of logging then, as far as i see there isnt any option
however you could do some custom logging something like this
Code:
local file = io.open(".data\logs\"..player:getName()..".lua")
file:write("\n"..os.time().." "..player:getName()..": "..words.." "..param)
file:close()
which would need to be added to all commands you wish to log
 
Code:
local file = io.open(".data\logs\"..player:getName()..".lua")
file:write("\n"..os.time().." "..player:getName()..": "..words.." "..param)
file:close()

So i just add this at the top of every command, yes?
 
test it to make sure it works, then yes
So i tried adding i to create_item like this

Code:
local file = io.open(".data\logs\"..player:getName()..".lua")
file:write("\n"..os.time().." "..player:getName()..": "..words.." "..param)
file:close()

function onSay(cid, words, param)
    local player = Player(cid)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    local count = tonumber(split[2])
    if count ~= nil then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:hasSubType() then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(1, count)
        end
    else
        count = 1
    end

    local result = player:addItem(itemType:getId(), count)
    if result ~= nil then
        if not itemType:isStackable() then
            if type(result) == "table" then
                for _, item in ipairs(result) do
                    item:decay()
                end
            else
                result:decay()
            end
        end
        if(not isPlayerGhost(cid)) then
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
    end
    return false
end

But it doesn't work :| i get error

Code:
[Warning - Event::checkScript] Can not load script: scripts/create_item.lua data/talkactions/scripts/create_item.lua:1: invalid escape sequence near '".data'
 
and change onSay(cid, ...) to onSay(player, ...) since its 1.2 and userdata and not cid..
and remove local player = Player(cid) and add
if not isPlayer(player) then
return false
end
 
and change onSay(cid, ...) to onSay(player, ...) since its 1.2 and userdata and not cid..
and remove local player = Player(cid) and add
if not isPlayer(player) then
return false
end
Ok i got that, is it the same for this? Lets say i wanna do (/t player name) to teleport him to temple, but /t only works to teleport the character that uses it

Code:
function onSay(cid, words, param)
    local player = Player(cid)
    if not player:getGroup():getAccess() then
        return true
    end

    local town = Town(param)
    if town == nil then
        player:sendCancelMessage("Town not found.")
        return false
    end

    player:teleportTo(town:getTemplePosition())
    return false
end
 
@God Mythera no you will get player from param not town. e.g
Code:
function onSay(player, words, param)
    local target = Player(param)
    if not player:getGroup():getAccess() then
        return true
    end

    if target == nil then
        player:sendCancelMessage("Player not found.")
        return false
    end

    target:teleportTo(target:getTown():getTemplePosition())
    return false
end
it still does not work if you don't difine it string split parameter, which in this case is an " " (space) so do it in talkactions.xml with separator=" "
 
Last edited:
@God Mythera no you will get player from param not town. e.g
Code:
function onSay(cid, words, param)
    local target = Player(param)
    if not player:getGroup():getAccess() then
        return true
    end

    if target == nil then
        player:sendCancelMessage("Player not found.")
        return false
    end

    target:teleportTo(target:getTown():getTemplePosition())
    return false
end
it still does not work if you don't difine it string split parameter, which in this case is an " " (space) so do it in talkactions.xml with separator=" "
Code:
<talkaction words="/t" separator=" " script="teleport_home.lua" />

Code:
function onSay(cid, words, param)
    local target = Player(param)
    if not player:getGroup():getAccess() then
        return true
    end

    if target == nil then
        player:sendCancelMessage("Player not found.")
        return false
    end

    target:teleportTo(target:getTown():getTemplePosition())
    return false
end

:S
 
@God Mythera stop using cid for player userdata please, but somehow you prefer to use it call methods to cid instead player, e.g
cid:getGroup():getAccess() then
cid:sendCancelMessage("Player not found.")
i just copied and pasted your code, i didnt noticed that you changed default player parameter to cid, so thats because doesnt let you teleport, server couldn't get your userdata because it was suppose to be player not cid, as i said if you want to keep using cid then call methods to CID: not PLAYER:.
 
@God Mythera stop using cid for player userdata please, but somehow you prefer to use it call methods to cid instead player, e.g
cid:getGroup():getAccess() then
cid:sendCancelMessage("Player not found.")
i just copied and pasted your code, i didnt noticed that you changed default player parameter to cid, so thats because doesnt let you teleport, server couldn't get your userdata because it was suppose to be player not cid, as i said if you want to keep using cid then call methods to CID: not PLAYER:.
As long as the parameter which represents cid/player or any others for that matter are used appropriately it doesn't matter what the value is labeled as. For public distribution of scripts you would want to use the familiar labels however for your own scripts you don't need to conform to such standards here is an example of what I mean.
Code:
function onSay(c, w, p)
    local t = Player(p)
    local c = type(c) == 'userdata' and c or Player(c)
    if c:getGroup():getAccess() < ACCOUNT_TYPE_GOD then
        return true
    end

    if t == nil then
        c:sendCancelMessage("Player not found.")
        return false
    end

    t:teleportTo(t:getTown():getTemplePosition())
    return false
end
 
As long as the parameter which represents cid/player or any others for that matter are used appropriately it doesn't matter what the value is labeled as. For public distribution of scripts you would want to use the familiar labels however for your own scripts you don't need to conform to such standards here is an example of what I mean.
i know that,
local t = Player(p) local c = type(c) == 'userdata' and c or Player(c)
and this is useless, you don't need to tell it since parameter you call is the same to methods, would be needed if for example:
Code:
function onSay(a, b, c)
local t = Player(c)
local c = type(a) == 'userdata' and a or Player(c)
if c:getGroup():getAccess() < ACCOUNT_TYPE_GOD then
return true
end
 
Back
Top