Jump to content

CourtezBoi

Members
  • Posts

    35
  • Joined

  • Last visited

Everything posted by CourtezBoi

  1. This is what you have: addEventHandler ( 'onPlayerQuit', root, function ( ) local account = getAccountName(getPlayerAccount ( source )) local balance = getElementData ( source, 'Balance' ) executeSQLQuery ( 'INSERT INTO banking ( account, balance ) VALUES ( ?, ? )', account, balance ) end ) This is what you want: addEventHandler ( 'onPlayerQuit', root, function ( ) local account = getAccountName(getPlayerAccount ( source )) local balance = getElementData ( source, 'Balance' ) executeSQLQuery ( "UPDATE banking SET balance = '?' WHERE account = '?'", account, balance ) end )
  2. What is wrong with the script? Does it give you any errors or such?
  3. You'd do such in the map editor, or using a gate resource such as this one: https://community.multitheftauto.com/index.php?p= ... ls&id=3402 if you want them to be able to open and close.
  4. Figured it out myself, was some weird syntax error that SQL didn't feel like telling me about. Here is the final code, in case it can help somebody else. local char, error = exports.sql:query_insertid("INSERT INTO characters (`account`, `character`, `x`, `y`, `z`, `rotation`, `interior`, `dimension`, `skin`, `money`, `age`, `desc`) VALUES ("..'"'..table.concat( { account, name, x, y, z, rotation, interior, dimension, skin, money, age, desc }, '", "')..'")')
  5. Hello there. I'm creating an account system for my mta server, and I've completely finished except one line of code that refuses to cooperate. The below function is called from a client-side script, sending it the name, description, age and skin of a players new character that they're trying to create, and this functions job is to send that information to the database and essentially create the character. function createCharacter ( name, desc, age, skin ) player = source if ( type ( name ) == "string" ) and age and skin and desc then local account = getAccountID ( player ) if account then local x, y, z = 1480, -1744, 14 local rotation, interior, dimension = 0, 0, 0 local money = 750 local char, error = exports.sql:query_insertid("INSERT INTO characters (account, character, x, y, z, rotation, interior, dimension, skin, money, age, desc) VALUES ("..table.concat( { account, name, x, y, z, rotation, interior, dimension, skin, money, age, desc }, ", ")..")") if char then outputChatBox ( "DEBUG: QUERY SUBMITTED" ) outputChatBox ( name:gsub ( " ", "_" ).." "..age.." "..skin.." "..desc.." "..tostring ( char ) ) setPlayerName ( player, name:gsub ( " ", "_" ) ) outputChatBox ( "You are now playing as "..name:gsub("_", " ")..".", player, 155, 255, 155 ) spawnPlayer ( player, x, y, z, rotation, skin, interior, dimension ) loadCharacters ( player ) setCharacterID ( player, char ) else outputChatBox ( "DEBUG: QUERY FAILED" ) outputChatBox ( "ERROR: "..error, player, 255, 155, 155 ) end else outputChatBox ( "You must be logged in to continue.", player, 255, 155, 155 ) end else outputChatBox ( "An error has occured, please report this issue on the bugtracker.", player, 255, 155, 155 ) end end The problem is the query itself. local char, error = exports.sql:query_insertid("INSERT INTO characters (account, character, x, y, z, rotation, interior, dimension, skin, money, age, desc) VALUES ("..table.concat( { account, name, x, y, z, rotation, interior, dimension, skin, money, age, desc }, ", ")..")") For some reason, this refuses to query. In the above if statement, it always goes false, and outputs the DEBUG: QUERY FAILED but the error variable is still nil so the next line doesn't send. My question is simply, why does it not submit this query. I've looked at my vehicle system which uses a similar query, and it inserts perfectly fine! Thanks in advance to anybody who can help.
  6. Alright so I am making a vehicle system for my server that allows you to create vehicles, and each vehicle has its own ID, so that you can delete vehicles, get vehicles, park vehicles, goto vehicles, etc. all by ID. So I created an ID column in my SQLite table, and made the resource. addCommandHandler ( "createveh", function ( thePlayer, commandName, ... ) local message = table.concat( { ... }, " " ) if #message > 0 then local model = getVehicleModelFromName ( message ) local px, py, pz = getElementPosition (thePlayer) local rx, ry, rz = getElementRotation (thePlayer) if not model then outputChatBox ( "That is not a valid car name" ) else vehicle = createVehicle ( model, px + 5, py, pz + 2 ) local health = getElementHealth (vehicle) local color1, color2, color3, color4 = getVehicleColor(vehicle) local tableUpgrades = getVehicleUpgrades(vehicle) local upgrades = table.concat(tableUpgrades, ",") local paintjob = getVehiclePaintjob(vehicle) local vehicles = executeSQLQuery("SELECT * FROM vehicles") local carid = #vehicles + 1 executeSQLInsert ( "vehicles", "'"..model.."','"..px.."','"..py.."','"..pz.."','"..rx.."','"..ry.."','"..rz.."','"..color1.."','"..color2.."','"..health.."','"..upgrades.."','"..paintjob.."','".. carid .."'") outputChatBox ( "[ADM]"..getPlayerName( thePlayer ) .." spawned a " .. message .. "!", getRootElement (), 255,215,0 ) setElementData ( vehicle, "id", carid, true ) end end end ) Theres my code to create a vehicle, now it spawns the vehicle, gives it an ID, etc, but if I delete say vehicle two, then it throws my entire code off, because then the number of rows + 1 isn't the next ID in the set. Any idea how I could fix this?
  7. Thats what I'm trying to do, but I really couldn't figure out the error with this. The code you gave doesn't seem to work, it just always says player not found
  8. I got the error [14:49:09] WARNING: bank\bank.lua:587: Bad argument @ 'givePlayerMoney'
  9. Alright so I tried to create a command to be able to transfer money from one player to the next. I got the following error: [14:38:19] WARNING: bank\bank.lua:586: Bad argument @ 'givePlayerMoney' [14:38:19] ERROR: bank\bank.lua:590: attempt to concatenate local 'source' (a userdata value) Heres a copy of the code. function pay(source , cmd, thePlayer, amount) toWho = getPlayerFromName ( thePlayer) local cash = getPlayerMoney( source ) if cmd == "pay" then if (tonumber(amount)>0) then givePlayerMoney(toWho,amount) takePlayerMoney(source,amount) name = getPlayerName(source) outputChatBox("You've given " .. thePlayer .. " $" .. amount .. "." ,source,255,255,150) outputChatBox(source .. " has given you $" .. amount .. "!",toWho,255,255,245) else outputChatBox("[usage] /pay [iD] [amount]", source) end else outputChatBox("Amount have to be greater than 0!",source,255,0,0) end end addCommandHandler("pay", pay); Any ideas as to how I can fix this?
×
×
  • Create New...