Recommended Posts

function buyWeapon(thePlayer, command)
	local mycoins = exports.coinsystem:getPlayerCoin(thePlayer)
		if (mycoins >= 1) then
			giveWeapon(thePlayer, 31, 2000)
			exports.coinsystem:takePlayerCoin(thePlayer, prize)
			outputChatBox("you bought a M4.", thePlayer, 0, 255, 0, false)
		else
			outputChatBox("you don't have enough coins!", thePlayer, 255, 0, 0, false)
	end
end
addCommandHandler("buyw", buyWeapon)

i got this error: xy.lua:17: attempt to compare number with nil

Share this post


Link to post

Please post the full script because, for example, prize is not declared

Second, you don't have line 17 in your posted script

Please tell us what the command is supposed to do( how it should work )

Share this post


Link to post
4 minutes ago, *BeaT* said:

Please post the full script because, for example, prize is not declared

Second, you don't have line 17 in your posted script

Please tell us what the command is supposed to do( how it should work )

This is the full code, sorry, line 3

Share this post


Link to post

Uou get this error because the

Quote

exports.coinsystem:getPlayerCoin(thePlayer)

Export, returns nil. So you can try this:

function buyWeapon( player, command )
	local p_coins = exports.coinsystem:getPlayerCoin( player )
	if tonumber( p_coins ) >= 1 then
		giveWeapon(player, 31, 2000)
		exports.coinsystem:takePlayerCoin(player, prize)
		outputChatBox("you bought a M4.", player, 0, 255, 0, false)		
	else
		outputChatBox("you don't have enough coins!", player, 255, 0, 0, false)
	end
end

 

  • Like 1

Share this post


Link to post
9 minutes ago, aka Blue said:

Uou get this error because the

Export, returns nil. So you can try this:


function buyWeapon( player, command )
	local p_coins = exports.coinsystem:getPlayerCoin( player )
	if tonumber( p_coins ) >= 1 then
		giveWeapon(player, 31, 2000)
		exports.coinsystem:takePlayerCoin(player, prize)
		outputChatBox("you bought a M4.", player, 0, 255, 0, false)		
	else
		outputChatBox("you don't have enough coins!", player, 255, 0, 0, false)
	end
end

 

working with command, but with button, doesn't working, why? :S 

addEvent( "m4", true ) 
addEventHandler( "m4", root, 
function ()
	local p_coins = exports.coinsystem:getPlayerCoin(player)
	if tonumber( p_coins ) >= 400 then
		giveWeapon(player, 31, 2000)
		exports.coinsystem:takePlayerCoin(player, 400)
		outputChatBox("you bought a M4.", player, 0, 255, 0, false)		
	else
		outputChatBox("you don't have enough coins!", player, 255, 0, 0, false)
	end
end
)

i got this error: xy.lua:3: attempt to compare number with nil

Share this post


Link to post

Because you use a player argument but its not defined. ¿Understand?. When you trigger to server, take sure you send the getLocalPlayer in the server too, something like this, see:

-- Client

triggerServerEvent( "m4", resourceRoot, getLocalPlayer( ) )

-- Server

addEvent( "m4", true ) 
addEventHandler( "m4", root, 
function ( player )
	local p_coins = exports.coinsystem:getPlayerCoin(player)
	if tonumber( p_coins ) >= 400 then
		giveWeapon(player, 31, 2000)
		exports.coinsystem:takePlayerCoin(player, 400)
		outputChatBox("you bought a M4.", player, 0, 255, 0, false)		
	else
		outputChatBox("you don't have enough coins!", player, 255, 0, 0, false)
	end
end
)

 

  • Like 1

Share this post


Link to post
1 minute ago, aka Blue said:

Because you use a player argument but its not defined. ¿Understand?. When you trigger to server, take sure you send the getLocalPlayer in the server too, something like this, see:


-- Client

triggerServerEvent( "m4", resourceRoot, getLocalPlayer( ) )

-- Server

addEvent( "m4", true ) 
addEventHandler( "m4", root, 
function ( player )
	local p_coins = exports.coinsystem:getPlayerCoin(player)
	if tonumber( p_coins ) >= 400 then
		giveWeapon(player, 31, 2000)
		exports.coinsystem:takePlayerCoin(player, 400)
		outputChatBox("you bought a M4.", player, 0, 255, 0, false)		
	else
		outputChatBox("you don't have enough coins!", player, 255, 0, 0, false)
	end
end
)

 

thanks

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.