Jump to content

Creating/Removing objects ClientSide


DarkLink

Recommended Posts

Hi there guys, I guess this one is easy for you to help me :)

I dont really know if I am doing it right.

Should I create and remove objects via client side ?

I mean all others clients will see that objects being created and removed ? its good sync ?

Or should I trigger some event on server side, and add and remove my objects there?

thanks alot in advance...

I really need a answer on this :)

Link to comment

Hm ok thanks, the problem is that I am doing some script.. where I can only create the object after I check something on client side (this check must be client side, not serverside, the name of function is : isLineOfSightClear) , so if check is ok, then I triggerServerEvent and then create there ? on server? is this the best way ?

by the way, can I pass as argument on triggerClientEvent a table of objects?

Thanks in advance ;)

Link to comment
Hm ok thanks, the problem is that I am doing some script.. where I can only create the object after I check something on client side (this check must be client side, not serverside, the name of function is : isLineOfSightClear) , so if check is ok, then I triggerServerEvent and then create there ? on server? is this the best way ?

by the way, can I pass as argument on triggerClientEvent a table of objects?

Thanks in advance ;)

yes you can

Link to comment

I dont know If I am doing the good way...

Can someone see this ?

server side:

  
local woodTable = {} 
  
function sendWoodTable() 
  
    outputChatBox("sending wood table for player that spawn") 
    triggerClientEvent ( source, "placeWoodsTable", source, woodTable ) 
     
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), sendWoodTable ) 
  
  

client side:

  
local woodTable = {} 
  
addEvent("placeWoodsTable", true) 
  
function createLine() 
     
    for k,wood in ipairs(woodTable) do  
         
        local xW, yW, zW = getElementPosition(wood)   -- I GET ERROR HERE... bad argument @ getElementPosition 
    end 
     
end 
  
  
 function placeWoodsFunc(woodTableReceived) 
    outputChatBox("received wood table , i guess..") 
    woodTable = woodTableReceived 
    addEventHandler("onClientRender", getRootElement(), createLine) 
     
 end 
 addEventHandler("placeWoodsTable", getRootElement(), placeWoodsFunc) 
  
  

can u guys see if there is something wrong ? sending this table ? thanks alot in advance guys .

Link to comment
You can't do that, if you insert "k" and "wood", then in client side "wood" will be a index, not an element.

I dont understand what u mean , using table.insert(woodTable, k, wood) is like insert wood on k index right ?

"We can also insert elements at a chosen point in the list. We can use the table library to insert elements into the table array without having to shuffle the other elements around. To do this we supply 3 arguments to the table.insert(table,position,value) function" from lua org

Link to comment
function createLine() 
    for k,wood in ipairs(woodTable) do 
        outputChatBox ( k ..": ".. tostring ( wood ) ) 
        local xW, yW, zW = getElementPosition(wood)   -- I GET ERROR HERE... bad argument @ getElementPosition 
    end 
end 

Link to comment

I already debug, and it goes though the table printing things like this :

110 : userdata 000002A9

111 : userdata 000002AA

112 : userdata 000002AB

113 : userdata 000002AC

...

so its everything okay ?

I dont understand :S sometimes works, other times dont :S

Link to comment
function createLine() 
    
    for k,wood in ipairs(woodTable) do 
        if ( wood and isElement ( wood ) ) then 
        local xW, yW, zW = getElementPosition(wood)   -- I GET ERROR HERE... bad argument @ getElementPosition 
        end 
    end 
    
end 

Link to comment

The problem continues.. :S

Look, I guess I am doing something wrong, I am trying to do this:

I have a table of objects on server and client side, the SAME objects.

When I remove on client, I trigger server event, to delete on the table of the server .

When I add on server, I trigger client event to add on the table of the client.

I idea is both tables have the same content, the same objects... but I think this is not very good syncronized... maybe there are better way to do this...

I need to do this because isLineOfSightClear only works on client... :S

Thanks in advance!

Link to comment

Anyone over here ? thanks in advance guys ...

EDIT:

Guys nevermind, I already get it working, using another paradigm. I mean I leaved the two tables (server and client side) solution, and implemented setElementData, and I dont need any tables being sent via triggers :)

Thanks alot all of you that helped ;)

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