Jump to content

[HELP2] Delete all function


squar

Recommended Posts

function createWorldObject ( thePlayer,objectID,objectPosX,objectPosY,objectPosZ) 
    local rx,ry,rz = getElementRotation ( source ) 
    obj = createObject(thePlayer,objectID,objectPosX,objectPosY,objectPosZ) 
    setElementDoubleSided (obj,true) 
    setElementRotation(obj,rx,ry,rz) 
  
function removeAllObjects () 
    for k,v in ipairs(getElementsByType ( "object", getResourceRootElement(getThisResource()))) do 
          destroyElement (v) 
     end  
end 
addEvent("onRemoveAll",true) 
addEventHandler("onRemoveAll",root,removeAllObjects) 

This script almost works perfectly. When I press the remove all button in my gui, it deletes the objects other player has placed as well. I was wondering how to fix it like when a player hits the delete all button, it deletes the object he has placed only. A hint would be great :)

Link to comment

Use a table.

Let us say as an example we are using a table named playerObjects

playerObjects = {} 
function createWorldObject ( thePlayer,objectID,objectPosX,objectPosY,objectPosZ) 
    local rx,ry,rz = getElementRotation ( source ) 
    obj = createObject(thePlayer,objectID,objectPosX,objectPosY,objectPosZ) 
    setElementDoubleSided (obj,true) 
    setElementRotation(obj,rx,ry,rz) 
    if not playerObjects[thePlayer] then playerObjects[thePlayer] = {} end 
    table.insert(playerObjects[thePlayer], obj) 
  
function removeAllObjects (thePlayer) -- You need to send an argument to here including the player element. 
if playerObjects[thePlayer] then 
    for k,v in ipairs(playerObjects[thePlayer]) do 
          destroyElement (v) 
     end 
     playerObjects[thePlayer] = nil -- Clear the table for the roadblocks 
end 
end 
addEvent("onRemoveAll",true) 
addEventHandler("onRemoveAll",root,removeAllObjects) 
  

Should work good luck ;)

Your first functions misses an event to trigger from clientside and a end.

Link to comment

I got a table in the client side one. By the script i have, I can use the delete all function, but it deletes the ones other people has placed as well. Is it a way to make the server side one deleting the objects the PLAYER has placed, without having the table on the server side one?

Link to comment
I got a table in the client side one. By the script i have, I can use the delete all function, but it deletes the ones other people has placed as well. Is it a way to make the server side one deleting the objects the PLAYER has placed, without having the table on the server side one?

What are you using the table on the clientside for, and why not creating one at the serverside too?

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