Jump to content

Give money script doesn't work


Recommended Posts

i made my 1st scritp that ive ever done on my own today and i got an error on my server CMD saying stack overflow. Here is script.

local commandname = "pay" 
local note = "Here is $1000" 
  
function givePlayerMoney (player, cmd) 
    givePlayerMoney (player, 100) 
    outputChatBox(note, player, 255, 255, 0, false) 
end 
addCommandHandler(commandname, givePlayerMoney) 

It's probs a really stupid mistake i made so can someone please correct me.

Thanks

Link to comment

Yes it is silly mistake.

stack overflow can describe a function calling itself infinitely. If you check your function name that is called by the command, it is the same as the MTA function to give player money. Therefore, you override the MTA function with your custom function and then call it every time it's called. The function can't even reach end of its call because it keeps calling itself and I bet you don't even see a message "Here is $1000" because server will never execute it. So simple fix: change the function name to something else and it will work just fine.

Link to comment

You are using givePlayerMoney as a function name, try:

local commandname = "pay" 
local note = "Here is $1000" 
  
function giveMoney (player, cmd) 
    givePlayerMoney (player, 100) 
    outputChatBox(note, player, 255, 255, 0, false) 
end 
addCommandHandler(commandname, giveMoney) 

Also, don't forget the (lua) (/lua) tags, use [] instead of () !

Edit: Damnit, looks like 50p was faster.

Link to comment

Or then you can use this.

local commandname = "pay" 
local note = "Here is $100" 
  
addCommandHandler(commandname, 
    function(player, cmd) 
        givePlayerMoney(player, 100) 
        outputChatBox(note, player, 255, 255, 0, false) 
    end 
) 

By the way, I like your style, I suppose you read my tutorial? :)

Link to comment

Hahahahaha thanks guys, yea that was pretty stupid if me so yea I'll fix it.

Quote

By the way, I like your style, I suppose you read my tutorial? :)

And yea I read the health one and man you really know how to write a good tutorial mate. Nice work, it showed me Andes basics and that's y I gave the money one a go. Thanks for the tips and myonlake, keep making tutorials dude, your good at it and many people would love it as there are not many tutorials out there. I suggest you make a tutorial that shows how to script a GUI for a login or something. Then a gamemode so new scriptures are not playing on 'play'. Hen start to move to more advanced stuff such jobs and also saving your position, money, health and ammo so when you login next your where you left off.

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...