AddEventHandler('playerJoining', function()
local _source = source
local identifier = GetPlayerIdentifiers(_source)[1]
local bank = 0
local cash = 0
local isRegistered = false
MySQL.Async.fetchAll("SELECT * FROM economy WHERE identifier = @identifier", {
['@identifier'] = identifier
}, function(result)
if result[1] ~= nil then
isRegistered = true
else
MySQL.Async.execute('INSERT INTO economy (identifier, bank, cash) VALUES (@identifier, @bank, @cash)',
{ ['@identifier'] = identifier, ['@bank'] = bank, ['@cash'] = cash }
)
end
end)
end)
RegisterCommand("givecash", function(source, args, rawCommand)
local identifier = GetPlayerIdentifier(GetPlayerFromServerId(args[1]))
local setamount = tonumber(args[2])
if IsPlayerAceAllowed(source, "admincommands") then
MySQL.Async.execute('UPDATE economy SET cash = cash + @setamount WHERE identifier = @identifier')
end
end)
hopefully this helps you out… You was not telling the mysql where to look, You was not feeding the identifier or the amount to set the balance to.
RegisterCommand("givecash", function(source, args, rawCommand)
local identifier = GetPlayerIdentifier(GetPlayerFromServerId(args[1]))
local setamount = tonumber(args[2])
if IsPlayerAceAllowed(source, "admincommands") then
MySQL.Async.execute('UPDATE economy SET cash= cash + @cash WHERE identifier=@identifier',{
['@identifier'] = identifier, --send identifier that you get from the args.
['@cash'] = setamount, --This is where you send the data from
}, function(result)
if result then
-- put code here if you want something to happen if successful
else
--if fail put what ever here..
end
end)
end
end)
You are passing a arg from client to server, So the id you are typing in is already the persons server ID? If so then all you need to do is remove that