Jump to content

Please help Bad argument


Recommended Posts

Hello gentlemen, I hope you are having a nice week, Well I am having a problem to see if you can help me solve it, I will thank you very much.

I am going to explain how it works, when picking up a box the user has to make a delivery and from there it generates money, but what happens, it only gives me the xp, but not the money, do you have any idea how to solve this ?.

Bad argument @ "givePlayerMoney" [Expected number at argument 2, git nill]

function createEnd()
    local money = math.random(1,#Entregas)
    local x,y,z = unpack(Entregas[money])
    MarkerEntrega = exports["x"]:createMarker("padrao2", Vector3 {x, y, z-0.9})
    addEventHandler("onClientMarkerHit", MarkerEntrega,
    function(hitElement)
        if hitElement == localPlayer then 
            local veh = getPedOccupiedVehicle(localPlayer)
            if veh and getElementModel(veh) == 530 then 
                local box = getElementData(veh, "dock.Caixa")
                if box and serviceActive then 
                    --local money = math.random(200, 290)
                    local money = math.random(money1, money2)
                    local exp = math.random(exp1, exp2)
                    givePlayerMoney(localPlayer, money)
                    triggerServerEvent("dock.removeCaixa", localPlayer, localPlayer)
                    triggerServerEvent("GiveExp", localPlayer, localPlayer, exp)
                    notifyC("x $ "..formatNumber(money)..",00.", "success")
                    notifyC("x", "info")
                    if getBoxCount() < 1 then 
                        generateBoxes()
                    end
                    destroyElement(source)
                else 
                    notifyC("x", 'error')
                end
            end
        end
    end)
end

 

Link to comment

I see that you want to randomize the money, I made this little example with "addCommandHandler", I tested it (I know this is not the way you want the script works but this is how I tested and It isn't showing any syntax error or something like that):

-----------EXAMPLE 1-------------- (TABLE)
moneyTable = {41244, 421, 1, 9876} ----A table in case you want specific "numbers"

function moneyRandomizer(thePlayer, command)
    local money = (moneyTable[math.random(#moneyTable)]) -------- This is how I randomize the number inside the table
    givePlayerMoney(thePlayer, money)
    iprint("money: "..money)
end
addCommandHandler("plata", moneyRandomizer)

------------EXAMPLE 2------------ (WITHOUT TABLE)
function moneyRandomizer(thePlayer, command)
    local money = math.random(190, 240) ----------------------This randomize between two values
    givePlayerMoney(thePlayer, money)
    iprint("money: "..money)
end
addCommandHandler("plata", moneyRandomizer)

So in your table you should replace 

local money = math.random(money1, money2) ----- your code

----Replace it with:

yourTable = {240, 260}
local money = (yourTable[math.random(#yourTable)]) ------EXAMPLE 1
----Or:

local money = math.random(190, 240)--------EXAMPLE 2

Also, you made the local function money twice, maybe you should remove it

Edited by Cronoss
Link to comment
  • Moderators

Where are money1 and money2 defined ? Can you print the values ?

Also, 2 things to note: https://wiki.multitheftauto.com/wiki/GivePlayerMoney

  1.   On the client side, it only takes 1 argument (your error looks like a server side error, so I don't think it is related to the givePlayerMoney you are showing us in your code).
  2. Don't add money on the client side, wiki says:
    image.png.bc1530d78d8be65120ab94057fd68f83.png
    So just like the XP, make a triggerServerEvent to then add the money on the server side. (For optimisation, make only 1 triggerServerEvent to add XP and money on the server side)
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...