Jump to content

thund3rbird23

Members
  • Posts

    119
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

thund3rbird23's Achievements

Sucka

Sucka (13/54)

10

Reputation

  1. The vehicle ID is the primary key in database. (id column)
  2. I'm getting the vehicle plate text from a client-side gui gridlist selection and want to check if the vehicle with the selected plate text is nearby then I can do whatever what I want with the vehicle. I had to modify the positions variable the positions debug is working well but I always getting "Vehicle is not nearby" doesn't matter if I'm close to the vehicle or not. And the vehicle position doesn't change while the player is in-game. That will change after the player is disconnected so I don't think so that's the good way of the vehicle's position?! function SetVehicleSellingDB(vehPlate) local query = dbQuery(con, "SELECT * FROM vehicle WHERE plate=?", vehPlate) local result = dbPoll(query, -1) if result then local vehicleplate = result[1]["plate"] local pos = fromJSON(result[1]["pos"]) local x = pos[1] local y = pos[2] local z = pos[3] iprint("x: "..x.. " y: "..y.." z: "..z) local nearby = 20 if getDistanceBetweenPoints3D(x, y, z, getElementPosition(source)) <= nearby then outputDebugString("Vehicle is nearby") else outputDebugString("Vehicle is not nearby") end end end
  3. I want to check if the selected vehicle is nearby by the vehicle's plate. I'm getting the vehicle's plate text from client-side gui (gridlist selection) then I query that plate from mysql in server-side and want to check if that is nearby or not. function SetVehicleSellingDB(vehPlate) local query = dbQuery(con, "SELECT * FROM vehicle WHERE plate=?", vehPlate) local result = dbPoll(query, -1) if result then local vehicleplate = result[1]["plate"] --- I getting the selected vehicle's plate from client-side gui succesfully local vehicle = getNearestVehicle( vehicleplate ) --- this doesn't work if vehicle then outputChatBox("Vehicle is nearby") end end end addEvent("SetVehSellingDB",true) addEventHandler("SetVehSellingDB",getRootElement(), SetVehicleSellingDB) It's works until I getting the vehicle's plate text but how can I insert the vehicleplate variable into the getNearestVehicle function? function getNearestVehicle( player ) local x, y, z = getElementPosition( player ) local prevDistance local nearestVehicle for i, v in ipairs( getElementsByType( "vehicle" ) ) do local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) ) if distance <= ( prevDistance or distance + 1 ) then prevDistance = distance nearestVehicle = v end end return nearestVehicle or false end getNearestVehicle function source:
  4. Now the local Selected = DGS:dgsGridListGetSelectedItem(gridlist) iprint("Selected is correct:", Selected ~= -1, ">input>", Selected ) Selected returns false. But before that it worked without any problem
  5. [A], , So the problem is the source isn't correct? I'm calling the source (gridlist) from the "onLoadOwnWeapons" event
  6. No errors in debug and if I put only outputChatBox("clicked") inside the SellBttnClick function then displays that... so yes the function gets called after clicking.
  7. Thank you. Now it seems to work... but I can't get the dgsGridListGetSelectedItem before it's worked when I used onResourceStart event handler. Do you have any idea? addEvent("onLoadOwnWeapons", true) addEventHandler("onLoadOwnWeapons", localPlayer, function (items) weapwindow = DGS:dgsCreateWindow(screenW - 278 - 10, (screenH - 237) / 2, 278, 237,"Your Weapons",false) DGS:dgsWindowSetCloseButtonEnabled(weapwindow, false) DGS:dgsWindowSetMovable ( weapwindow, false ) gridlist = DGS:dgsCreateGridList (0.04, 0.01, 0.92, 0.58, true, weapwindow ) local items = getElementData(localPlayer, "weaponmodel") column = DGS:dgsGridListAddColumn(gridlist, "Weapons", 0.5) for k, v in ipairs(items) do row = DGS:dgsGridListAddRow(gridlist, v[1]) DGS:dgsGridListSetItemText ( gridlist, row, column, v[1] ) end sellbttn = DGS:dgsCreateButton(0.62, 0.62, 0.34, 0.08, "Sell", true, weapwindow) addEventHandler ( "onDgsMouseClick", sellbttn, SellBttnClick, false ) end, false) --- SellBttnClick function (from Dgs Wiki page)--- function SellBttnClick(button, state) if button == "left" and state == "down" then if source == gridlist then local Selected = DGS:dgsGridListGetSelectedItem(gridlist) if Selected ~= -1 then local output= DGS:dgsGridListGetItemText(gridlist,Selected,column) outputChatBox(""..output.."",255,0,0) end end end end
  8. Uh okay I'm totally lost... I need those table when I open the gui window. I set the guivisible true when I click on a button from another window. This is the main window but I need to set the guivisible false so we can't see the gui always. The items variable doesn't work here I just left it there to better illustrate what I want to do. (I need to put the table in the gridlist but only after I click on a button) function test() weapwindow = DGS:dgsCreateWindow(screenW - 278 - 10, (screenH - 237) / 2, 278, 237,"Your Weapons",false) DGS:dgsSetVisible(weapwindow, false) DGS:dgsWindowSetCloseButtonEnabled(weapwindow, false) DGS:dgsWindowSetMovable ( weapwindow, false ) gridlist = DGS:dgsCreateGridList (0.04, 0.01, 0.92, 0.58, true, weapwindow ) local items = getElementData(localPlayer, "weaponmodel") column = DGS:dgsGridListAddColumn(gridlist, "Weapons", 0.5) for k, v in ipairs(items) do row = DGS:dgsGridListAddRow(gridlist, v[1]) DGS:dgsGridListSetItemText ( gridlist, row, column, v[1] ) end DGS:dgsSetVisible(weapwindow,false) end addEventHandler ( "onClientResourceStart", resourceRoot, test ) This is the another window where I have the button which "opens" the gui window (I set the gui visible to true): addEventHandler ( "onClientClick", root, function ( button, state ) if ( button == "left" and state == "down" ) then if drawInfo == true and ( isMouseInPosition ( screenW * 0.4195, screenH * 0.6680, screenW * 0.0523, screenH * 0.0166 ) ) then drawInfo = false DGS:dgsSetVisible(weapwindow,true) end if drawInfo == true and ( isMouseInPosition ( screenW * 0.4836, screenH * 0.6670, screenW * 0.0547, screenH * 0.0176 ) ) then drawInfo = false end end end ) How can I put the table in to the gridlist if I click on that button with your solution? Because currently the gridlist is empty and the debug just return an empty table "{}"
  9. items debug is false items2 debug is the table what I need. Screenshot: https://i.imgur.com/33JanAb.png EDIT: my bad... I misspelled a word in items variable. The items & items2 debug is the table what I want.
  10. I'll try to describe it clearly ? I query the weaponmodels here: --- server.lua --- addEvent("loadOwnWeapons",true) addEventHandler("loadOwnWeapons",getRootElement(),function(player) local owner = getElementData(source, "acc:id") local query = dbQuery(con,"SELECT * FROM weapons WHERE owner = ?", owner) local weapons = dbPoll(query,-1) if weapons then local newTable = {} for k,v in ipairs(weapons) do newTable[#newTable + 1] = {v["weaponmodel"]} end setElementData(source, "weaponmodel", newTable) end end) Then I calling this server event in client-side: --- client.lua --- function test() triggerServerEvent("loadOwnWeapons", localPlayer) local items = getElementData(localPlayer, "weaponmodel") iprint(items) end addEventHandler ( "onClientResourceStart", resourceRoot, test ) The situation is: When I connect to the server then the items debug is (only one string): XZG-324 After I restart the resource the items debug is an empty table: {} After I restarting the resource twice (a table with the player's weaponmodels which I need without restarting the resource): {{"XZG-324"},{"YRT-598"},{"OEV-153"},{"EFC-543"},{"LEZ-054"}}
  11. I still don't understand what is the problem... look I added a button which is "refresh" the gridlist's items, when I click on that button and debug the items with iprint then I get only one string... for ex.: xyz123 and after I restart the resource and then click on the refresh button then I get the table which I need... But why? function refreshBttnClick() triggerServerEvent("loadOwnWeapons", localPlayer) DGS:dgsSetVisible(weaponwindow,false) weaponwindow = DGS:dgsCreateWindow(screenW - 278 - 10, (screenH - 237) / 2, 278, 237,"Your Weapons",false) DGS:dgsWindowSetCloseButtonEnabled(weaponwindow, false) DGS:dgsWindowSetMovable ( weaponwindow, false ) gridlist = DGS:dgsCreateGridList (0.04, 0.01, 0.92, 0.58, true, weaponwindow ) column = DGS:dgsGridListAddColumn(gridlist, "Weapons", 0.5) local items = getElementData(localPlayer, "weaponmodel") iprint(items) for k, v in ipairs(items) do row = DGS:dgsGridListAddRow(gridlist, v[1]) DGS:dgsGridListSetItemText ( gridlist, row, column, v[1] ) end refreshbttn = DGS:dgsCreateButton(0.05, 0.62, 0.34, 0.08, "Refresh", true, weaponwindow) addEventHandler ( "onDgsMouseClick", refreshbttn, refreshBttnClick, false ) end
  12. Gridlist only load data if I restart the resource... I'm using thisdp's GUI ... I tried to load the weapons from server side when player joins but still the same. function loadweapons() triggerServerEvent("loadOwnWeapons", localPlayer) end addEventHandler("onClientPlayerJoin", getRootElement(), loadweapons) I set the window visible to false function test() weapwindow = DGS:dgsCreateWindow(screenW - 278 - 10, (screenH - 237) / 2, 278, 237,"Your Weapons",false) DGS:dgsSetVisible(weapwindow, false) DGS:dgsWindowSetCloseButtonEnabled(weapwindow, false) DGS:dgsWindowSetMovable ( weapwindow, false ) gridlist = DGS:dgsCreateGridList (0.04, 0.01, 0.92, 0.58, true, weapwindow ) local items = getElementData(localPlayer, "weaponmodel") column = DGS:dgsGridListAddColumn(gridlist, "Weapons", 0.5) for k, v in ipairs(items) do row = DGS:dgsGridListAddRow(gridlist, v[1]) DGS:dgsGridListSetItemText ( gridlist, row, column, v[1] ) end DGS:dgsSetVisible(weapwindow,false) end addEventHandler ( "onClientResourceStart", resourceRoot, test ) If I debug the items with iprint(items) I get only string instead of table... but if I restart the resource I get the table and everything is working. And here I set the window visible to true if I click on other button from another window addEventHandler ( "onClientClick", root, function ( button, state ) if ( button == "left" and state == "down" ) then if drawInfo == true and ( isMouseInPosition ( screenW * 0.4195, screenH * 0.6680, screenW * 0.0523, screenH * 0.0166 ) ) then drawInfo = false DGS:dgsSetVisible(weapwindow,true) end if drawInfo == true and ( isMouseInPosition ( screenW * 0.4836, screenH * 0.6670, screenW * 0.0547, screenH * 0.0176 ) ) then drawInfo = false end end end ) the loadOwnWeapons server-side event is: addEvent("loadOwnWeapons",true) addEventHandler("loadOwnWeapons",getRootElement(),function(player) local owner = getElementData(source, "acc:id") local query = dbQuery(con,"SELECT * FROM weapons WHERE owner = ?", owner) local weapons = dbPoll(query,-1) if weapons then local newTable = {} for k,v in ipairs(weapons) do newTable[#newTable + 1] = {v["model"]} end setElementData(source, "weaponmodel", newTable) end end) My question is why I only get the table from the loadOwnWeapons server-side event if I restart the resource? Maybe because I only get the weaponmmodel elementdata in the onClientResourceStart event handler... but what should I replace it with?
  13. Yes.. I wrote the question first then thought about that ... sorry ? and thank you. You helped me a lot
  14. Thanks. I trying with thisdp's DX GUI System but for some reason it's display "clicked" multiple times in chatbox when I click to the "Sell" button... What do I doing wrong? I need to check the button left or right & the state of the button? function test() window = DGS:dgsCreateWindow(screenW - 278 - 10, (screenH - 237) / 2, 278, 237,"Your weapon list",false) gridlist = DGS:dgsCreateGridList (0.04, 0.11, 0.92, 0.78, true, window ) column = DGS:dgsGridListAddColumn(gridlist, "Weapons", 0.5) for k, v in ipairs(items) do row = DGS:dgsGridListAddRow(gridlist, v[1]) DGS:dgsGridListSetItemText ( gridlist, row, column, v[1] ) end button = DGS:dgsCreateButton(0.62, 0.88, 0.34, 0.08, "Sell", true, gridlist) addEventHandler ( "onDgsMouseClick", button, BttnClick, false ) end addEventHandler ( "onClientResourceStart", resourceRoot, test ) function BttnClick() outputChatBox("clicked") end
×
×
  • Create New...