Jump to content

atmsystem Bugged help


rogerioexper

Recommended Posts

Hello atmbank system is initializing when the player enters is already in the middle of the screen and does not leave it should be some bug can help me to clean it I liked the system a lot and change the image only help me with this bug starting next to the player and not Date
--====================================================--
-- //             Script By ShWaEkI                 \\ --
--//              Don't Remove This                  \\ --
--=======================================================--

staticimage  = {}
PathImage  = {}
ParentImage = {}
BankMoney = 0

_guiCreateStaticImage = guiCreateStaticImage
function guiCreateStaticImage( X, Y, W, D, URl1 , R, P, URl2 )
	Image1 = _guiCreateStaticImage(X, Y, W, D, "images/"..URl1.."1.png", R, P)
	Image2 = _guiCreateStaticImage(( X ==  317  and X-117 or X+48 ),  Y, 120, 50, "images/"..URl2.."1.png", R, P)
	PathImage[Image1] = { URl1, URl2 }
	ParentImage[Image1] = Image2
	return Image1
end

addEventHandler("onClientResourceStart", resourceRoot,
function()
	local screenW, screenH = guiGetScreenSize()
        staticimage[1] = _guiCreateStaticImage((screenW - 378) / 2, (screenH - 335) / 2, 378, 335, "images/back.png", false)
		guiSetVisible ( staticimage[1], false  )
		
		WindowLabel1 = guiCreateLabel(0, 0, 378, 335, "", false, staticimage[1])
        staticimage[2] = guiCreateStaticImage(317, 98, 50, 50, "b", false, WindowLabel1, "deposit-")
        staticimage[3] = guiCreateStaticImage(10, 98, 50, 50, "g", false, WindowLabel1, "transfer-")
        staticimage[4] = guiCreateStaticImage(317, 183, 50, 50, "b", false, WindowLabel1, "withdraw-")
        staticimage[5] = guiCreateStaticImage(10, 183, 50, 50, "g", false, WindowLabel1 ,"exit-")

		WindowLabel2 = guiCreateLabel(0, 0, 378, 335, "", false, staticimage[1])
		guiSetVisible ( WindowLabel2, false  )
		Label_1 = guiCreateLabel(38, 99, 340, 15, "English", false, WindowLabel2)
        Label_2 = guiCreateLabel(0, 77, 340, 15, "عربي", false, WindowLabel2)
        guiLabelSetHorizontalAlign(Label_2, "right", false)
        guiSetFont(Label_1, "default-bold-small")
        guiSetFont(Label_2, "default-bold-small")
		guiLabelSetColor(Label_1, 0, 255, 255)    
		guiLabelSetColor(Label_2, 0, 255, 255)    
        Edit  = guiCreateEdit(130, 139, 108, 23, "0", false, WindowLabel2)    
		staticimage[6] = guiCreateStaticImage(317, 183, 50, 50, "b", false, WindowLabel2, "deposit-")
		staticimage[7] = guiCreateStaticImage(10, 183, 50, 50, "g", false, WindowLabel2 ,"back-")
		
		Label_3 = guiCreateLabel(129, 277, 111, 15, "$122", false, staticimage[1])
		Label_4 = guiCreateLabel(129, 302, 111, 15, "$122111", false, staticimage[1])
        guiSetFont(Label_3, "default-bold-small")
        guiSetFont(Label_4, "default-bold-small")
        guiLabelSetColor(Label_3, 0, 255, 0)
        guiLabelSetColor(Label_4, 255, 255, 0)  

		WindowLabel3 = guiCreateLabel(0, 0, 378, 335, "", false, staticimage[1])
		guiSetVisible ( WindowLabel3, false  )	
		staticimage[8] = guiCreateStaticImage(317, 183, 50, 50, "b", false, WindowLabel3, "transfer2-")
		staticimage[9] = guiCreateStaticImage(10, 183, 50, 50, "g", false, WindowLabel3 ,"back-")	
		Edit_2 = guiCreateEdit(189, 99, 168, 24, "0", false, WindowLabel3)
        Edit_3 = guiCreateEdit(189, 133, 168, 24, "0", false, WindowLabel3)
        Label_5 = guiCreateLabel(68, 101, 106, 22, "ID  / رقم التعريف", false, WindowLabel3)
        Label_6 = guiCreateLabel(68, 137, 106, 20, "Money / المبلغ", false, WindowLabel3)  
		guiSetFont(Label_5, "default-bold-small")
        guiSetFont(Label_6, "default-bold-small")
        guiLabelSetColor(Label_5, 0, 255, 0)
        guiLabelSetColor(Label_6, 255, 255, 0) 
		
		for i, v in ipairs ( getElementsByType( "object" ,resourceRoot) ) do
			setObjectBreakable( v, false )
		end
end )


addEventHandler( "onClientGUIClick", resourceRoot, 
function ( )
	if ( source == staticimage[2] ) then
		guiSetVisible ( WindowLabel1, false)
		guiSetVisible ( WindowLabel3, false)
		guiSetVisible ( WindowLabel2, true)
		guiSetText( Edit, "0" )
		guiSetText( Label_1, "type the amount you want to deposit in the bank" )
		guiSetText( Label_2, "قم بكتابة المبلغ الذي تريد ايداعه في البنك" )
		optionType = "Deposit"
		local Parent = ParentImage[staticimage[6]]
		guiStaticImageLoadImage ( Parent, "images/deposit-1.png" )
	elseif ( source == staticimage[4] ) then
		guiSetVisible ( WindowLabel1, false)
		guiSetVisible ( WindowLabel3, false)
		guiSetVisible ( WindowLabel2, true)
		guiSetText( Edit, "0" )
		guiSetText( Label_1, "type the amount you want to withdraw from the bank" )
		guiSetText( Label_2, "قم بكتابة المبلغ الذي تريد سحبه من البنك" )
		optionType = "Withdraw"
		local Parent = ParentImage[staticimage[6]]
		guiStaticImageLoadImage ( Parent, "images/withdraw-1.png" )
	elseif ( source == staticimage[3] ) then
		guiSetVisible ( WindowLabel1, false )
		guiSetVisible ( WindowLabel2, false)
		guiSetVisible ( WindowLabel3, true)
		optionType = "Transfer"
	elseif ( source == staticimage[5] ) then
		guiSetVisible ( staticimage[1], false)
		showCursor( false )
	elseif ( source == staticimage[6] ) then
		local Money = tonumber( guiGetText(Edit)  )
		if ( optionType and Money > 0 ) then
			triggerServerEvent ("BankAction", localPlayer, optionType, Money )
		end
	elseif ( source == staticimage[7] ) then
		guiSetVisible ( WindowLabel2, false)
		guiSetVisible ( WindowLabel1, true)
	elseif ( source == staticimage[8] ) then
		local Money = tonumber( guiGetText(Edit_3)  )
		local ID = tonumber( guiGetText(Edit_2)  )
		if ( optionType and ID and Money > 0 ) then
			triggerServerEvent ("BankAction", localPlayer, optionType, Money, ID )
		end
	elseif ( source == staticimage[9] ) then
		guiSetVisible ( WindowLabel3, false)
		guiSetVisible ( WindowLabel1, true)
	end
end )


addEvent( "updateBalanceLabel", true )
addEventHandler( "updateBalanceLabel", root,
function ( Money, MaxMoney )
	if ( not guiGetVisible ( staticimage[1] ) ) then
		guiSetVisible( staticimage[1], true) 
		showCursor( true )
	end
	BankMoney = Money
	guiSetText(Label_3 ,"$"..convertNumber ( Money ) )
	guiSetText(Label_4 ,"$"..convertNumber ( MaxMoney )  )
end )

addEvent( "closeBankWindow", true )
addEventHandler( "closeBankWindow", root,
function (  )
	guiSetVisible ( WindowLabel3, false)
	guiSetVisible ( WindowLabel2, false)
	guiSetVisible ( WindowLabel1, true)
	guiSetVisible( staticimage[1], false) 
	showCursor( false )
end )


addEventHandler("onClientMarkerLeave", resourceRoot,
function ( player ) 
	if ( getElementType(player) == "player" ) and ( player == localPlayer )  then
		if ( guiGetVisible ( staticimage[1] ) ) then
			guiSetVisible( staticimage[1], false) 
			showCursor( false )
		end
	end
end )


addEventHandler("onClientGUIChanged", resourceRoot, 
function ()
	local Text = guiGetText(source)
	if ( Text == "" ) then
		guiSetText(source, "0")
	elseif ( not tonumber(Text) ) then
		guiSetText(source, string.gsub(Text, "[^%d]", ""))
	elseif ( tonumber(Text)  < 0 ) then
		guiSetText(source, "0")
	else
		if ( optionType == "Deposit" ) then
			if ( tonumber(Text)  > getPlayerMoney() ) then
				guiSetText(source, getPlayerMoney() )
			end
		elseif ( optionType == "Withdraw" ) then
			if ( tonumber(Text)  > tonumber(BankMoney) ) then
				guiSetText(source, tonumber(BankMoney) )
			end
		end
	end
end )

addEventHandler( "onClientMouseEnter", resourceRoot, 
function()
	if ( getElementType(source) == "gui-staticimage" )  then
		local Path = PathImage[source]
		if ( Path ) then
			guiStaticImageLoadImage ( source, "images/"..Path[1].."2.png" )
			local Parent = ParentImage[source]
			if ( Parent ) then
				if ( source == staticimage[6] ) then
					if ( optionType == "deposit" ) then
						guiStaticImageLoadImage ( Parent, "images/deposit-2.png" )
					elseif ( optionType == "withdraw" ) then
						guiStaticImageLoadImage ( Parent, "images/withdraw-2.png" )
					end
				else
					guiStaticImageLoadImage ( Parent, "images/"..Path[2].."2.png" )
				end
			end
		end
	end
end )

addEventHandler( "onClientMouseLeave", resourceRoot, 
function()
	if ( getElementType(source) == "gui-staticimage" ) then
		local Path = PathImage[source]
		if ( Path ) then
			guiStaticImageLoadImage ( source, "images/"..Path[1].."1.png" )
			local Parent = ParentImage[source]
			if ( Parent ) then
				if ( source == staticimage[6] ) then
					if ( optionType == "deposit" ) then
						guiStaticImageLoadImage ( Parent, "images/deposit-1.png" )
					elseif ( optionType == "withdraw" ) then
						guiStaticImageLoadImage ( Parent, "images/withdraw-1.png" )
					end
				else
					guiStaticImageLoadImage ( Parent, "images/"..Path[2].."1.png" )
				end
			end
		end
	end
end )

function convertNumber ( number )  
	local formatted = number  
	while true do      
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')    
		if ( k==0 ) then      
			break   
		end  
	end  
	return formatted
end
--====================================================--
-- //             Script By ShWaEkI                 \\ --
--//              Don't Remove This                  \\ --
--=======================================================--

PlayersID = {}
Accounts = {}
local Markers = { 
     { 2456.70 , -1513.3 ,  23, { 2456.7  ,-1514 ,23.6, 180 } },
     { 1456.60 , -1583.6 , 12.6, { 1456.6,-1582.9,  13.2, 0 } },
     { 1109.80 , -924.50  , 42.4, { 1109.8  ,-923.9 ,43, 0 } },
     { 2082.60 , 1156.50 , 10.1, { 2083.3 ,1156.5 ,10.5 , 270 } },
     { 2086.40 , 2059.50 , 10, { 2085.7 ,2059.5 ,10.7 , 90 } },
     { -1589.4 , 1239.60 , 6.2, { -1588.7 ,1239.6 ,6.8 , 270 } },
     { -2338.6 , -79.300 , 34.4, { 2338.6 ,-79.9  ,35 , 0 } },
	 { 359.000 , -2071.7 , 9.62, { 359,-2071.1,10.3, 0 } },
--	{Marker_X, Marker_Y, Marker_Z, { Object_X, Object_Y, Object_Z, Object_R } },
}




exports["scoreboard"]:scoreboardAddColumn ( "ID", root, 20, "ID", 1 )


MaxMoney = 5000000

addEventHandler ( 'onPlayerLogin', root,
function ( _, Account )
	Accounts[source] = Account
end )

addEventHandler ( "onPlayerJoin", root,
function( )
	setElementData ( source, "ID", getFreeID( ) )
end)

addEventHandler ( "onPlayerQuit", root,
function( )
    PlayersID[getElementData (source, "ID")] = nil
end)

addEventHandler ( "onResourceStart", resourceRoot,
function  ( )
	for i, v in ipairs ( getElementsByType ( "player" ) ) do
		if ( not isGuestAccount ( getPlayerAccount ( v ) ) ) then 
			Accounts[v] = getPlayerAccount ( v )
		end
		PlayersID[i] = v
		setElementData (v, "ID", i )
	end
	for i,v in ipairs(Markers) do 
		local Marker = createMarker(v[1],v[2],v[3],"cylinder", 1, 0, 255, 0, 120)
		local Object = createObject ( 2942, v[4][1],v[4][2],v[4][3]-0.3, 0, 0, v[4][4] )
		local Blip = createBlipAttachedTo( Object, 52, 2, 0, 0, 0, 0, 3, 400 )
		setElementFrozen( Object, true )
	end
end )


addEvent( "BankAction", true )
addEventHandler( "BankAction", root,
function ( Action, Money, ID )
	if ( Accounts[source] ) then
		if Action == "GetMoney" then
			showBankMoney( source,  Accounts[source] )
		elseif Action == "Deposit" then
			if Money > getPlayerMoney( source )  then
				outputChatBox("You dont have enough enough Money !", source, 255, 0, 0 )
				return
			end
			giveBankMoney( Accounts[source], Money )
			takePlayerMoney(source, Money)
			showBankMoney( source, Accounts[source] )
			closeBankWindow( source )
		elseif Action == "Withdraw" then
			if Money > getBankMoney( Accounts[source] )  then
				outputChatBox( "You dont have money on your account to Withdraw it !", source, 255, 0, 0 )
				return
			end
			takeBankMoney( Accounts[source], Money )
			givePlayerMoney(source, Money)
			showBankMoney( source, Accounts[source] )
			closeBankWindow( source )
		elseif Action == "Transfer" then
			local player = getPlayerFromID( ID )
			if not ( player )then
				outputChatBox( "Not Found Player ", source, 255, 0, 0 )
				return
			end
			if Money > getBankMoney( Accounts[source] )  then
				outputChatBox( "You dont have money on your account to Transfer it !", source, 255, 0, 0 )
				return
			end
			if source == player then
				outputChatBox("You can't transfer to yourself ", source, 255, 0, 0 )
				return
			end
			takeBankMoney( Accounts[source], Money )
			giveBankMoney( Accounts[player], Money )
			showBankMoney( source, Accounts[source] )
			showBankMoney( player, Accounts[player] )
			outputChatBox( "You have successfully send Money to ".. getPlayerName(player) .." $".. Money .."!", source, 0,255,0)
			outputChatBox( getPlayerName(source) .." have send Money to you $ ".. Money .."!", player, 0,255,0)
			closeBankWindow( source )
		end
	end
end )

addEventHandler("onMarkerHit", resourceRoot,
function ( player, MD ) 
    local px, py, pz = getElementPosition ( player )
	local mx, my, mz = getElementPosition ( source )
	if ( Accounts[player] ) and ( MD ) and ( pz-3 < mz ) and ( pz+3 > mz ) then
		showBankMoney( player, Accounts[player] )
	end
end )


function showBankMoney( player, Account )
	triggerClientEvent (player, "updateBalanceLabel", player, getBankMoney( Account ), MaxMoney )
end

function closeBankWindow( player )
	triggerClientEvent (player, "closeBankWindow", player )
end

function setBankMoney( Account, Money )
	setAccountData (Account, "Bank", Money)
end

function getBankMoney( Account )
	return getAccountData (Account, "Bank") or 0
end

function takeBankMoney( Account, Money )
	setAccountData (Account, "Bank", ( getBankMoney( Account ) - Money ))
end

function giveBankMoney( Account, Money )
	setAccountData (Account, "Bank", ( getBankMoney( Account ) + Money ))
end

function getFreeID( )
	local NewID =  false
	for i=1,getMaxPlayers() do
		if ( not PlayersID[i] ) then
			NewID = i
			break
		end
	end
	return NewID
end

function getPlayerFromID( ID )
	local player = false
	for i, v in ipairs ( getElementsByType ( "player" ) ) do
		if getElementData (v, "ID") == tonumber( ID ) then
			player = v
			break
		end
	end
	return player
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...