Jump to content

Creating/Removing objects ClientSide


Recommended Posts

Posted

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

Posted

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 ;)

Posted
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

Posted

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 .

Posted
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

Posted
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

Posted
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

Posted
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 

Posted

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

Posted
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 

Posted

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!

Posted

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 ;)

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