Jump to content

Hi guys, help me :)


Musamba

Recommended Posts

I always get the output "not found", it's a command:

if string.find(favs[1].favmaps, currentMap) then 
            outputChatBox("found") 
            if string.find(favs[1].favmaps, ","..currentMap)  then 
                executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(favs[1].favmaps,","..currentMap, "").."' WHERE serial=?", serial) 
            elseif string.find(favs[1].favmaps, currentMap..",") then 
                executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(favs[1].favmaps,currentMap..",", "").."' WHERE serial=?", serial) 
            end 
            outputChatBox("#0000ffThis map has been remove from your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff for mark it as favourite!", source, 255, 255, 255, true) 
        else 
            outputChatBox("not found") 
            executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..favs[1].favmaps..","..currentMap.."' WHERE serial=?", serial) 
            outputChatBox("#0000ffThis map has been added to your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff again for remove as favourite!", source, 255, 255, 255, true) 
        end 

Link to comment

Guys this is the full function, please help me...

function mfavCommand(source, command) 
    local currentMap = tostring(getResourceInfo(exports['mapmanager']:getRunningGamemodeMap(), "name")) 
    local serial = getPlayerSerial(source) 
    local favs = executeSQLQuery("SELECT favmaps FROM userpanelDatas WHERE serial=?", serial) 
    if favs[1].favmaps then 
        if string.find(favs[1].favmaps, currentMap) then 
            outputChatBox("found") 
            if string.find(favs[1].favmaps, ","..currentMap)  then 
                executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(favs[1].favmaps,","..currentMap, "").."' WHERE serial=?", serial) 
            elseif string.find(favs[1].favmaps, currentMap..",") then 
                executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(favs[1].favmaps,currentMap..",", "").."' WHERE serial=?", serial) 
            end 
            outputChatBox("#0000ffThis map has been remove from your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff for mark it as favourite!", source, 255, 255, 255, true) 
        else 
            outputChatBox("not found") 
            executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..favs[1].favmaps..","..currentMap.."' WHERE serial=?", serial) 
            outputChatBox("#0000ffThis map has been added to your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff again for remove as favourite!", source, 255, 255, 255, true) 
        end 
    end 
end 
addCommandHandler("mfav", mfavCommand) 

The error is the same: Always "not found"!

Link to comment

try this:

function mfavCommand(source, command) 
    local currentMap = getResourceInfo(exports['mapmanager']:getRunningGamemodeMap(), "name") --returns a string 
    local serial = getPlayerSerial(source) 
    local favs = executeSQLQuery("SELECT favmaps FROM userpanelDatas WHERE serial=?", serial) 
    local favmap = favs[1].favmaps 
    if favmap then 
        local found = false 
        for _,v in ipairs(favmap)do -- I think it's a table 
            if string.find(currentMap..",",v,1,true) or string.find("v"..currentMap,v,1,true) then 
                found = true 
                outputChatBox("found") 
                if string.find(","..currentMap,v,2,true)  then 
                    executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(v,","..currentMap, "").."' WHERE serial=?", serial) 
                    break; 
                elseif string.find(currentMap..",",v,1) then 
                    executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(v,currentMap..",", "").."' WHERE serial=?", serial) 
                    break; 
                end 
                outputChatBox("#0000ffThis map has been remove from your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff for mark it as favourite!", source, 255, 255, 255, true) 
            end 
        end 
        if not found then 
                outputChatBox("not found") 
                executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..favmap.." , "..currentMap.."' WHERE serial=?", serial) 
                outputChatBox("#0000ffThis map has been added to your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff again for remove as favourite!", source, 255, 255, 255, true) 
            end 
        end 
    end 
end 
addCommandHandler("mfav", mfavCommand) 

Link to comment

Sorry but you function donsn't work because "favmap" variable is not a table..

Anyway i tryed to fix my function and i did it (Thanks Jaysds1, i used the string.find function like you used it in your function), but it still doen't work and i found the problem: the string.gsub does't work!

function mfavCommand(source, command) 
    local currentMap = tostring(getResourceInfo(exports['mapmanager']:getRunningGamemodeMap(), "name")) 
    local serial = getPlayerSerial(source) 
    local favs = executeSQLQuery("SELECT favmaps FROM userpanelDatas WHERE serial=?", serial) 
    if type(favs[1].favmaps) == "string" then 
        if string.find(favs[1].favmaps, currentMap, 1, true) then 
            executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..string.gsub(favs[1].favmaps, ","..currentMap, "").."' WHERE serial=?", serial) 
            outputChatBox("#0000ffThis map has been remove from your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff for mark it as favourite!", source, 255, 255, 255, true) 
        else 
            executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..favs[1].favmaps..","..currentMap.."' WHERE serial=?", serial) 
            outputChatBox("#0000ffThis map has been added to your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff again for remove as favourite!", source, 255, 255, 255, true) 
        end 
    end 
    outputChatBox(","..currentMap) --FIRST OUTPUT 
    outputChatBox(favs[1].favmaps:gsub(tostring(","..currentMap), ""))--SECOND OUTPUT 
end 
addCommandHandler("mfav", mfavCommand) 

The outputs at line 14 and 15 are the same! So i think the problem is this:

favs[1].favmaps:gsub(tostring(","..currentMap), "") 

Link to comment

Ok, i solved whit an alternative method:

function addMapToFavourites(theMap, thePlayer) 
    local serial = getPlayerSerial(thePlayer) 
    local favs = executeSQLQuery("SELECT favmaps FROM userpanelDatas WHERE serial=?", serial) 
    executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..favs[1].favmaps..","..theMap.."' WHERE serial=?", serial) 
end 
  
function removeMapFromFavourites(theMap, thePlayer) 
    local serial = getPlayerSerial(thePlayer) 
    local favs = executeSQLQuery("SELECT favmaps FROM userpanelDatas WHERE serial=?", serial) 
    local newData = "" 
    for i, favmap in ipairs(split(favs[1].favmaps, ",")) do 
        if favmap ~= theMap then 
            newData = newData..","..favmap 
        end 
    end 
    executeSQLQuery("UPDATE userpanelDatas SET favmaps='"..newData.."' WHERE serial=?", serial) 
end 
  
function mfavCommand(source, command) 
    local currentMap = tostring(getResourceInfo(exports['mapmanager']:getRunningGamemodeMap(), "name")) 
    local serial = getPlayerSerial(source) 
    local favs = executeSQLQuery("SELECT favmaps FROM userpanelDatas WHERE serial=?", serial) 
    if type(favs[1].favmaps) == "string" then 
        if string.find(favs[1].favmaps, currentMap, 1, true) then 
            removeMapFromFavourites(currentMap, source) 
            outputChatBox("#0000ffThis map has been remove from your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff for mark it as favourite!", source, 255, 255, 255, true) 
        else 
            addMapToFavourites(currentMap, source) 
            outputChatBox("#0000ffThis map has been added to your favourite maps#ff0000! #0000ffUse #ffffff/mfav#0000ff again for remove as favourite!", source, 255, 255, 255, true) 
        end 
    end 
end 
addCommandHandler("mfav", mfavCommand) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...