Jump to content

kieran

Members
  • Posts

    367
  • Joined

  • Last visited

Everything posted by kieran

  1. @idarrr The point of it is to create an auto complete for URLs if the player enters, for example, "google.com" and forgets "http://www." I only looked at dX images, this made me a little confused as I have only added gui images, but first time doing a click event for them, found out I could just shove a button after the image and set it's alpha to 0, works well enough but your way is better. I also found one more issue.... When I do a google search, I can not click the hyperlinks. How would I check if a client clicked a URL? All I'd need to do after that is check if the domain is blocked and request it. I appreciate the help, hopefully you'll see a new browser on forums that works just like the one on your PC soon! But yeah, would help if google search actually worked...
  2. So I have two problems on this gui browser I am making, but the main one is getting the position when I click and loading the url, code (and other problem) is below. Second problem: I can not use :sub(int, int) to set the url on my gui edit, it spams "http://www." even if it's in my URL edit box. Thanks for any help, been really struggling with both of these problems for about a week.
  3. Works fine now, the key part I was missing was: theBrowser = guiGetBrowser( webBrowser ) I don't know why, but you need to get the browser then use that to load the URL, rather than just using the GUI browsers variable... Anyway thanks Working Code
  4. Same result.... it can't get the browser from the function. I've tried putting the enter bind on loadBrowser hoping it would get the created browser, but don't know how I'd add a handler to identify the browser when I press enter on my edit box, keeps saying the browser (texture) isn't there.
  5. Made my browser, but now it won't set the new site when I press enter (enter's bound it to function) local screenWidth, screenHeight = guiGetScreenSize() local px,py = 800, 600 local x,y = (screenWidth/px), (screenHeight/py) win = false function createBrowser() if ( window ) then --So it's easy to load the browser for player if ( guiGetVisible( window )) then showCursor( false ) toggleAllControls(true) guiSetVisible( window, false ) else guiSetInputEnabled(false) showCursor(true) toggleAllControls(false) guiSetVisible( window, true ) end else toggleAllControls(false) window = guiCreateWindow(x+50, y+50, screenWidth-100, screenHeight-100, "Please wait while your page loads", false) edit_site = guiCreateEdit(0, y+25, screenWidth, 25, "", false, window) local webBrowser = guiCreateBrowser(0, 55, screenWidth, screenHeight-100, false, false, false, window) local theBrowser = guiGetBrowser( webBrowser ) bindKey ("enter", "down", nextPage)--Here I have bound enter to my function addEventHandler("onClientBrowserCreated", webBrowser, loadBrowser) end end bindKey ("F3", "down", createBrowser) function SetURL(url) guiSetText(window, url) end function loadBrowser() loadBrowserURL(source, "http://www.youtube.com") showCursor(true) win = true addEventHandler("onClientBrowserDocumentReady", root, SetURL) end function nextPage() if ( guiGetVisible( window )) then --[[local webBrowser = guiCreateBrowser(0, 55, screenWidth, screenHeight-100, false, false, false, window) addEventHandler("onClientBrowserCreated", webBrowser, function()]] site = guiGetText(edit_site)--Comments above was my attempt to draw a new browser on old one... loadBrowserURL(source, site) --end) end end Debug: Bad argument @ 'loadbrowserURL' [expected texture at argument 1, got nil] I created a browser, but what use is it when you can't go to a different site? haha
  6. @ShayF I have tried the one off wiki, but what's the point in making a new one if I can just tweak the default browser? But yeah, it kinda helps, prefer the GUI one to the dX browser though, it's easier... Anyway going off what you posted, I think the browser is declared on line 23 of the code I posted... Also why is "self." before everything that includes the browser? Thanks
  7. Hello, I was looking for a web browser and found out there was a nice default resource, but it creates the browser inside a window and it is zoomed in far too much, I was wondering if anyone could look over it and see where it draws the browser as I have no clue how it's drawing a browser in a window, just want to make the width the windows size. Client WebBrowserGUI = {} WebBrowserGUI.instance = nil function WebBrowserGUI:new() local o=setmetatable({},{__index=WebBrowserGUI}) o:constructor() return o end function WebBrowserGUI:constructor() local sizeX, sizeY = screenWidth * 0.9, screenHeight * 0.9 self.m_Window = GuiWindow(screenWidth * 0.05, screenHeight * 0.05, sizeX, sizeY, "Web browser", false) self.m_Window:setSizable(false) self.m_BackButton = GuiButton(5, 25, 32, 32, "<", false, self.m_Window) self.m_BackButton:setEnabled(false) self.m_ForwardButton = GuiButton(42, 25, 32, 32, ">", false, self.m_Window) self.m_ForwardButton:setEnabled(false) self.m_EditAddress = GuiEdit(77, 25, sizeX - 192, 32, "Please enter an address", false, self.m_Window) self.m_DevButton = GuiButton(sizeX - 110, 25, 32, 32, "✎", false, self.m_Window) self.m_LoadButton = GuiButton(sizeX - 75, 25, 32, 32, "➽", false, self.m_Window) self.m_ButtonClose = GuiButton(sizeX - 38, 25, 24, 24, "✖", false, self.m_Window) self.m_ButtonClose:setProperty("NormalTextColour", "FFFF2929") self.m_ButtonClose:setProperty("HoverTextColour", "FF990909") self.m_ButtonClose:setFont("default-bold-small") self.m_Browser = GuiBrowser(5, 62, sizeX - 10, sizeY - 67, false, false, false, self.m_Window) if not self.m_Browser then outputChatBox( "Can't create browser. Check Settings->Web Browser" ) self.m_Window:destroy() return end local browser = self.m_Browser:getBrowser() addEventHandler("onClientBrowserCreated", browser, function(...) self:Browser_Created(...) end) addEventHandler("onClientBrowserNavigate", browser, function(...) self:Browser_Navigate(...) end) addEventHandler("onClientBrowserWhitelistChange", root, function(...) self:Browser_WhitelistChange(...) end) addEventHandler("onClientBrowserDocumentReady", browser, function(...) self:Browser_DocumentReady(...) end) self.m_RequestedURL = "" showCursor(true) GuiElement.setInputMode("no_binds_when_editing") end function WebBrowserGUI:Browser_Created() addEventHandler("onClientGUIClick", self.m_LoadButton, function(...) self:LoadButton_Click(...) end, false) addEventHandler("onClientGUIAccepted", self.m_EditAddress, function(...) self:LoadButton_Click(...) end, false) addEventHandler("onClientGUIClick", self.m_BackButton, function(...) self:BackButton_Click(...) end, false) addEventHandler("onClientGUIClick", self.m_ForwardButton, function(...) self:ForwardButton_Click(...) end, false) addEventHandler("onClientGUIClick", self.m_ButtonClose, function(...) self:CloseButton_Click(...) end, false) addEventHandler("onClientGUIClick", self.m_DevButton, function(...) self:DevButton_Click(...) end, false) self:loadURL("https://mtasa.com/") end function WebBrowserGUI:Browser_Navigate(targetURL, isBlocked) if isBlocked then self.m_RequestedURL = targetURL Browser.requestDomains({targetURL}, true) return end end function WebBrowserGUI:Browser_WhitelistChange(whitelistedURLs) for i, v in pairs(whitelistedURLs) do if self.m_RequestedURL:find(v) then self.m_Browser:getBrowser():loadURL(self.m_RequestedURL) self.m_RequestedURL = "" end end end function WebBrowserGUI:Browser_DocumentReady() self.m_Window:setText("Web browser: " .. tostring(self.m_Browser:getBrowser():getTitle())) self.m_EditAddress:setText(tostring(self.m_Browser:getBrowser():getURL())) self.m_BackButton:setEnabled(self.m_Browser:getBrowser():canNavigateBack()) self.m_ForwardButton:setEnabled(self.m_Browser:getBrowser():canNavigateForward()) end -- // GUI Navigation function WebBrowserGUI:LoadButton_Click(param1, state) if isElement(param1) or (param1 == "left" and state == "up") then self:loadURL(self.m_EditAddress:getText()) end end function WebBrowserGUI:BackButton_Click(button, state) if button == "left" and state == "up" then self.m_Browser:getBrowser():navigateBack() end end function WebBrowserGUI:ForwardButton_Click(button, state) if button == "left" and state == "up" then self.m_Browser:getBrowser():navigateForward() end end function WebBrowserGUI:CloseButton_Click(button, state) if button == "left" and state == "up" then self.m_Window:destroy() showCursor(false) --GuiElement.setInputMode("no_binds_when_editing") WebBrowserGUI.instance = nil end end function WebBrowserGUI:DevButton_Click(button, state) if button == "left" and state == "up" then if not getDevelopmentMode() then exports.msgbox:guiShowMessageBox("You have to enable the development using setDevelopmentMode", "error", "Development mode required", false) return end self.m_Browser:getBrowser():toggleDevTools(true) end end -- \\ GUI Navigation function WebBrowserGUI:loadURL(url) if url == "" then self.m_EditAddress:setText("about:blank") self.m_Browser:getBrowser():loadURL("about:blank") return elseif url:sub(0, 6) == "about:" then self.m_EditAddress:setText(url) self.m_Browser:getBrowser():loadURL(url) return elseif url:sub(0, 7) ~= "http://" and url:sub(0, 8) ~= "https://" then url = "http://"..url end if Browser.isDomainBlocked(url, true) then self.m_RequestedURL = url Browser.requestDomains({url}, true) return end self.m_EditAddress:setText(url) self.m_Browser:getBrowser():loadURL(url) end It's a little advanced for me and this is why I came here to ask what and how, thanks.
  8. Okay this is basically a help topic now, found the issue, I started my game mode on map editor, meaning that the password was added there too..... This was not thought out all that well, maybe leave a note on the forum saying it will change editor config if resource is started on map editor...
  9. I have put this line in one of my scripts setServerPassword( nil ) Even though I set it to nil AND tried an empty sting, still asks for password, even when server is off please help me...? Me thinks an update is needed..... This should NOT be passwording my map editor, I am port forwarding my server through my network and I am only loading the script in my mtaserver.conf file, what the heck is happening?
  10. Hello, I am doing my first "big" script, basically the first useful one haha... I create blips for locations in a table, then set a timer, but I have forgot how to add and retrieve elements (in this case the blips) and was wondering if someone could help, only have the needed code to keep it easy to read. Client side script local ATM_Locations = { {1505.16626, -1750.68909, 13.54688},--1 {1690.0927734375, -2334.8369140625, 13.546875},--2 {1951.19543, -2175.53784, 13.55421},--3 {2041.50390625, -1430.728515625, 17.1640625},--4 {1878.06372, 2073.94067, 11.06250},--5 {2280.76465, 2431.10596, 10.82031},--6 {2020.86316, 1016.50653, 10.82031},--7 {-1210.31104, 1834.64917, 41.92969},--8 {174.82074, 1175.05469, 14.75781},--9 {1380.58093, 260.50055, 19.56693},--10 {1238.48145, 327.90039, 19.75551},--11 {1626.68469, 1815.06384, 10.82031}--12 } blips = false local Blips = {} function blips() for i=1,#ATM_Locations do local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3] Blips[i] = createBlip ( x, y, z, 3, 2) blips = true setTimer( destroyBlips, 10000, 1) end end addCommandHandler( "ATM", blips, false ) function destroyBlips() if (blips == true) then destroyElement(Blips) end end Don't pay attention to blip type, will change later haha.
  11. Solved one problem have another. I made the rookie mistake of not adding button and state to function, hah! And also I forgot to add server script in meta well at least this post will make others with similar problem double check there script
  12. Hello, I am in the process of making a bank script, trying to keep it as simple as possible, stuck with getting the amount from edit box and taking it away from the players element data. Here is code. Client local ATM_Locations = { {1690.0927734375, -2334.8369140625, 13.546875} } local ATMS = {} local window = {} local screenW, screenH = guiGetScreenSize() function DrawATM() if not(isElement(window)) then guiSetInputEnabled(false) showCursor(true) window = guiCreateWindow((screenW - 239) / 2, (screenH - 198) / 2, 239, 198, "ATM", false) guiWindowSetSizable(window, false) Amount_lbl = guiCreateLabel(98, 31, 55, 16, "Amount", false, window) edit = guiCreateEdit(25, 47, 190, 25, "", false, window) rad_with = guiCreateRadioButton(45, 80, 75, 25, "Withdraw", false, window) rad_dep = guiCreateRadioButton(135, 80, 65, 25, "Deposit", false, window) Balance_lbl = guiCreateLabel(80, 127, 200, 17, "Balance: ", false, window) accept_btn = guiCreateButton(10, 160, 99, 24, "Accept", false, window) exit_btn = guiCreateButton(130, 160, 99, 24, "Exit", false, window) setElementData (localPlayer, "Bank.Balance",(getElementData (localPlayer, "Bank.Balance"))) BankBalance = getElementData( localPlayer, "Bank.Balance" ) if not (BankBalance) then guiSetText ( Balance_lbl, "Balance: 0" ) setElementData( localPlayer, "Bank.Balance", 0 ) --guiSetFont(Iron, "sa-header") elseif (BankBalance) then guiSetText ( Balance_lbl, "Balance: " ..BankBalance ) end addEventHandler("onClientGUIClick",accept_btn,acceptATM) addEventHandler("onClientGUIClick",exit_btn,exitATM) end end function exitATM() if(button == "left" and state == "up") then if (source == exit_btn) then if (isElement(window)) then guiSetInputEnabled(false) guiSetVisible(window, false) destroyElement(window) showCursor(false) end end end end function acceptATM() if(button == "left" and state == "up") then if (source == accept_btn) then BankBalance = getElementData( localPlayer, "Bank.Balance" ) if (BankBalance) then if(guiRadioButtonGetSelected(rad_with))then if ( tonumber(BankBalance) <= tonumber (0)) then outputChatBox("Insufficent funds are in your account, please put some money in first.") elseif ( tonumber(BankBalance) >= tonumber (1)) then if (tonumber( BankBalance ) >= tonumber( amount )) then amount = guiGetText(edit) setElementData (localPlayer, "Bank.Balance",(getElementData (localPlayer, "Bank.Balance")or 0 ) - amount) triggerServerEvent("withdraw", getRootElement(), localPlayer, amount) end end end if (guiRadioButtonGetSelected(rad_dep))then PlayerMoney = getPlayerMoney(localPlayer) if ( tonumber(PlayerMoney) <= tonumber (0)) then outputChatBox("You must have at least 1 dollar... Go work!") elseif ( tonumber(PlayerMoney) >= tonumber (1)) then if (tonumber( PlayerMoney ) >= tonumber( amount )) then amount = guiGetText(edit) setElementData (localPlayer, "Bank.Balance",(getElementData (localPlayer, "Bank.Balance")or 0 ) + amount) triggerServerEvent("deposit", getRootElement(), localPlayer, amount) end end end end end end end function createGUI() for i=1,#ATM_Locations do local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3] ATMS[i] = createColTube( x,y,z,1,2 ) addEventHandler( "onClientColShapeHit",ATMS[i], DrawATM ) end end createGUI() Server function withdrawHandler(thePlayer, givenAmount) if isElement(thePlayer) then givePlayerMoney(thePlayer, givenAmount) end end addEvent("withdraw", true) addEventHandler("withdraw", getRootElement(), withdrawHandler) function depositHandler(thePlayer, takenAmount) if isElement(thePlayer) then money = getPlayerMoney(thePlayer) setPlayerMoney(thePlayer, money - takenAmount) end end addEvent("deposit", true) addEventHandler("deposit", getRootElement(), depositHandler) The GUI shows, both buttons don't work, the exit button worked before I tried adding "acceptATM" function, so the problem lies somewhere there, but nothing on debugscript 3 Thanks all for help
  13. Worked perfect, and yes, I had a problem first with milliseconds, but then I realized I set it to *100 and not *1000 of sounds length But after that I had a problem making my timer global as it was local inside another function, tried your code and works perfect! Thanks Did make one edit though, a useful tip I found out is... Always remove a onClientResourceStart handler if it's just when the player logs on or joins, prevents it restarting
  14. Sorry, but no, I will explain, I am using a timer in the function that loops the music, that timer is INSIDE the function, so it can get the sound length and set the timer to repeat the process. The problem is, on my custom event, it can not find the timer as it is INSIDE a different function, I want it so that I can use the timer across more than one function, but still get the sound length... Basically I am looping a timer in a function, but wish to cancel it with a custom event.
  15. Okay, I have been tackling this sort of thing for around a week now, do you want the music just playing once or multiple times?
  16. It is not fixed I don't think I have been explaining it well... I want to trigger an event to stop the timer when my player logs in. It works the exact same as before, the problem is I can not get the timer from "nextSound" when I try to kill it on my custom event. Client Server I will try explain why it can not find the timer, I know why it can't, the timer can only be used in the function it is currently in, this is the reason I wanted to nest a function and add a handler to stop it. Finally, I am using 2 functions, one to make the timer, one to stop it. I want to make it so it can be used across functions when set inside a function. One idea I have is put the timer in a table and get the table when I try to stop it, how would I do that? Also read comments, they should give a better idea of what I am trying.
  17. Not managed yet, driving me crazy, the whole problem is that it can't find the timer, I know you need to make a timer or something as a global variable (setting element data would do that as it shares it with server) but with the timer I have it in one function, trying to cancel it in another, and when I loop the song, I am trying to cancel the timer before it starts (so it's not really necessary on the loop.) Bbut the problem is the last function, it can't find "nextSong" since I put it in an if and set the timer there. But if you would debug on your PC would be appreciated it's just the pesky timer.
  18. I don't understand what you mean, isSoundFinished couldn't find the sound as I was trying to check it outside the function, I think it needs a local variable with it, and yes, you seen the code, my timers play the next song from the list, they have the variable "nextSong" as I say, it can not find it as I am trying to check a timer outside the function I defined the variable.... I don't know if that's because my script is client side and the timer only runs for client or not.... And isSoundFinished wouldn't be much use, I am trying to get the local variable from line 34, but as this timer is in a separate function to the one I use to kill it, it can not detect it, at least I think that's what is going on..... So here is something I think could work, can you add events with no handlers and then use triggerEvent? Or do you need the handlers to handle these events? If you can't, then can you nest functions? I have tried but not succeeded...
  19. What you might want to consider is setting players data with setElementData and then using a timer to remove there data after 45 seconds, just create an event that sets the data to false, this means the data would be removed, when the player clicks the button, get there element data, if there element data is true, then output a message, otherwise spawn a vehicle or whatever you are doing and then set there element data to true. I would suggest not using a timer as you'd be setting it outside of your function, unfortunately I have no idea how to declare a timer as a global variable to use it across functions, but you could set it, then check if it exists AFTER near the top of your button click event... I would personally use the first approach, set their data, set a timer to remove their data, then check their data (NOT THE TIMER) and if it's that data do nothing, else do something, then when timer hits 0, it would go to an event to remove there data, simple!
  20. kieran

    Help-me

    Yes, but when you add players to a list on ACL, the resource that is adding players must have permission to add them, which you have done..... What are you trying to do with your script? Also please type "/debugscript 3" into the chat in game and tell us what it says, this will tell us errors in your script.
  21. attempt to call global "isSoundFinished" (a nil value) Looks as if this is global, my script is with my login panel, it is client side, not global... I have even tried removing the event handler from when the player renders so when the first timer is done, it SHOULD remove event handler and then add it again when playing the next song, in an attempt to get the timer from that function, but nothing! And to start with I don't think you quite get my issue..... The timer itself is not being found when the event is triggered. Not the sound, it stops the sound, but my timer is still active, this means that even though the sound goes off, the timer is still active, meaning it will repeat the whole process again.... Is there any way to set data to a timer (not a sound element) or create a variable that will carry it to a function? And another useful piece of information, even though my timer is within my function (before the last event in snippet I sent) it can not find it there either, so is there a problem with isTimer? Okay source of the problem was found, turns out I was looking at the wrong function as Timer not found. was returned to chat when I was using code above, so looks as if the isTimer does not register a timer at all..... Any way around this? Edit: I have update the code snippet, my debugscript 3 returns "Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got nil]" for BOTH functions.
  22. @koragg That will cause extreme lag and spam errors on debugscript 3 since I am checking for "sound" all the time even though it's stopped first time, know any other way? As in, can I check to see if a specific sound is running?
  23. @koragg Nope, still keeps timer on after the server event is triggered, changed timer to 1 and added a return at the end as it was being triggered 6 times? Honestly at a loss here.... I know that most languages can only get code inside functions and use it on that function, for example if you set a local variable in visual studio and tried using it on another form with c# it wouldn't be able to get it as it isn't passed, is there maybe a similar issue with timers...? Because I tried this and it returned "Timer not found." to chat box... Updated code (Client) Would it be possible to set data on the localPlayer to the timer even though the player isn't spawned? Only way I can think of to pass it to next function.
×
×
  • Create New...