Jump to content

[HELP] Window opens on any map start


LabiVila

Recommended Posts

server:

function dooutput (player) 
    resources = {} 
    for _,v in pairs (getResources()) do  
        if (getResourceInfo (v, "gamemodes") == "race") then 
            local map = getResourceInfo (v, "name") 
            if map then  
                table.insert (resources, map) 
            end 
        end 
    end 
    triggerClientEvent (player, "all", player, resources) 
end 
addEvent ("goforit", true) 
addEventHandler ("goforit", getRootElement(), dooutput) 
  
function nextOne (map) 
    executeCommandHandler ("nextmap", source, map) 
    triggerClientEvent ("nextMapName", getRootElement(), map) 
end 
addEvent ("setNextMap", true) 
addEventHandler ("setNextMap", getRootElement(), nextOne) 

client

local everyRes = {} 
local x,y = guiGetScreenSize () 
  
function enableNMonstart () 
    isNM = false 
end 
addEvent ("onClientMapStarting", true) 
addEventHandler ("onClientMapStarting", getRootElement(), enableNMonstart) 
  
function mapGUI (res) 
    everyRes = res 
    main = guiCreateWindow ((480/1366)*x, (160/768)*y, (400/1366)*x, (450/768)*y, "Map Shop", false) 
    local mainList = guiCreateGridList ((10/1366)*x, (30/768)*y, (700/1366)*x, (370/768)*y, false, main) 
    local mainListColumn = guiGridListAddColumn (mainList, "Map name:", 0.85) 
    local searchBar = guiCreateEdit ((10/1366)*x, (410/768)*y, (210/1366)*x, (50/768)*y, "", false, main) 
    local nextmapButton = guiCreateButton ((230/1366)*x, (410/768)*y, (100/1366)*x, (50/768)*y, "Buy as next map", false, main) 
    local X = guiCreateButton ((340/1366)*x, (410/768)*y, (40/1366)*x, (50/768)*y, "X", false, main) 
    if mainListColumn then 
        for _,res in pairs (everyRes) do 
            local mainListRow = guiGridListAddRow (mainList) 
            guiGridListSetItemText (mainList, mainListRow, mainListColumn, res, false, false) 
        end 
    end 
     
    addEventHandler ("onClientGUIClick", nextmapButton, 
        function () 
            if (isNM == false) then 
                clickedName = guiGridListGetItemText (mainList, guiGridListGetSelectedItem (mainList), 1) 
                triggerServerEvent ("setNextMap", getLocalPlayer(), clickedName) 
                isNM = true 
            else 
                outputChatBox ("#ff7100[server]#ffffff Next map is already bought.", 255, 255, 255, true) 
            end 
        end 
    ) 
     
    addEventHandler ("onClientGUIClick", X, 
        function () 
            guiSetVisible (main, false) 
            showCursor (false) 
        end 
    ) 
     
    showCursor (true) 
end 
addEvent ("all", true) 
addEventHandler ("all", getRootElement(), mapGUI) 
  
function sendTrigger () 
    triggerServerEvent ("goforit", getRootElement(), getLocalPlayer()) 
end 
addCommandHandler ("mapshop", sendTrigger) 

The error is: Bad argument @ 'guiGridListSeTItemText' [Expected string at argument 4, got player]

I thought maybe I made a global variable or something and I messed up, tried to change the looping for every resource to another value-name but it didn't work. So the window opens itself on any map start (while state running) and it's all blank

Link to comment

About your bad argument at guiGridListSetItemText(): the function waits by a string, and you sent a player object (yes, the error message describes itself). Use getPlayerName(), returning a string, like expectated.

guiGridListSetItemText (mainList, mainListRow, mainListColumn, getPlayerName(res), false, false) 

At line 4, on server's script, would not be "gamemode" instead "gamemodes"? Please, I am really sorry if I am saying bullshit, but I did not touch on a meta.xml file there is a big time.

About your other problem, I did not understand it so well. I would appreciate if you could explain something more about that. Should your GUI opens only when a certain map starts?

And please, don't bump your topics again. Is not allowed.

Link to comment

Well thanks for taking time and reading that first, I've fixed it by adding a command handler server-side, and it worked (surprisingly), then if you may notice, 'res' isn't a player element, it is the name of the resource (defined in server side). Checked meta again, it's 'gamemodes', not 'gamemode' (yes I don't understand why would they do that either). Thanks anyway

EDIT: I won't bump again, sorry

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...