Hi,
I can't seem to trigger server event. Chat(), SetDisplay(), print works but not the trigger. What can I do? New to FiveM dev btw.
JS:
$("#submit").click(function () {
let IDinputValue = $("#IDinput").val()
let AmountinputValue = $("#Amountinput").val()
if (IDinputValue.length >= 100) {
$.post("http://nui2/error", JSON.stringify({
error: "Input was greater than 100"
}))
return
} else if (!IDinputValue) {
$.post("http://nui2/error", JSON.stringify({
error: "There was no value in the input field"
}))
return
}
// if there are no errors from above, we can send the data back to the original callback and hanndle it from there
$.post('http://nui2/main', JSON.stringify({
PlayerID: IDinputValue,
Amount: AmountinputValue,
}));
return;
})
Client side: (here I call the TriggerServerEvent)
RegisterNUICallback("main", function(data)
chat(data.PlayerID, {0,255,0})
SetDisplay(false)
print("test")
TriggerServerEvent('qb-faktura:server:payfaktura', source, data.PlayerID, data.Amount)
end)
Server side: (Here I register the ServerEvent)
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('qb-faktura:server:payfaktura', function(source, id, amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player.PlayerData.money.bank >= amount then
Player.Functions.RemoveMoney('bank', amount , "fakturabetaling")
--id.Functions.AddMoney('bank',amount, "fakturabetaling")
TriggerClientEvent('QBCore:Notify', src, "Du betalte " ..amount.. " kr til " .. id , "success")
else
TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok penger", "error")
end
end)
Anyone who knows?
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('qb-faktura:server:payfaktura')
AddEventHandler('qb-faktura:server:payfaktura', function(id, amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
id = tonumber(id)
amount = tonumber(amount)
if Player.PlayerData.money.bank >= amount then
Player.Functions.RemoveMoney('bank', amount , "fakturabetaling")
--id.Functions.AddMoney('bank',amount, "fakturabetaling")
TriggerClientEvent('QBCore:Notify', src, "Du betalte " ..amount.. " kr til " .. ID , "success")
else
TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok penger", "error")
end
end)
Fixed it. Easy fix. just handle as number and not string.