Jump to content

Name objects with itemname + playername?


scaryface87

Recommended Posts

Hello,

I've made a script lately but i got a little problem.

If player1 uses the command /attachobject

the object will attach

If player2 uses it also it"ll works fine

But if player1 uses /removeobject then it removes the object of player2 not player1.

So my question is , is it possible to name the created object "object(playeraccount) ?

Sorry for bad english here is my script ;

#server side

  
function testFunct(playerSource) 
object = createObject(1238,0,0,0) 
setElementCollisionsEnabled(object,false) -- anti push abuse + camerafix with other objects 
attachElements(object,playerSource,0,1,0.2) 
end 
addCommandHandler("attach",testfunction) 
  
  
function testFunct(playerSource) 
object = createObject(1238,0,0,0) 
attachElements(object,playerSource,0,1,0.2) 
end 
addCommandHandler("attach",testFunct) 
  
function testother() 
detachElements(object,playerSource) 
end 
addCommandHandler("removeobJect",testother) 
  
  

Link to comment

That's because you're overwriting the same variable, object.

Player 1 runs the command, an object is created with the pointer object.

Player 2 runs the command, an object is created - but the pointer object already exists. It overwrites it.

Player 1 runs the command to delete the object, last created object is deleted. (In this case, the one made by Player 2)

You'll indeed need to use tables for this;

table.insert 
table.remove 

Link to comment

Hm i give it a try even tought i never used tables

So if im right its someting like this :

I have no clue how to use it

So if im right it can be somethign like this :

  
myTabel = {}   
function testFunc(playerSource) 
table.insert ( myTable, { "1238", 3, 2, 1 } )-- i dont get this but i tried 
  for i,v in ipairs ( myTabel ) do -- to get everything of the table... 
    local model = getElementModel(v[1]) 
    local object[i] = createObject ( model, tonumber([v2]), tonumber([v3]), tonumber([v4])) 
attachElements(object[i],playerSource,0,1,0.2) 
  end 
end 
addCommandHandler("attach",testFunct) 
  
  
function testother(playerSource) 
detachElements(object[i],playerSource) 
table.remove(myTable,) --- same unfinished but idk how to do this too 
end 
addCommandHandler("removeobJect",testother) 
  
  

Link to comment

Wrong. i will gave you an example:

local playerObjects = {} 
  
function testFunct(player) 
    if (isElement(playerObjects[player])) then 
        destroyElement(playerObjects[player]) 
    end 
    playerObjects[player] = createObject(1238,0,0,0) 
    setElementCollisionsEnabled(playerObjects[player],false)  
    attachElements(playerObjects[player],player,0,1,0.2) 
end 
addCommandHandler("attach",testfunction) 
  
  
function testother(player) 
    if (isElement(playerObjects[player])) then 
        destroyElement(playerObjects[player]) 
        playerObjects[player] = nil 
    end 
end 
addCommandHandler("removeobJect",testother) 

Link to comment

Hello ,

So i tought it would fix my actual script but it didnt.

So i've made a function to attach an object to myself (a cone) but if someone elses takes another cone and i do tries to remove the cone wen he clcks on it after doing command then it removes the latest created object created by a player i remove hes. its still not the actual code but its kind of the same & it should help.

  
-- server 
local playerObjects = {} 
  
function createCones()  
playerObjects[player] = createObject(1238,1042.91797,1024.59106,11.00000) 
-- playerObjects[player] = createObject(1238,1042,91797,1024,59106,12) -- i know this isnt going to work but i kindda want it to work 
end 
addCommandHandler("createCone",createCones) -- this gets triggered by something else but u can take it as a commandhandler 
  
function onPlayerClick(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
attachElements(playerObjects[player],player,0,1,0.2) --  attach clicked cone 
end 
addEvent("onPlayerClick",true) 
addEventHandler("onPlayerClick",getRootElement(),onPlayerClick) 
  
function onRemoveRequest(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
destroyElement(playerObjects[player]) -- to remove the clicked cone too 
end 
addEvent("onRemoveRequest",true) 
addEventHandler("onRemoveRequest",getRootElement(),onRemoveRequest) 
  
  
--- client --- 
  
function testCursor() 
 if isCursorShowing ( getLocalPlayer() ) then   
 showCursor(false) 
removeEventHandler("onClientClick",getRootElement(),clickHandler) 
 else 
 showCursor(true) 
addEventHandler("onClientClick",getRootElement(),clickHandler) 
 end 
end 
addCommandHandler("cursor",testCursor)     
  
function removeCursor() 
 if isCursorShowing ( getLocalPlayer() ) then   
 showCursor(false) 
removeEventHandler("onClientClick",getRootElement(),clickRemoveHandler) 
 else 
 showCursor(true) 
addEventHandler("onClientClick",getRootElement(),clickRemoveHandler) 
 end 
end 
addCommandHandler("removecursor",removeCursor)     
  
  
function clickHandler(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
if clickedElement then 
triggerServerEvent("onPlayerClick",resourceRoot,button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
end 
end 
  
  
function clickRemoveHandler(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
if clickedElement then 
triggerServerEvent("onRemoveRequest",resourceRoot,button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
end 
end 
addEventHandler("onClientClick",getRootElement(),clickRemoveHandler) 
  
  
  
  

Link to comment
Hello,

I've made a script lately but i got a little problem.

If player1 uses the command /attachobject

the object will attach

If player2 uses it also it"ll works fine

But if player1 uses /removeobject then it removes the object of player2 not player1.

So my question is , is it possible to name the created object "object(playeraccount) ?

Sorry for bad english here is my script ;

#server side

  
function testFunct(playerSource) 
object = createObject(1238,0,0,0) 
setElementCollisionsEnabled(object,false) -- anti push abuse + camerafix with other objects 
attachElements(object,playerSource,0,1,0.2) 
end 
addCommandHandler("attach",testfunction) 
  
  
function testFunct(playerSource) 
object = createObject(1238,0,0,0) 
attachElements(object,playerSource,0,1,0.2) 
end 
addCommandHandler("attach",testFunct) 
  
function testother() 
detachElements(object,playerSource) 
end 
addCommandHandler("removeobJect",testother) 
  
  

you want to do like this ?

ObbCheck = { } 
  
  
addCommandHandler ( "attach", function ( thePlayer, cmd, WhatPlaye, Objectid ) 
--local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) < [OPTIONL] 
-- if not ( isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Console" ) ) ) then return outputChatBox ( "#FF0000* INFO #000000: #FF0000 You Are Not Console !", thePlayer, 255, 0, 0, true ) end < [OPTIONL] 
GetPnaam = getPlayerFromName ( WhatPlaye ) 
 if ( isElement ( ObbCheck [ GetPnaam ] ) ) then 
  destroyElement ( ObbCheck [ GetPnaam ] ) 
end 
 if ( ( WhatPlaye ) and ( tonumber ( Objectid ) ) ) then 
   if ( isElement ( GetPnaam ) ) then 
    local xp, yp, zp = getElementPosition ( GetPnaam ) 
     ObbCheck [ GetPnaam ] = createObject ( Objectid, xp, yp, zp ) 
      setElementAlpha ( GetPnaam, 0 ) 
      setElementCollisionsEnabled( ObbCheck [ GetPnaam ], false ) 
     attachElements ( ObbCheck [ GetPnaam ], GetPnaam ) 
    outputChatBox ( "#00FF00* INFO #000000: #FF0000 DONE To Make [ #0000FF" .. getPlayerName ( GetPnaam ) .. " #FF0000] Object", thePlayer, 255, 0, 0, true ) 
   else 
    outputChatBox ( "#FF0000* INFO #000000: #FF0000 This Player [ #0000FF" .. WhatPlaye .. " #FF0000] Not Found", thePlayer, 255, 0, 0, true ) 
   end 
  else 
   outputChatBox ( "#FF0000* INFO #000000: #FF0000 Error In The Syntax #FF0000 [#00FF00 /Tobject < PlayerName > < ObjectID > #FF0000]", thePlayer, 255, 0, 0, true ) 
  end 
 end ) 
  
addCommandHandler ( "removeobJect", function ( thePlayer, cmd, WhatPlaye ) 
 --local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) < [OPTIONL] 
  --if ( isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Console" ) ) ) then < [OPTIONL] 
   if ( isElement ( ObbCheck [ GetPnaam ] ) ) then 
    destroyElement ( ObbCheck [ GetPnaam ] ) 
     setElementAlpha ( GetPnaam, 255 ) 
      outputChatBox ( "#00FF00* INFO #000000: #00FF00 DONE !", thePlayer, 255, 0, 0, true ) 
     else 
      outputChatBox ( "#FF0000* INFO #000000: #FF0000 This Player Is Already Not object", thePlayer, 255, 0, 0, true ) 
     end 
    else 
     outputChatBox ( "#FF0000* INFO #000000: #FF0000 You Are Not Console !", thePlayer, 255, 0, 0, true ) 
  --end < [OPTIONL] 
end ) 
  
addEventHandler ( "onPlayerQuit", resourceRoot, function (  ) 
 if ( isElement ( ObbCheck [ GetPnaam ] ) ) then 
  destroyElement ( ObbCheck [ GetPnaam ] ) 
 end 
end ) 
Link to comment
Hello ,

So i tought it would fix my actual script but it didnt.

So i've made a function to attach an object to myself (a cone) but if someone elses takes another cone and i do tries to remove the cone wen he clcks on it after doing command then it removes the latest created object created by a player i remove hes. its still not the actual code but its kind of the same & it should help.

  
-- server 
local playerObjects = {} 
  
function createCones()  
playerObjects[player] = createObject(1238,1042.91797,1024.59106,11.00000) 
-- playerObjects[player] = createObject(1238,1042,91797,1024,59106,12) -- i know this isnt going to work but i kindda want it to work 
end 
addCommandHandler("createCone",createCones) -- this gets triggered by something else but u can take it as a commandhandler 
  
function onPlayerClick(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
attachElements(playerObjects[player],player,0,1,0.2) --  attach clicked cone 
end 
addEvent("onPlayerClick",true) 
addEventHandler("onPlayerClick",getRootElement(),onPlayerClick) 
  
function onRemoveRequest(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
destroyElement(playerObjects[player]) -- to remove the clicked cone too 
end 
addEvent("onRemoveRequest",true) 
addEventHandler("onRemoveRequest",getRootElement(),onRemoveRequest) 
  
  
--- client --- 
  
function testCursor() 
 if isCursorShowing ( getLocalPlayer() ) then   
 showCursor(false) 
removeEventHandler("onClientClick",getRootElement(),clickHandler) 
 else 
 showCursor(true) 
addEventHandler("onClientClick",getRootElement(),clickHandler) 
 end 
end 
addCommandHandler("cursor",testCursor)     
  
function removeCursor() 
 if isCursorShowing ( getLocalPlayer() ) then   
 showCursor(false) 
removeEventHandler("onClientClick",getRootElement(),clickRemoveHandler) 
 else 
 showCursor(true) 
addEventHandler("onClientClick",getRootElement(),clickRemoveHandler) 
 end 
end 
addCommandHandler("removecursor",removeCursor)     
  
  
function clickHandler(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
if clickedElement then 
triggerServerEvent("onPlayerClick",resourceRoot,button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
end 
end 
  
  
function clickRemoveHandler(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
if clickedElement then 
triggerServerEvent("onRemoveRequest",resourceRoot,button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
end 
end 
addEventHandler("onClientClick",getRootElement(),clickRemoveHandler) 
  
  
  
  

sorry if i'am late but that example when u clicked the object you attached with it

Chk = true 
Objj = createObject ( 980, -2415.6787109375, -600.8818359375, 132.5625 + 6, 0, 0, 0 ); 
  
  
addEventHandler ( "onElementClicked", resourceRoot, function ( theButton, theState, plr ) 
        if ( theButton == "left" and theState == "down" ) then 
            if ( source == Objj ) then 
        attachElements ( Objj, plr ); 
            setElementAlpha ( plr, 0 ); 
        showCursor ( plr, false ); 
        end 
    end 
end ); 
  
addCommandHandler ( "Scursour", function ( plr ) 
showCursor ( plr, Chk ) 
    Chk = not Chk 
end ); 
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...