Jump to content

A little problem


TorNix~|nR

Recommended Posts

guys the script works fine, but the line 16 and 17 have problem

:attempt to concatenate local 'targetPlayer' (a userdata value)

help please?

addCommandHandler("sendmoney",function(player,cmd,targetPlayer,money)
    money = tonumber(money) and math.floor(tonumber(money)) or nil
    if not (targetPlayer) or not (money) then
        outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true)
    else
        local targetPlayer = getPlayerFromName (targetPlayer) 
        local sourcename = getPlayerName (source) 		
        if targetPlayer then
            if (targetPlayer==player) then
                outputChatBox(" You cant give money to yourself.",player,255,0,0,true)
            elseif money <= 0 then
                outputChatBox(" Minimum ammount is 0.",player,255,0,0,true)
            elseif getPlayerMoney(player) >= money then   
                takePlayerMoney(player,money)
                givePlayerMoney(targetPlayer,money)
                outputChatBox ( "You gave " .. targetPlayer .. " " .. money .. "$", source, 0, 255, 0, true) -- THIS LINE
                outputChatBox ( "" .. sourcename .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE
            else
                outputChatBox(" You dont have enough money.",player,177,9,45,true)
            end
        end
    end
end)

 

Link to comment

If you were trying to use the function parameter "targetPlayer" as the target player's name you can't because line 6 overrides it.

You need to either change the name of the variable that holds the actual player at line 6 or change the function parameter's "targetPlayer" to "targetPlayerName" and use that at line 16.

Also in line 16 source is not defined use "player" as it is what you defined as the player who uses the command in your function parameter.

EDIT: I also suggest using getPlayerFromPartialName so u  don't have to type the player's FULL name each time you use the command

what if someone's name is jackthepro1164 all u gotta type is jac or 164 , thep etc..

Edited by Mr.Loki
Link to comment

same

15: attempt to concatenate local 'targetPlayerName' (a boolean / userdata value)

addCommandHandler("sendmoney",function(player,cmd,targetPlayer,money)
    money = tonumber(money) and math.floor(tonumber(money)) or nil
    if not (targetPlayer) or not (money) then
        outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true)
    else
        local targetPlayerName = getPlayerFromName (targetPlayer) 	
        if targetPlayer then
            if (targetPlayer==player) then
                outputChatBox(" You cant give money to yourself.",player,255,0,0,true)
            elseif money <= 0 then
                outputChatBox(" Minimum ammount is 0.",player,255,0,0,true)
            elseif getPlayerMoney(player) >= money then   
                takePlayerMoney(player,money)
                givePlayerMoney(targetPlayerName,money)
                outputChatBox ( "You gave " .. targetPlayerName .. " " .. money .. "$", player, 0, 255, 0, true) -- THIS LINE
                outputChatBox ( "" .. player .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE
            else
                outputChatBox(" You dont have enough money.",player,177,9,45,true)
            end
        end
    end
end)

 

  • Confused 1
Link to comment
addCommandHandler("sendmoney",function(player,cmd,targetPlayerName,money)
	money = tonumber(money) and math.floor(tonumber(money)) or nil
	if not (targetPlayerName) or not (money) then
		outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true)
	else
		local targetPlayer = getPlayerFromName (targetPlayerName) 	
		if targetPlayer then
			if (targetPlayer==player) then
				outputChatBox(" You cant give money to yourself.",player,255,0,0,true)
			elseif money <= 0 then
				outputChatBox(" Minimum ammount is 1.",player,255,0,0,true)
			elseif getPlayerMoney(player) >= money and money > 0 and targetPlayer~=player then   
				takePlayerMoney(player,money)
				givePlayerMoney(targetPlayer,money)
				outputChatBox ( "You gave " .. targetPlayerName .. " " .. money .. "$", player, 0, 255, 0, true) -- THIS LINE
				outputChatBox ( "" .. player .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE
			else
				outputChatBox(" You dont have enough money.",player,177,9,45,true)
			end
		end
	end
end)

You have to read through your code carefully.

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