hemen Posted August 18, 2010 Posted August 18, 2010 How to get the variable from server-side script in client-side, or from server-side script in client-side? Are there some functions, besides getElementData?
Dark Dragon Posted August 18, 2010 Posted August 18, 2010 Another way would be to transfer them using events, but setting the element data is fine too. Loads of fun for free! Also a lot of fun for free!
dzek (varez) Posted August 18, 2010 Posted August 18, 2010 events are better anyway - cause it's easier to make an action after sending values ie. from server to client. i know about onClientElementDataChange - but it's more complicated i think Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
hemen Posted August 19, 2010 Author Posted August 19, 2010 I created function, which receive and return value of variable. --Client-side script. function getvar1(varname,number) triggerServerEvent("getvar1",getRootElement(),gMe,varname,number) return getElementData(gMe,"variable") end --Server-side script. function getvar1 (player,varname,number) local var = " " if varname == "name" then var = GangInfo.Name[number] elseif varname == "leader" then var = GangInfo.Leader[number] end setElementData(player,"variable",var) end addEvent( "getvar1", true ) addEventHandler( "getvar1", getRootElement(), getvar1 ) But it's need to wait some value of milliseconds up to starting next function. Example: --Client-side outputChatBox(""..getvar1("name",gangid).."") Script doesn't writes value of variable, because there are interval from receiving value of variable to writing of message. How it can be fixed?
dzek (varez) Posted August 19, 2010 Posted August 19, 2010 i suggest not to use setElementData. triggerServerEvent, and after doing some actions triggerClientEvent back. waiting some ms in unreliable - sometimes server/client can get a lag.. Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
hemen Posted August 19, 2010 Author Posted August 19, 2010 i suggest not to use setElementData.triggerServerEvent, and after doing some actions triggerClientEvent back. waiting some ms in unreliable - sometimes server/client can get a lag.. But what can i do, if triggerServerEvent and triggerClientEvent doesn't return a value of variable?
dzek (varez) Posted August 19, 2010 Posted August 19, 2010 i dont understand what you mean Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
hemen Posted August 19, 2010 Author Posted August 19, 2010 I'm sorry, i speak english very bad. I'll answer the question in the different way. How recieve* a value of server-side script's variable by (with ?) function triggerServerEvent?
dzek (varez) Posted August 19, 2010 Posted August 19, 2010 -- sending value from client to server, and back to client --[[ CLIENT SIDE SCRIPT ]]-- addEvent("sendToClient", true) addEventHandler("sendToClient", getRootElement(), function(var1) outputChatBox("got variable from server: ".. var1) end) myVar = "hello world!" triggerServerEvent("sendToServer", getLocalPlayer(), myVar) --[[ SERVER SIDE SCRIPT ]]-- addEvent("sendToServer", true) addEventHandler("sendToServer", getRootElement(), function(var1) varToSend = var1.." server says hello too!" triggerClientEvent(source, "sendToClient", source, varToSend) end) try this script, look on wiki pages for triggerServerEvent and triggerClientEvent (click on them in script above) I'm sure you will understand it Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
hemen Posted August 19, 2010 Author Posted August 19, 2010 I understood only that this function concentrates on itself, there is a recursion. I didn't understand, when did this function started from. I need only in function, which receive values of variables from server-side to client-side.
50p Posted August 19, 2010 Posted August 19, 2010 @hemen You can't simply have a function which returns a server-side variable in client-side script, or the other way around... You have to trigger events back and forth. - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
dzek (varez) Posted August 19, 2010 Posted August 19, 2010 there is NO recursion in my example.. Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
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