PrettyDiamond Posted February 3, 2020 Share Posted February 3, 2020 ----------------------------------------->> -- Grand Theft International (GTi) -- Author: JT Pennington (JTPenn) -- Date: 08 Jul 2014 -- Resource: GTIrules/rules.Lua -- Version: 1.0 ----------------------------------------->> local font = "default" local quickSelect = {} --[[ addEventHandler("onClientResourceStart", resourceRoot, function() font = guiCreateFont("courier.ttf") end) --]] -- Create Rules Panel ----------------------->> function createRulesPanel(rules) -- Delete if Already Exists if (isElement(window)) then closePanel("left", "up") return end -- Load Rules Data --local rules = string.gsub(rules, "%(", "%{") --local rules = string.gsub(rules, "%)", "%}") loadedData, loadFail = loadstring(tostring(rules)) if (loadFail) then outputChatBox("GTI Rules failed to load. The rules file is not configured correctly.", 255, 0, 0) outputChatBox(loadFail, 255, 0, 0) return false end loadedData() -- Create Window local sX, sY = guiGetScreenSize() local wX, wY = 700, 500 local sX, sY, wX, wY = (sX/2)-(wX/2),(sY/2)-(wY/2),wX,wY -- sX, sY, wX, wY = 437, 182, 700, 500 window = guiCreateWindow(sX, sY, wX, wY, "RPG City Regras & Ajuda", false) guiWindowSetSizable(window, false) guiSetAlpha(window, 1.00) gridlist = guiCreateGridList(9, 24, 225, 467, false, window) guiGridListAddColumn(gridlist, "Manual de Instrução", 0.9) guiGridListSetSortingEnabled(gridlist, false) -- addEventHandler("onClientGUIClick", gridlist, updateDocumentation, false) -- Create the Gridlist Items quickSelect = {} local curr_sec for _,tbl in ipairs(documents) do if (not tbl[2]) then local row = guiGridListAddRow(gridlist) guiGridListSetItemText(gridlist, row, 1, tbl[1], true, false) guiGridListSetItemColor(gridlist, row, 1, 215, 25, 25) else local row = guiGridListAddRow(gridlist) guiGridListSetItemText(gridlist, row, 1, tbl[1], false, false) quickSelect[row] = tbl[2] end end memo = guiCreateMemo(241, 24, 450, 437, "Bem vindo/a ao RPG City Reallife. Use o menu á esquerda para navegar pela documentação do servidor.\n\nRegras do Servidor:\n\n"..theRules["English"], false, window) guiSetFont(memo, font) guiMemoSetReadOnly(memo, true) button = guiCreateButton(506, 467, 185, 23, "Fechar", false, window) -- addEventHandler("onClientGUIClick", button, closePanel, false) showCursor(true) end addEvent("GTIrules.createRulesPanel", true) addEventHandler("GTIrules.createRulesPanel", root, createRulesPanel) -- Panel Functions ------------------->> function togglePanel() if (not exports.GTIaccounts:isPlayerLoggedIn()) then return end if (isElement(window) and not guiGetVisible(window)) then guiSetVisible(window, true) showCursor(true) elseif (isElement(window)) then closePanel("left", "up") else triggerServerEvent("GTIrules.getHelpFile", resourceRoot) end end bindKey("F9", "down", togglePanel) addCommandHandler("rules", togglePanel) function closePanel(btn, state) if (btn ~= "left" or state ~= "up") then return end guiSetVisible(window, false) showCursor(false) destroyElement(window) end function updateDocumentation(btn, state) if (btn ~= "left" or state ~= "up") then return end local row = guiGridListGetSelectedItem(gridlist) if (not row or row == -1) then return end guiSetText(memo, quickSelect[row]) end The function createRulesPanel wont works for me, im trying for a days to make this works, but im failed, so i coming here and ask @ all if you can help me a little... The connection to the rules.txt file its successfull established but instead to draw the window, the function try to print the rules.txt out ti the outputbox chat... like this: * Rules not yet downloaded. Press F9 again. GTI Rules failed to load. The rules file is not configured correctly. [string "Art 1° - Não praticar Power Gaming: Mínimo (10H) Máximo(24H..."]:1: '=' expected near '1' Thx in advance and sorry for my bad english... Link to comment
Addlibs Posted February 3, 2020 Share Posted February 3, 2020 (edited) loadstring loads Lua code from a string into a function than you can call (to execute the loaded code). Looking at the loadstring error message, it does not appear that you're putting code into that, but rather a string of text, not code. You have two options: Either change line 65 to memo = guiCreateMemo(241, 24, 450, 437, "Bem vindo/a ao RPG City Reallife. Use o menu á esquerda para navegar pela documentação do servidor.\n\nRegras do Servidor:\n\n"..rules, false, window) and remove line 28 through 34 (the safer option, since you remove the ability for arbitrary code execution in your script) Or the second option, is to change the rules.txt file to contain valid code which this script expects. It appears to expect a table named theRules with a string of rules under the key "English", so your rules.txt should be local theRules = { ["English"] = "Art 1° - Não praticar Power Gaming: Mínimo (10H) Máximo(24H ..." } and it should load correctly. However, this is less safe, since it can allow someone with access to editing rules.txt to insert malicious code into the file, which is then executed on through clients' Lua interpreters. Edited February 3, 2020 by MrTasty 1 Link to comment
PrettyDiamond Posted February 6, 2020 Author Share Posted February 6, 2020 @MrTasty I am very grateful for your help, unfortunately I could not solve the problem in this way. I tried everything possible, at the end its was just an "unfinished string" and still didn't give me the rules.txt file on my memo GUI. Then I decided to use the xml variant. This was successful, i thank you again for everything. Regards PrettyDiamond Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now