Jump to content

[HELP] Box System


xXGhostXx

Recommended Posts

Hello everyone.

I make box system and for save number box i used set account data.

Command : /givebox <PlayerName> <Number>

function dadanBox (thePlayer, command, player, tedad)
	local taraf = getPlayerFromName (player)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(taraf)
	local box = getAccountData(account, tedad)
	local esmAdmin = getPlayerName(thePlayer)
	local esmesh = getPlayerName(taraf)
	if taraf then
	if tedad then
		setAccountData(taraf, account, box+tedad)
		outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)
		outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)
	else
		outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)
	end
	else
		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)
	end
end
addCommandHandler("givebox", dadanBox)

And for show number box I used get account data.

function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, tedad)
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

What is problem ?!

Please answer me.

@iMr.WiFi..! @Dimos7

Link to comment
function dadanBox (thePlayer, command, player, tedad)
	local taraf = getPlayerFromName (player)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(taraf)
	local box = getAccountData(account, tedad)
	local esmAdmin = getPlayerName(thePlayer)
	local esmesh = getPlayerName(taraf)
	if taraf then
	if tedad then
		setAccountData( account,"tedad" box+tedad)
		outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)
		outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)
	else
		outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)
	end
	else
		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)
	end
end
addCommandHandler("givebox", dadanBox)
function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

 

Edited by Dimos7
Link to comment
7 minutes ago, Dimos7 said:

function dadanBox (thePlayer, command, player, tedad)
	local taraf = getPlayerFromName (player)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(taraf)
	local box = getAccountData(account, tedad)
	local esmAdmin = getPlayerName(thePlayer)
	local esmesh = getPlayerName(taraf)
	if taraf then
	if tedad then
		setAccountData( account,"tedad" box+tedad)
		outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)
		outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)
	else
		outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)
	end
	else
		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)
	end
end
addCommandHandler("givebox", dadanBox)

function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

 

Debug error : attempt to perform arithmetic on local 'box' (a boolean value)

Link to comment
function dadanBox (thePlayer, command, player, tedad)
	local taraf = getPlayerFromName (player)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(taraf)
	local box = getAccountData(account, "tedad")
	local esmAdmin = getPlayerName(thePlayer)
	local esmesh = getPlayerName(taraf)
	if taraf then
	if tedad then
		setAccountData( account,"tedad", box+tedad)
		outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)
		outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)
	else
		outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)
	end
	else
		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)
	end
end
addCommandHandler("givebox", dadanBox)
function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

 

Edited by Dimos7
Link to comment
3 minutes ago, Dimos7 said:

function dadanBox (thePlayer, command, player, tedad)
	local taraf = getPlayerFromName (player)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(taraf)
	local box = getAccountData(account, "tedad")
	local esmAdmin = getPlayerName(thePlayer)
	local esmesh = getPlayerName(taraf)
	if taraf then
	if tedad then
		setAccountData( account,"tedad", box+tedad)
		outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)
		outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)
	else
		outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)
	end
	else
		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)
	end
end
addCommandHandler("givebox", dadanBox)

function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

 

Debug error : unexpected symbol near '

Link to comment
2 minutes ago, Dimos7 said:

line?

function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

line : 8

Test yourself

Link to comment

If there's not account data called "tedad" in the account, local value called box will receive a boolean [ false ]. So, you can't set it's data in line 10 since this is a boolean. Therefore, you need to set box's value to 0 if there isn't value already exists in that, like below.

Server Side :-

function dadanBox (thePlayer, command, player, tedad)
	local taraf = getPlayerFromName (player)
	local account = getPlayerAccount(taraf)
	local box = getAccountData(account, "tedad") or 0
	local tedad = tonumber(tedad)
	local esmAdmin = getPlayerName(thePlayer)
	local esmesh = getPlayerName(taraf)
	if taraf then
	    if tedad then
		    setAccountData( account,"tedad", box+tedad)
		    outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)
		    outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)
	    else
		    outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)
	    end
	else
		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)
	end
end
addCommandHandler("givebox", dadanBox)

function boxMan (thePlayer, command, tedad)
	local tedad = tonumber(tedad)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)
end
addCommandHandler("mybox", boxMan)

 

Edited by DeadthStrock
  • Haha 1
Link to comment
4 hours ago, DeadthStrock said:

If there's not account data called "tedad" in the account, local value called box will receive a boolean [ false ]. So, you can't set it's data in line 10 since this is a boolean. Therefore, you need to set box's value to 0 if there isn't value already exists in that, like below.

 Server Side :-


function dadanBox (thePlayer, command, player, tedad)	local taraf = getPlayerFromName (player)	local account = getPlayerAccount(taraf)	local box = getAccountData(account, "tedad") or 0	local tedad = tonumber(tedad)	local esmAdmin = getPlayerName(thePlayer)	local esmesh = getPlayerName(taraf)	if taraf then	    if tedad then		    setAccountData( account,"tedad", box+tedad)		    outputChatBox("#00ff00[Done]: #ffffffShoma Be #00ff00"..esmesh.." #ffffffTedad "..tedad.." Box Dadid!", thePlayer, 255, 255, 255, true)		    outputChatBox("#ffff00[Info]: #ffffffAdmin #ffff00"..esmAdmin.." #ffffffBe Shoma #ffff00"..tedad.." #ffffffBox Dad!", taraf, 255, 255, 255, true)	    else		    outputChatBox("#ff0000[Error]: #ffffffTedad Box Ra Vared Konid!", thePlayer, 255, 255, 255, true)	    end	else		outputChatBox("#00ff00Bezan: /givebox <PartOfName> <Tedad>", thePlayer, 255, 255, 255, true)	endendaddCommandHandler("givebox", dadanBox)function boxMan (thePlayer, command, tedad)	local tedad = tonumber(tedad)	local account = getPlayerAccount(thePlayer)	local box = getAccountData(account, "tedad")	outputChatBox("#00ff00Shoma #ffffff"..box.." #00ff00Box Darid!", thePlayer, 255, 255, 255, true)endaddCommandHandler("mybox", boxMan)

 

Thanks !!!!!!!!!

❤️ I LOVE YOU ❤️

What is problem ?!

function bazKardanBox (thePlayer, command)
	local account = getPlayerAccount(thePlayer)
	local box = getAccountData(account, "tedad")
	local jayeze = math.random(100000,600000)
	if ( getAccountData(account, "tedad") == true ) then
	givePlayerMoney(thePlayer, jayeze)
	setAccountData( account,"tedad", box-tedad)
	outputChatBox("#FF00FF[Pro-Box]: #ffffff"..getPlayerName(thePlayer).." Az Box Mablagh #FF00FF$"..jayeze.." #ffffffBe Dast Avord!", root, 255, 255, 255, true)
	else
		outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
	end
end
addCommandHandler("openbox", bazKardanBox)

I want when use /openbox take 1 box from account data and give Player money.

and if not box the player does not give the money

Edited by xXGhostXx
  • Like 1
Link to comment

Check this out !

function bazKardanBox (thePlayer, command)
  local account = getPlayerAccount(thePlayer)
  local box = getAccountData(account, "tedad")
  local jayeze = math.random(100000,600000)
	if ( box > 0 ) then -- the variable 'box' is actually a numeric value
	    givePlayerMoney(thePlayer, jayeze)
	    setAccountData( account,"tedad", box-1) -- 1 will be deducted from current box amount
	    outputChatBox("#FF00FF[Pro-Box]: #ffffff"..getPlayerName(thePlayer).." Az Box Mablagh #FF00FF$"..jayeze.." #ffffffBe Dast Avord!", root, 255, 255, 255, true)
	else
	    if box == 0 then -- box amount is 0
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
		else -- when box ammount isn't exists or it's a boolean
		    setAccountData( account,"tedad", 0)
			outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
		end
	end
end
addCommandHandler("openbox", bazKardanBox)

 

Link to comment
2 minutes ago, DeadthStrock said:

Check this out !


function bazKardanBox (thePlayer, command)  local account = getPlayerAccount(thePlayer)  local box = getAccountData(account, "tedad")  local jayeze = math.random(100000,600000)	if ( box > 0 ) then -- the variable 'box' is actually a numeric value	    givePlayerMoney(thePlayer, jayeze)	    setAccountData( account,"tedad", box-1) -- 1 will be deducted from current box amount	    outputChatBox("#FF00FF[Pro-Box]: #ffffff"..getPlayerName(thePlayer).." Az Box Mablagh #FF00FF$"..jayeze.." #ffffffBe Dast Avord!", root, 255, 255, 255, true)	else	    if box == 0 then -- box amount is 0		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )		else -- when box ammount isn't exists or it's a boolean		    setAccountData( account,"tedad", 0)			outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )		end	endendaddCommandHandler("openbox", bazKardanBox)

 

Why the chatBox line 11 are repeated twice?

Link to comment

Below one is the better one. Since it checking if account data exist before any processes.

function bazKardanBox (thePlayer, command)
  local account = getPlayerAccount(thePlayer)
  local box = getAccountData(account, "tedad")
  local jayeze = math.random(100000,600000)
	if ( box and box > 0 ) then -- the variable 'box' is actually a numeric value
	    givePlayerMoney(thePlayer, jayeze)
	    setAccountData( account,"tedad", box-1) -- 1 will be deducted from current box amount
	    outputChatBox("#FF00FF[Pro-Box]: #ffffff"..getPlayerName(thePlayer).." Az Box Mablagh #FF00FF$"..jayeze.." #ffffffBe Dast Avord!", root, 255, 255, 255, true)
	else
	    if box == 0 then -- box amount is 0
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
	    else
		    setAccountData( account,"tedad", 0)
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
		end
	end
end
addCommandHandler("openbox", bazKardanBox)

 

Link to comment
1 minute ago, DeadthStrock said:

Below one is the better one. Since it checking if account data exist before any processes.


function bazKardanBox (thePlayer, command)
  local account = getPlayerAccount(thePlayer)
  local box = getAccountData(account, "tedad")
  local jayeze = math.random(100000,600000)
	if ( box and box > 0 ) then -- the variable 'box' is actually a numeric value
	    givePlayerMoney(thePlayer, jayeze)
	    setAccountData( account,"tedad", box-1) -- 1 will be deducted from current box amount
	    outputChatBox("#FF00FF[Pro-Box]: #ffffff"..getPlayerName(thePlayer).." Az Box Mablagh #FF00FF$"..jayeze.." #ffffffBe Dast Avord!", root, 255, 255, 255, true)
	else
	    if box == 0 then -- box amount is 0
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
	    else
		    setAccountData( account,"tedad", 0)
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
		end
	end
end
addCommandHandler("openbox", bazKardanBox)

 

I deleted chat box line 14, no problem ?

Link to comment
6 minutes ago, DeadthStrock said:

no problem. But, when a player command /openbox for first time, he wouldn't notify than he hadn't enough number of boxes.

I added sound for open box !

But sound played for all players !

How to add sound for the Player ?

Server :

function bazKardanBox (thePlayer, command)
  local account = getPlayerAccount(thePlayer)
  local box = getAccountData(account, "pBox")
  local jayeze = math.random(50000,300000)
	if ( box and box > 0 ) then
		triggerClientEvent("sedabox", root)
	    givePlayerMoney(thePlayer, jayeze)
	    setAccountData( account,"pBox", box-1)
	    outputChatBox("#FF00FF[Pro-Box]: #ffffff"..getPlayerName(thePlayer).." Az Box Mablagh #FF00FF$"..jayeze.." #ffffffBe Dast Avord!", root, 255, 255, 255, true)
	else
	    if box == 0 then
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
	    else
		    setAccountData( account,"pBox", 0)
		    outputChatBox( "#ff0000[Error]: #ffffffShoma Box Nadarid!", thePlayer, 255, 0, 0,true )
		end
	end
end
addCommandHandler("openbox", bazKardanBox)

Client :

addEvent("sedabox",true)
addEventHandler("sedabox",getRootElement(),function()
    local sound = playSound("Data/box.wav")
	setSoundVolume(sound, 5.0)
end)

 

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