DarkLink Posted June 3, 2012 Share Posted June 3, 2012 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
CapY Posted June 3, 2012 Share Posted June 3, 2012 Just create the object server side. Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 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
TwiX! Posted June 3, 2012 Share Posted June 3, 2012 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
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 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
Castillo Posted June 3, 2012 Share Posted June 3, 2012 The table send should be ok, although you don't tell us how your table works. Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 The table send should be ok, although you don't tell us how your table works. thanks for ur reply what do u mean mate? its a table of objects of GTA World, model 1418 Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 I mean how you insert the objects into the table. Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 I am using, table.insert(woodTable, wood) . and sometimes , when I need to add to a specific index, table.insert(woodTable, k, wood) Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 You can't do that, if you insert "k" and "wood", then in client side "wood" will be a index, not an element. Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 There is no nil values on a table right ? since when I remove using table.remove(woodTable, k) , its removes the element on k index, and the element that says on k index is the element that was on k+1 index... right ? I read that here : http://lua-users.org/wiki/TablesTutorial thanks alot Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 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
Castillo Posted June 3, 2012 Share Posted June 3, 2012 Sorry, forget about what I said. Debug your script client side, see what "wood" returns. Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 Sorry, forget about what I said.Debug your script client side, see what "wood" returns. No problem mate, thanks anyway, can you say me how I can debug that ? how to do it ? thanks in advance Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 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
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 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 sometimes works, other times dont Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 Well, what you can do is check if it's a valid element. Link to comment
DarkLink Posted June 3, 2012 Author Share Posted June 3, 2012 Well, what you can do is check if it's a valid element. How I make that check ? sorry for so many questions.. thanks. Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 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
DarkLink Posted June 4, 2012 Author Share Posted June 4, 2012 The problem continues.. 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... Thanks in advance! Link to comment
DarkLink Posted June 4, 2012 Author Share Posted June 4, 2012 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
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