evox91 Posted May 29, 2012 Share Posted May 29, 2012 Hi, How can i share a variable from server to client ? i tried this code but fail --serverside local info ="string" function displayLoadedRes ( thePlayer ) setElementData ( thePlayer, "m", info ) end addEventHandler ( "onResourceStart", getRootElement(), displayLoadedRes ) --clientside function xy() outputChatBox ( getElementData( getLocalPlayer(), "m" )) end thx for help Link to comment
Castillo Posted May 29, 2012 Share Posted May 29, 2012 onResourceStart has no "player" argument. --server side: local info ="string" function displayLoadedRes ( ) for index, player in ipairs ( getElementsByType ( "player" ) ) do setElementData ( player, "m", info ) end end addEventHandler ( "onResourceStart", resourceRoot, displayLoadedRes ) -- client side: function xy ( ) outputChatBox ( getElementData ( localPlayer, "m" ) ) end Link to comment
elf23 Posted May 29, 2012 Share Posted May 29, 2012 -- another way --server; local info = "string" triggerServerEvent("someEvent",root,info) --client; addEvent("someEvent",true) function share(info) outputChatBox(info) end addEventHandler("someEvent",root,share) Link to comment
Castillo Posted May 29, 2012 Share Posted May 29, 2012 No, because the client won't have the script downloaded yet, so it'll output that the event is not added client side. Link to comment
Castillo Posted May 29, 2012 Share Posted May 29, 2012 It'll work fine some times, then it'll start doing what I said. Link to comment
evox91 Posted May 29, 2012 Author Share Posted May 29, 2012 sorry but none work for me Link to comment
Castillo Posted May 29, 2012 Share Posted May 29, 2012 Of course the element data won't update when you change the variable. Link to comment
evox91 Posted May 29, 2012 Author Share Posted May 29, 2012 i call the function with simple keybind,and i not changed. but i try now in empty sript Link to comment
evox91 Posted May 29, 2012 Author Share Posted May 29, 2012 ok in empty script the first solution is working but when i put in my gamemode then not work Link to comment
evox91 Posted May 29, 2012 Author Share Posted May 29, 2012 tahnks for help,now working Link to comment
evox91 Posted May 30, 2012 Author Share Posted May 30, 2012 Sorry for lot of nuub questions, but this is important for me: This is full server code ,and when a new player connecting to server got error, but when i restart the script from adminpanel then working good,but when again joinning a player fail I tried modyfy the event ,but other event also got error How can sync the variables without error ? --full server code(the client codes are good) addEventHandler ( "onResourceStart", resourceRoot, displayLoadedRes ) function refresh() for index, player in ipairs ( getElementsByType ( "player" ) ) do setElementData ( player, "m", exports.exp_system:getPlayerLevel ( player) ) setElementData ( player, "m1", exports.exp_system:getPlayerEXP ( player) ) local x,y,z =getElementPosition ( player ) setElementData ( player, "m2", getZoneName(x,y,z,false) ) local playerAccount = getPlayerAccount(player) if isGuestAccount ( playerAccount ) then setElementData ( player, "m3", "logged" ) else setElementData ( player, "m3", "not logged" ) end setElementData ( player, "m4",exports.bank:getBankAccountBalance( player) ) setElementData ( player, "m5",exports.house_system:gethouseccount( playerAccount) ) outputChatBox (exports.house_system:gethouseccount( playerAccount) ) end end function displayLoadedRes ( ) setTimer ( refresh, 1000, 100) end Very thanks for help,this is my last question ! Link to comment
elf23 Posted May 30, 2012 Share Posted May 30, 2012 use onPlayerJoin or onPlayerLogin event... Link to comment
evox91 Posted May 30, 2012 Author Share Posted May 30, 2012 thats ok,but i use the variables ind gui, this is client code: local vm ="" local vm2="" local vm3="" local vm4="" local vm5="" local vm6="" function cw() GUIEditor_Window = {} GUIEditor_TabPanel = {} GUIEditor_Tab = {} GUIEditor_Memo = {} GUIEditor_Label = {} GUIEditor_Window[1] = guiCreateWindow(179,118,691,542,"Server ver- 0.1.1",false) GUIEditor_TabPanel[1] = guiCreateTabPanel(17,27,658,506,false,GUIEditor_Window[1]) GUIEditor_Tab[1] = guiCreateTab("Főoldal",GUIEditor_TabPanel[1]) GUIEditor_Label[1] = guiCreateLabel(13,16,600,69,"Jelenlegi szint: ".. vm,false,GUIEditor_Tab[1]) guiSetFont(GUIEditor_Label[1],"sa-header") GUIEditor_Label[2] = guiCreateLabel(13,81,196,45,"Jelenlegi élménypont: ".. vm2,false,GUIEditor_Tab[1]) guiSetFont(GUIEditor_Label[2],"default-bold-small") GUIEditor_Label[3] = guiCreateLabel(14,117,185,43,"Következő szinthez:",false,GUIEditor_Tab[1]) GUIEditor_Label[4] = guiCreateLabel(13,152,220,26,"Be vagy jelentkezve:".. vm3 ,false,GUIEditor_Tab[1]) GUIEditor_Label[5] = guiCreateLabel(13,189,131,28,"Banki összeg:" ..vm4 ,false,GUIEditor_Tab[1]) GUIEditor_Label[6] = guiCreateLabel(11,228,240,30,"Birtokolt házak:" .. vm5,false,GUIEditor_Tab[1]) GUIEditor_Label[7] = guiCreateLabel(6,269,216,41,"Játékos tulajdonságok:",false,GUIEditor_Tab[1]) guiSetAlpha(GUIEditor_Label[7],1) guiLabelSetColor(GUIEditor_Label[7],0,255,0) GUIEditor_Label[8] = guiCreateLabel(44,311,322,35,"Jelenlegi pénz: getPlayerMoney()",false,GUIEditor_Tab[1]) guiLabelSetColor(GUIEditor_Label[8],255,255,0) GUIEditor_Label[9] = guiCreateLabel(44,346,199,26,"Jelenlegi hely: "..vm6 ,false,GUIEditor_Tab[1]) guiLabelSetColor(GUIEditor_Label[9],250,240,230) GUIEditor_Label[10] = guiCreateLabel(44,382,198,27,"Körözöttségi szint: getPlayerWantedLevel()",false,GUIEditor_Tab[1]) guiLabelSetColor(GUIEditor_Label[10],255,0,0) GUIEditor_Tab[2] = guiCreateTab("A szerver bemutatása",GUIEditor_TabPanel[1]) GUIEditor_Memo[1] = guiCreateMemo(4,7,653,467,"\n majd szerver bemutatása",false,GUIEditor_Tab[2]) GUIEditor_Tab[3] = guiCreateTab("Fejlődési szintek",GUIEditor_TabPanel[1]) GUIEditor_Memo[2] = guiCreateMemo(5,9,646,466,"",false,GUIEditor_Tab[3]) GUIEditor_Tab[4] = guiCreateTab("Használható parancsok,funkciók",GUIEditor_TabPanel[1]) GUIEditor_Memo[3] = guiCreateMemo(4,10,647,462,"",false,GUIEditor_Tab[4]) GUIEditor_Tab[5] = guiCreateTab("Szabályok",GUIEditor_TabPanel[1]) GUIEditor_Memo[4] = guiCreateMemo(6,6,644,467,"",false,GUIEditor_Tab[5]) GUIEditor_Tab[6] = guiCreateTab("Admilista",GUIEditor_TabPanel[1]) GUIEditor_Memo[5] = guiCreateMemo(4,7,649,469,"",false,GUIEditor_Tab[6]) guiSetVisible(GUIEditor_Window[1],false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() cw() bindKey('f1', 'down', servermessage) end ) function servermessage() if(guiGetVisible(GUIEditor_Window[1])==true) then guiSetVisible(GUIEditor_Window[1],false) showCursor(false) else guiSetVisible(GUIEditor_Window[1],true) showCursor(true) end end function remotePlayerJoin() cw() vm=getElementData( getLocalPlayer(), "m" ) vm2=getElementData( getLocalPlayer(), "m1" ) vm3=getElementData( getLocalPlayer(), "m3" ) vm4=getElementData( getLocalPlayer(), "m4" ) vm5=getElementData( getLocalPlayer(), "m5" ) vm6=getElementData( getLocalPlayer(), "m2" ) end addEventHandler("onClientPlayerJoin", getRootElement(), remotePlayerJoin) Link to comment
evox91 Posted May 30, 2012 Author Share Posted May 30, 2012 i want refresh the gui text but now ,not changed Link to comment
evox91 Posted May 30, 2012 Author Share Posted May 30, 2012 ok i solved with guiSetText 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