Jump to content

variable between server and client


evox91

Recommended Posts

Posted

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

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

-- another way

  
--server; 
  
local info = "string" 
triggerServerEvent("someEvent",root,info) 
  
--client; 
  
addEvent("someEvent",true) 
function share(info) 
outputChatBox(info) 
end 
addEventHandler("someEvent",root,share) 
  

Posted

No, because the client won't have the script downloaded yet, so it'll output that the event is not added client side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

It'll work fine some times, then it'll start doing what I said.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Of course the element data won't update when you change the variable.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 :redhotevil:

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 !

Posted

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) 
  

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