Jump to content

i need help again :)


Erhabi

Recommended Posts

function gui ( )
       window = guiCreateWindow ( 0.4, 0.3, 0.3, 0.4, "Welcome "..getPlayerName ( getLocalPlayer () ), true )
       mymoney = guiCreateLabel ( 0.25, 0.10, 0.8, 0.12, "Your money: $"..getPlayerMoney ( source ), true, window )
       guiCreateLabel ( 0.1, 0.25, 0.8, 0.12, "Player:", true, window )
       guiCreateLabel ( 0.1, 0.44, 0.8, 0.12, "Money:", true, window )
       editBox1 = guiCreateEdit( 0.3, 0.26, 0.7, 0.12, "", true, window )
       editBox2 = guiCreateEdit( 0.3, 0.42, 0.7, 0.12, "", true, window )
       give = guiCreateButton ( 0.1, 0.58, 0.8, 0.12, "Give!", true, window )
addEventHandler ( "onClientGUIClick", give, give1, false )
end
addEventHandler ( "onClientResourceStart", getRootElement(), gui )
--------------
function show_gui ( )
guiSetText ( mymoney, "Your money: $"..getPlayerMoney ( source ) )
guiSetText ( window, "Welcome "..getPlayerName ( getLocalPlayer () ) )
       if ( guiGetVisible ( window ) == true ) then
               guiSetVisible ( window, false )
               showCursor ( false )
       else
               guiSetVisible ( window, true )
               showCursor ( true )
       end
end
function close_gui ( )
     showCursor ( false )
     guiSetVisible ( window, false )
end
function Keys ( )
     bindKey ( "F7", "down", show_gui )
end
addEventHandler( "onClientResourceStart", getRootElement( ), Keys )
addEventHandler ( "onClientResourceStart", getRootElement(), close_gui )
---------------
function give1 ( )
eee = guiGetText ( editBox1 )
player1 = getPlayerFromName ( eee )
ddd = guiGetText ( editBox2 )
end
---------------

my problem how can i get player name from editBox1 and give him money

i can't give him money in client.lua :(

because i can't set player in givePlayerMoney if it in client.lua

Link to comment

BE PATIENT!!!

Here's the script.. Please visit in http://www.wiki.multitheftauto.com in future, i wont help you with this kind of cases if you dont go there.

okay ..

CLIENT-SIDE

(client.lua)

-- Please go to wiki.multitheftauto.com so i dont need to help you in future --
-- Here's working script --
-- Taalasmaa handles --
 
 
function gui ( )
       window = guiCreateWindow ( 0.4, 0.3, 0.3, 0.4, "Welcome "..getPlayerName ( getLocalPlayer () ), true )
       mymoney = guiCreateLabel ( 0.25, 0.10, 0.8, 0.12, "Your money: $"..getPlayerMoney ( source ), true, window )
guiCreateLabel ( 0.1, 0.25, 0.8, 0.12, "Player:", true, window )
guiCreateLabel ( 0.1, 0.44, 0.8, 0.12, "Money:", true, window )
       editBox1 = guiCreateEdit( 0.3, 0.26, 0.7, 0.12, "", true, window )
       editBox2 = guiCreateEdit( 0.3, 0.42, 0.7, 0.12, "", true, window )
       give = guiCreateButton ( 0.1, 0.58, 0.8, 0.12, "Give!", true, window )
addEventHandler ( "onClientGUIClick", give, give1, false )
end
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), gui )
--------------
function show_gui ( )
guiSetText ( mymoney, "Your money: $"..getPlayerMoney ( source ) )
guiSetText ( window, "Welcome "..getPlayerName ( getLocalPlayer () ) )
if ( guiGetVisible ( window ) == true ) then
guiSetVisible ( window, false )
showCursor ( false )
else
guiSetVisible ( window, true )
showCursor ( true )
end
end
function close_gui ( )
showCursor ( false )
guiSetVisible ( window, false )
end
function Keys ( )
bindKey ( "F7", "down", show_gui )
end
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), Keys )
addEventHandler ( "onClientResourceStart",getResourceRootElement(getThisResource()), close_gui )
---------------
function give1 ( )
eee = guiGetText ( editBox1 )
ddd = guiGetText ( editBox2 )
triggerServerEvent ( "theMoney", getLocalPlayer(), eee,ddd ) -- This sends datas to the server where is the function --
end
---------------

SERVERSIDE

Example: (server.lua)

function giveThem ( userplayer,money ) -- The datas we just sent
local cash = getPlayerMoney(source) 
if (cash > tonumber(money)) then -- if player who is sending money got that much money that he want to send
moneyToGive = getPlayerFromName(userplayer) -- get the player who we want to give the moneys
if (moneyToGive ~= false) then -- if there player exist
givePlayerMoney(moneyToGive,money) -- give his money
name = getPlayerName(source) 
takePlayerMoney(source,money) -- take the money amount from the sender
outputChatBox("You've given money amount of: " .. money .. "$ for: " .. userplayer,source,255,255,0) -- just stuff you can change this --
outputChatBox(name .. " has given you money amount of: " .. money .. "$!",moneyToGive,255,255,0) -- the player who get the money will see this, can be changed too --
else
outputChatBox("Player did not exist",source,255,0,0) -- if there wasnt player
end
else
outputChatBox("You are trying to send amount of money that you even dont have?",source,255,0,0) -- if the sender does not have the amount of money he wants to send
end
end
addEvent( "theMoney", true )
addEventHandler( "theMoney", getRootElement(), giveThem )

Regards

Taalasmaa

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