Jump to content

[HELP] Box System


xXGhostXx

Recommended Posts

Posted

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

Posted (edited)
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
Posted
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)

Posted (edited)
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
Posted
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 '

Posted
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

Posted (edited)

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
Posted (edited)
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
Posted

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)

 

Posted
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?

Posted

If player's box amount is equals to zero .. then it outputs. If there isn't "tedad" value in the account, set value to 0 and it output. It wouldn't output twice a same time.

Posted
2 minutes ago, DeadthStrock said:

If player's box amount is equals to zero .. then it outputs. If there isn't "tedad" value in the account, set value to 0 and it output. It wouldn't output twice a same time.

Which take output for simplified code ?

Line 11 or 14 ?

Posted

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)

 

Posted
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 ?

Posted

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

Posted
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)

 

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