Jump to content

Need help with new scripts


Recommended Posts

Posted

First of all a big hello to you all :)

Now, here's my problem. I recently started an RP server and we are building the gamemode using the paradise roleplay gamemode (yea, you can laugh :P ) but we can't figure out how to get our commands working. Infact we added a new folder containing the files and the resource gets loaded without problems but then when we use the command in game it doesn't work.

Also we can't figure out how to give weapons and money to players.

Hope someone can help us out and tell us what we are missing ^^

Posted

Okay i figured out how to get them start but i have a problem with one of these:

function pay(player, amount) 
        if(   givePlayerMoney ( player,  tonumber(amount) )   )  then 
            outputChatBox ("Hai dato dei soldi", source, 255, 255, 255, true ) 
        end 
end 
  
  
addCommandHandler ( "gmoney", pay  ) 

It says WARNING: commands\script.lua:20: Bad argument @ 'givePlayerMoney'

Posted

As addCommandHandler page in wiki says, handler function has player and command name as the first parameters:

player playerSource, string commandName, [string arg1, string arg2, ...] 

So the first line should look like this:

function pay(player, command, amount) 

In addition, since player may enter the command without writing the amount, you should check if tonumber(amount) returns a number value. Otherwise warning messages will show up.

Posted

Adding command didn't change anything but also, if we set a fixed import instead of a var (like 100 dollars) it works BUT it appear to be only on client side, infact when we relog the money are gone. (we also use a mysql database if it's important)

Posted (edited)
Okay i figured out how to get them start but i have a problem with one of these:

function pay(player, amount) 
        if(   givePlayerMoney ( player,  tonumber(amount) )   )  then 
            outputChatBox ("Hai dato dei soldi", source, 255, 255, 255, true ) 
        end 
end 
  
  
addCommandHandler ( "gmoney", pay  ) 

It says WARNING: commands\script.lua:20: Bad argument @ 'givePlayerMoney'

amount = ??

function pay(player) 
        if (givePlayerMoney ( player,  200  )  then 
            outputChatBox ("Hai dato dei soldi", source, 255, 255, 255, true ) 
        end 
end 
addCommandHandler ( "gmoney", pay  ) 
Edited by Guest
Posted
Okay i figured out how to get them start but i have a problem with one of these:

function pay(player, amount) 
        if(   givePlayerMoney ( player,  tonumber(amount) )   )  then 
            outputChatBox ("Hai dato dei soldi", source, 255, 255, 255, true ) 
        end 
end 
  
  
addCommandHandler ( "gmoney", pay  ) 

It says WARNING: commands\script.lua:20: Bad argument @ 'givePlayerMoney'

amount = ??

function pay(player) 
        if(   givePlayerMoney ( player,  200  )  then 
            outputChatBox ("Hai dato dei soldi", source, 255, 255, 255, true ) 
        end 
end 
  
  
addCommandHandler ( "gmoney", pay  ) 

Make no sense .

Posted

Use this because the way you are trying to check is wrong :

function pay( player ) 
        if ( getPlayerMoney ( player ) == ( 200 ) ) then 
            outputChatBox ( "Hai dato dei soldi",player, 255, 255, 255, true ) 
        end 
end 
addCommandHandler ( "gmoney", pay  ) 

:wink:

Posted
Use this because the way you are trying to check is wrong :

function pay( player ) 
        if ( getPlayerMoney ( player ) == ( 200 ) ) then 
            outputChatBox ( "Hai dato dei soldi",player, 255, 255, 255, true ) 
        end 
end 
addCommandHandler ( "gmoney", pay  ) 

He want give not get !

addCommandHandler ( "gmoney", 
function ( player ) 
if (givePlayerMoney(player,200)) then 
      outputChatBox ( "I've got a $ 200",player, 255, 255, 255, true ) 
      end 
end) 
Posted

I think he want's something like this :

addCommandHandler ( 'gmoney', function ( player, cmd, amount ) 
    if not tonumber( amount ) then 
        return 
    end 
    local give = givePlayerMoney ( player,  amount ) 
    if give then 
        outputChatBox ( 'Hai dato dei soldi', player, 255, 255, 255, true ) 
    end 
end ) 

Posted

Thanks "The best" but the problem is, with this command i give a stated amount of money and i want to be able to set the amount i want everytime, also the big problem is the money disappear after i relog on the server so they are only in client side becouse they don't get saved. How can i make it work on server side?

Posted

Can you give me an example of what i should write to save the money in the player account? i can't figure it out myself...

Posted
addEventHandler ("onPlayerQuit", root, 
    function () 
        local playerAccount = getPlayerAccount (source) 
        local playerMoney = getPlayerMoney (source) 
        setAccountData etc. 
    end 
) 

Just a basic start to give you an idea what to do. Save player's money to account data and then retrieve the account data onPlayerLogin.

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