Jump to content

have problem when send string from server to clients


cocowen

Recommended Posts

in my serverside

  
function getItemDes( itemid ) 
    --outputDebugString ( "[DEBUG]getItemDes", 3 ) 
    if ( type( itemid ) == "number" ) then 
        --outputDebugString ( "[DEBUG]getItemDes is number", 3 ) 
        if ( itemid > 0 ) then 
            outputDebugString ( "[DEBUG]getItemDes ="..tostring(items[itemid].itemdes), 3 ) 
            return items[itemid].itemdes 
        end 
    else 
        return MISSING_ARGUMENTS 
    end 
end 
  
addEvent("getItemDes", true) 
addEventHandler("getItemDes", _root, getItemDes) 
  

my clientside

  
  
ItemsInfo = triggerServerEvent("getItemDes", _root,itemid) 
  
  

i want to update the item's name from server to client

but the string send from server , and what i get on client is a boolen , not a string value

am i right?or what's the problem ? thx

Link to comment
if ( type( itemid ) == "number" ) then 

but the string send from server , and what i get on client is a boolen , not a string value

You check here if your variable number.

Can you show full function where you trigger event getItemDes.

P.S use

[lua][/lua] 

Link to comment

thanks for your replay

  
outputDebugString ( "[DEBUG]getItemDes ="..tostring(items[itemid].itemdes), 3 ) 
  

this step have print the correct item id (number)

and what the client code is here

  
function draw3DOverlay() 
    if ( type ( selectedIndex ) == "number" ) then 
        if ( myItems[selectedIndex] ~= nil ) then 
             
            if ( alpha < 200 ) then 
                alpha = alpha + 4 
            else 
                alpha = 200 
            end 
  
            if ( windowAlpha < 180 ) then 
                windowAlpha = windowAlpha + 3 
            else 
                windowAlpha = 180 
            end 
  
            local itemid = myItems[selectedIndex].itemid  -- this step have get the id  
            outputChatBox ( tostring(itemid) ) 
  
  
            ItemDes = triggerServerEvent("getItemDes", _root ,itemid) 
            outputChatBox ( tostring(ItemsInfo[itemid].itemname) )  -- get boolen here , but i need string 
  
  
            local image = dxDrawImage(getX(45.5), getY(28.5), 64, 64, "images/1.png", 0, 0, 0, tocolor( 255, 255, 255, alpha ) ) 
        end 
    end 
end 
  

Link to comment

just a quick reply.. sorry :mrgreen:

u shouldnt use triggerServerEvent in onClientRender, that would be too extreme... update the data in a function on a timer to update it every second or two if u need it that often.

also, u will need 2 triggers 1 server and 1 client, because: ItemDes = triggerServerEvent("getItemDes", _root ,itemid)

will return true/false if it was triggered, it cant be used to retrieve data, for this u need to request the info with your first trigger, then once it triggers that function, to trigger back to the client with the itemid.

so something like:

client:

  
triggerServerEvent("requestItemUpdate",getRootElement(),getLocalPlayer()) -- use this to request the data 
  
addEvent("receiveItemUpdate,true") 
function receiveUpdate(itemID) 
  --update variable here 
end 
addEventHandler("receiveItemUpdate",getRootElement(),receiveUpdate) 
  

server:

  
addEvent("requestItemUpdate",true) 
function requestUpdate() 
  triggerClientEvent(source,"receiveItemUpdate",source,itemID) 
end 
  

there are other ways too, u could also use setElementData(....

then retrieve it clientside with getElementData(...

sorry i dont have time to write it for u... dinner break (im sure kenix will help u out :) )

Link to comment

Thank you guys , Kenix and Scooby

u guys just make this clear

and i finaly find a way : when player login , ask the server to send the data to client( :D i also have thought the ideal of scooby mentioned , and trigger twice make me think maybe there are better way)

and i noctice that to do it when render is really a bad ideal

thank you,too ! :lol:

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