bartje01 Posted March 8, 2011 Share Posted March 8, 2011 Hey guys. Another question once again. I want that I can see my stats in a GUI menu. But the GUI menu is created in client.lua And my stats in server.lua So how will I do that? It was an event function but I'm not sure how to use it. Please help. Link to comment
proracer Posted March 8, 2011 Share Posted March 8, 2011 https://wiki.multitheftauto.com/wiki/TriggerServerEvent Link to comment
bartje01 Posted March 8, 2011 Author Share Posted March 8, 2011 Yea that was it. Thanks Could you also help me with my other problem please? viewtopic.php?f=91&t=32217 Link to comment
bartje01 Posted March 8, 2011 Author Share Posted March 8, 2011 Damn. It doesn't work At server side function greetingHandler ( message ) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", getRootElement(), greetingHandler ) At client side function greetingCommand ( sourcePlayer,cmd,who,amount ) triggerServerEvent ( "onGreeting", getLocalPlayer(), "Hello World!" ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local cash = getAccountData ( account, "data.cash" ) local deaths = getAccountData ( account, "data.deaths" ) local adminlevel = getAccountData ( account, "data.adminlevel" ) outputChatBox ( "The client says: " .. message, source ) outputChatBox ( "Money: ".. tostring( cash ) , thePlayer ) outputChatBox ( "Deaths: ".. tostring( deaths ), thePlayer ) outputChatBox ( "Adminlevel: ".. tostring( adminlevel ), thePlayer ) end end addCommandHandler ( "greet", greetingCommand ) Link to comment
proracer Posted March 8, 2011 Share Posted March 8, 2011 Account data's doesn't work with clientside files, you should use setElementData / getElementData instead. Link to comment
bartje01 Posted March 8, 2011 Author Share Posted March 8, 2011 Then what will it be? Like: local cash = getElementData ( account, "data.cash" ) I'm just not sure about this Link to comment
Moderators Citizen Posted March 8, 2011 Moderators Share Posted March 8, 2011 Yeah but you have to setElementData in the server-side before Link to comment
NotAvailable Posted March 8, 2011 Share Posted March 8, 2011 heres a part of my script: client: function swatCar() guiSetVisible(window, false) showCursor(false) triggerServerEvent( "spawnSWAT", getLocalPlayer(),getPlayerName( getLocalPlayer() ) ) end server: addEvent("spawnSWAT", true) function carSwat(playerName) local guy = getPlayerFromName( playerName ); local x, y, z = getElementPosition ( guy ) local r = getPedRotation ( guy ) vehicle = createVehicle ( 601, x, y, z, 0, 0, r ) warpPedIntoVehicle ( guy, vehicle ) outputChatBox("S.W.A.T spawned!", guy, 0, 255, 0) end addEventHandler ( "spawnSWAT", getRootElement(), carSwat ) Link to comment
Moderators Citizen Posted March 8, 2011 Moderators Share Posted March 8, 2011 Sorry but what are you trying to do ? Why you put another part of your script ? Link to comment
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 erroors serverside function greetingHandler ( message ) account = getPlayerAccount(thePlayer) local cash = getElementData ( account, "data.cash" ) local deaths = getElementData ( account, "data.deaths" ) local adminlevel = getElementData ( account, "data.adminlevel" ) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", getRootElement(), greetingHandler ) clientside function greetingCommand ( sourcePlayer,cmd,who,amount ) triggerServerEvent ( "onGreeting", getLocalPlayer(), "Hello World!" ) account = getPlayerAccount(sourcePlayer) if not isGuestAccount ( getPlayerAccount ( sourcePlayer ) ) then outputChatBox ( "Money: ".. tostring( cash ) , sourcePlayer ) outputChatBox ( "Deaths: ".. tostring( deaths ), sourcePlayer ) outputChatBox ( "Adminlevel: ".. tostring( adminlevel ), sourcePlayer ) end end addCommandHandler ( "greet", greetingCommand ) [2011-03-09 16:39:03] WARNING: testmode\server.lua:146: Bad argument @ 'getPlayerAccount' [2011-03-09 16:39:03] WARNING: testmode\server.lua:147: Bad argument @ 'getElementData' [2011-03-09 16:39:03] WARNING: testmode\server.lua:148: Bad argument @ 'getElementData' [2011-03-09 16:39:03] WARNING: testmode\server.lua:149: Bad argument @ 'getElementData' Link to comment
proracer Posted March 9, 2011 Share Posted March 9, 2011 You are again using functions: getPlayerAccount and isGuestAccount which only work for serverside. Btw, can you tell again what are trying to achieve? Link to comment
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 I'm trying to make /stats now /greet So I can see my stats in client side. If that works I can go futther and use it for GUI Could you please fix it the right way? Link to comment
Wojak Posted March 9, 2011 Share Posted March 9, 2011 Could you please fix it the right way? There is nothing to fix in your's code - it is a random copying from the wiki. One can only rewrite it using some logic... The goal is to "ask the server for accountData" serverside function greetingHandler ( ) account = getPlayerAccount(source) if not isGuestAccount (account ) then local cash = getAccountData ( account, "data.cash" ) local deaths = getAccountData ( account, "data.deaths" ) local adminlevel = getAccountData ( account, "data.adminlevel" ) triggerClientEvent(source,"SendAccountData",source,cash,deaths,adminlevel) end end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", getRootElement(), greetingHandler ) clientside function greetingCommand ( ) triggerServerEvent ( "onGreeting", getLocalPlayer()) end addCommandHandler ( "greet", greetingCommand ) addEvent( "SendAccountData", true ) addEventHandler( "SendAccountData", getRootElement(), function(cash,deaths,adminlevel) outputChatBox ( "Money: ".. tostring( cash ) ) outputChatBox ( "Deaths: ".. tostring( deaths) ) outputChatBox ( "Adminlevel: ".. tostring( adminlevel ) ) end) Link to comment
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 Ah great it works. Now I understand it Thankyou very much Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now