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

357ac0078264.jpg

- Working on [php/HTML/Mysql/Lua/Java Scripts/Web Design/3D Modeling]

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.

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

I mean how you insert the objects into the table.

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

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

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

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

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

Well, what you can do is check if it's a valid element.

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

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

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!

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