Jump to content

DriFtyZ

Members
  • Posts

    73
  • Joined

  • Last visited

Everything posted by DriFtyZ

  1. full script is this addEventHandler("onResourceStart", resourceRoot, function (resource) connectionDb = dbConnect("sqlite", "user_settings.db") if connectionDb then outputDebugString( "Connection with database was successfully established." ) dbExec(connectionDb,"create table if not exists 'settings'(id INTEGER PRIMARY KEY, playerName TEXT, carReflect NUMBER, water NUMBER, contrast NUMBER, detail NUMBER, sky NUMBER, showFps NUMBER)") else outputDebugString( "Connection with database couldn't be established." ) end end ) function playerLogin(source) local playerAcc = getPlayerAccount(source) local accName = getAccountName(source) local playerQuery = dbQuerry(connectionDb,"SELECT * FROM settings WHERE playerName='..accName..'") local playerQueryResult = dbPoll(playerQuery, -1) if playerQueryResult == nil then local createPlayerIndex = dbExec(connectionDb, "INSERT INTO settings (playerName,carReflect,water,contrast,detail,sky,showFps) VALUES ('..accName..', 1, 1, 1, 1, 1, 1") end end addEventHandler("onPlayerLogin", resourceRoot, playerLogin)
  2. function playerLogin(source) local playerAcc = getPlayerAccount(source) local accName = getAccountName(source) local playerQuery = dbQuerry(connectionDb,"SELECT * from settings WHERE playerName=?", ..accName..) local playerQueryResult = dbPoll(playerQuery, -1) if playerQueryResult == nil then local createPlayerIndex = dbExec(connectionDb, "INSERT INTO settings VALUES (playerName,carReflect,water,contrast,detail,sky,showFps)", ""..accName"" , 1, 1, 1, 1, 1, 1 ) end end addEventHandler("onPlayerLogin", resourceRoot, playerLogin) it doesn't make any sense to me, i know its wrong but i can't figure this out (from sql part side)
  3. wikies dbExec and etc they just explain how to use that specific function but INSERT SELECT commands are something related to sql that wiki doens't explain about i tihnk (ill send you pm)
  4. i understand what you mean but can you be a bit more specific about the select, insert
  5. Hello fellows how are you ? Today i want to use database connections Into a simple script that im gonna make about user settings The script is simple a gui opens up and the user selects if he wants to enable disable some graphical settings (car reflection, water, detail, contrast, show fps counter etc blah blah) Script is made and works perfect but i want to save each user settings to database(sqlite for now since i don't want to have remote control of database for now so mysql is not needed) so when he logs on to server the settings he set before will be applied, and also if hes new user server will make a new list in database for that user with default settings (1(enable) for each setting)) anyway i don't need you to tell me how exaclty im gonna code that cause you will get through much work but i want to give me the idea how the hell am i gonna do this because the wiki is helpless in these things if you want some example how bad i am in scripting sql see below: playerSettings = {} function playerJoin() local settingsQuery = dbQuerry(connectionDb,"select * from settings") local settingsQueryResult = dbPoll(settingsQuery, -1) for i, user in pairs(settingsQueryResult) do local playerName = getAccountName(source) table.insert(playerSettings,playerName) end end addEventHandler("onPlayerJoin", resourceRoot, playerJoin) thanks in advance
  6. sorry, i have been little busy last day it wasn't server side script and i fixed it with your example, thanks
  7. hello community i started making a car shop scripting where when a player hits a marker it opens up a gui menu where he can select which he wants to buy, BUT when he selects a specific car on the list i made it to spawn inside the carshop to see how it look like is(preview car)... the thing is the vehicle that is created is not locally which means all the players can see it any ideas how to create and remove elements only for localPlayer?
  8. okay, thanks for your help, appreciated
  9. its related to first example you gave me addEventHandler("onClientGUIClick", resourceRoot, function(btn, state) if btn == "left" and state == "up" then local selRow, selInd = guiGridListGetSelectedItem(Carshop.gridlist[1]) if( selRow ~= -1 ) then guiSetEnabled( YOUR_GUI_BUTTON, true) else guiSetEnabled( YOUR_GUI_BUTTON, false) end end end) - if the left click is pressed and released - and if the gridlist (x) is selected - do this but if i click anywhere in a gui and the same row, index of the gridlist is selected it still excecutes the script i want somehow to end the loop if the user has the same thing selected already but i can't figure it out (lua tables thing got fixed over the rest of my day, sorry if i bother you too much)
  10. Thanks for your reply i fixed the problem over the night should i ask you one more detail or make a new topic? cause i can't really understand how to make this thing work properly here, it has to do with the tables as that was my main problem
  11. Sorry i meant guiSetVisible which is still.. im gonna try your new handler and btw what does the button() in bottom of script? Yes, somehow im still getting the nil warnings but the button works now, not only that im getting nil warnings almost in every guiSetVisible parameter i do but it works like a charm
  12. badargument @ eventhandler expected element at argument 2 and got nil but both of the 2 gui elements are active and the names of the vars are these what is wrong
  13. lets say the following script doesn't work Confirmation = { button = {}, } function button () Confirmation.window = guiCreateWindow(699, 412, 328, 164, "Car Shop", false) Confirmation.button.no = guiCreateButton(195, 104, 85, 31, "No", false, Confirmation.window) end function cancel () guiGetVisible (Confirmation.window, false) end addEventHandler ("onClientGUIClick", Confirmation.button.no, cancel, false ) its an example but still doesn't work when i set the button inside a function
  14. Understood sir one last ask-for-help here how can i trigger the onClientGUIClick button if its created inside an function? thanks for your help in advance lets say the events are addEventHandler ("onClientGUIClick", Confirmation.button.no, cancel, false ) addEventHandler ("onClientGUIClick", Confirmation.button.yes, buyVehicle, false ) I took your code to make a confirmation window appear with the buttons inside function confirmWindow(btn, state) if btn == "left" and state == "up" then local selRow, selInd = guiGridListGetSelectedItem(Carshop.gridlist[1]) local vehName = guiGridListGetItemText ( Carshop.gridlist[1], selRow, selInd ) local vehPrice = guiGridListGetItemText ( Carshop.gridlist[1], selRow, 2 ) if( selRow ~= -1 ) then Confirmation.window = guiCreateWindow(699, 412, 328, 164, "Car Shop", false) Confirmation.label = guiCreateLabel(54, 37, 226, 55, "Are you sure you want to buy "..vehName.." for $"..vehPrice..".", false, Confirmation.window) guiLabelSetHorizontalAlign(Confirmation.label, "left", true) Confirmation.button.no = guiCreateButton(195, 104, 85, 31, "No", false, Confirmation.window) -- (No Button) When i click it an event should be triggered? guiSetProperty(Confirmation.button.no, "NormalTextColour", "FFAAAAAA") Confirmation.button.yes = guiCreateButton(52, 104, 85, 31, "Yes", false, Confirmation.window) -- (Yes Button) same here when i click a whole other story script will run the vehicle in database, and blah blah (not written yet) guiSetProperty(Confirmation.button.yes, "NormalTextColour", "FFAAAAAA") else guiSetEnabled( Carshop.button.buyVehicle, false ) end end end Sorry if i ask a lot but this is my day 4 in scripting and the whole days im in front of the wikies looking for answer in what i do
  15. Thank you, if you mind can you explain to me what are btn, state, sel, selind?
  16. Thank you so much for your help i have another one problem for noobs like me how can i script the buy vehicle button to pop up only when i select something from the row i used the following function onClientGUIClick but still no sucess function buyVehicle (localPlayer) local carSelected = guiGridListGetSelectedItem ( Carshop.gridlist[1] ) if not carSelected == false then guiSetVisible (Confirmation.window, true) else return end end
  17. Hello community, i started learning lua few days ago and i want to create a carshop gui script but with custom vehicles and i want the gui to load their tables automatically but ican't figure it out any help? heres part of the script below(rest is useless in current situation) function createVehicleList () Carshop.gridlist[1] = guiCreateGridList(24, 37, 465, 397, false, Carshop.window) Carshop.column[1] = guiGridListAddColumn(Carshop.gridlist[1], "Vehicle", 0.5) Carshop.column[2] = guiGridListAddColumn(Carshop.gridlist[1], "Price", 0.2) if ( Carshop.column[1] ) then for a, b in pairs( VehiclesNames ) do local carName = b local carListRow = guiGridListAddRow ( Carshop.gridlist[1] ) guiGridListSetItemText ( Carshop.gridlist[1], carListRow, Carshop.column[1], carName , false, false ) end for c, d in pairs( VehiclePrices ) do local carPrice = d guiGridListSetItemText ( Carshop.gridlist[1], carListRow, Carshop.column[2], carPrice , false, false ) end end end heres my table values VehiclesNames = { silvia_s15 = "Nissan Silvia S15", sx240 = "Nissan 240SX", supra_mk4 = "Toyota Supra MK4", skyline_r32 = "Nissan Skyline R32", skyline_r34 = "Nissan Skyline R34", } VehiclePrices = { silvia_s15 = "40000", sx240 = "12000", supra_mk4 = "60000", skyline_r32 = "35000", skyline_r34 = "60000", } and a screenshot to understand a bit where i am stuck:
  18. Thanks a lot, i was going to make it dissapear through onresourcestart event but your option is more simple
  19. thanks a lot it worked but i can't understand why the panel opens up while starting the resource by default even since the event handle is gone now
  20. Hello mta community, im new to lua scripting (day 2) and i want to make a gui menu that has options inside to enable disable shaders but for now i can't even reach the way how the windows gets visible when i pree a key (F2 in my situation) can you help me out a bit? thanks in advance Here's my code below (yes i checked mta wiki) water = {} Contrast = {} Close = {} carpaint = {} contrast = {} graphics = {} detail = {} addEventHandler("onClientResourceStart", resourceRoot, function GuiWindow () graphics.window = guiCreateWindow(625, 207, 451, 315, "Graphics Menu", false) guiWindowSetSizable(graphics.window, false) guiSetAlpha(graphics.window, 0.85) guiSetProperty(graphics.window, "CaptionColour", "FFB1794C") carpaint.checkbox = guiCreateCheckBox(192, 53, 16, 20, "", false, false, graphics.window) water.checkbox = guiCreateCheckBox(192, 100, 17, 17, "", false, false, graphics.window) constrast.checkbox = guiCreateCheckBox(192, 144, 14, 16, "", false, false, graphics.window) detail.checkbox = guiCreateCheckBox(192, 187, 15, 15, "", false, false, graphics.window) Close.button = guiCreateButton(149, 243, 152, 49, "Close", false, graphics.window) guiSetProperty(Close.button, "NormalTextColour", "FFAAAAAA") carpaint.label = guiCreateLabel(39, 53, 86, 25, "Car Reflections", false, graphics.window) guiSetFont(carpaint.label, "default-bold-small") water.label = guiCreateLabel(39, 100, 104, 24, "Water Reflections", false, graphics.window) guiSetFont(water.label, "default-bold-small") contrast.label = guiCreateLabel(39, 142, 104, 26, "Contrast", false, graphics.window) guiSetFont(contrast.label, "default-bold-small") detail.label = guiCreateLabel(39, 186, 104, 26, "Detail", false, graphics.window) guiSetFont(detail.label, "default-bold-small") end ) bindKey ( "F2", "down", F2) function F2 () local state = guiGetVisible ( graphics.window ) if state == false then guiSetVisible (graphics.window, true) showCursor (true) else guiSetVisible (graphics.window, false) showCursor (false) end end
  21. Sorry i haven't noticed that on the wiki, Thanks for the reply i can now understead how the (k,v in pairs) works now when i want something specific. I started learning lua yesterday
  22. Hello people im new to scripting and i want to make a basic script that disables one vehicle component so i can enable the other on it (like front bumpers) lets say i have the stock front bumper (bump_front_dummy) visible by default and i want to hide it and enable the extra bumper that is on the model file.. im pretty sure this can be achieved somehow but i tried several things to make work without success links i used to learn: https://wiki.multitheftauto.com/wiki/GetVehicleComponents https://wiki.multitheftauto.com/wiki/SetVehicleComponentVisible here's my script below: addCommandHandler ( "test", function ( ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) local Component = getVehicleComponents ( theVehicle ) if ( theVehicle ) then for k in pairs ( Component("bump_front_dummy") ) do setVehicleComponentVisible(Component, k , false) end end end )
×
×
  • Create New...