Jump to content

(Duda) Borrar un objeto creado


lucascba

Recommended Posts

Hola, estoy haciendo un sistema de sombreros, bueno el sistema consiste en que el jugador elija su sombrero, cuando se lo coloca se crea un objeto del lado del server para que todos vean, cuando el jugador elige otro objeto el que tenia se elimina y se crea el nuevo, pero el problema es que cuando otro jugador crea otro objeto se elimina el objeto del otro jugador, como puedo hacer para que no pase? Gracias.

Link to comment

ok..

Server:

function hatsserver (Modelo,escala,xH,yH,aL,rz) 
local x, y, z = getElementPosition(source) 
  
hat = createObject(model, x, y, z, 0, 0, rz) 
setObjectScale ( hat, escala) 
exports.bone_attach:attachElementToBone(hat,source,1,xH,yH,aL,0, 0, rz) 
end 
addEvent ("PonerElSombrero", true) 
addEventHandler ("PonerElSombrero", getRootElement(), hatsserver) 
  
function sacarhat (elplayer) 
if elplayer then 
if ( isElement ( hat ) ) then 
        destroyElement ( hat ) 
end 
end 
end 
addEvent ("sacarHat", true) 
addEventHandler ("sacarHat", getRootElement(), sacarhat) 
  

Client:

    local hRow = nil 
  
    VipSombreros = guiCreateWindow(0.37, 0.19, 0.24, 0.52, "CL ~ Sombreros VIP", true) 
        guiWindowSetSizable(VipSombreros, false) 
  
        hGrid = guiCreateGridList(10, 23, 311, 319, false, VipSombreros) 
        guiGridListAddColumn(hGrid, "Sombreros", 0.9) 
        botonponer = guiCreateButton(10, 353, 91, 39, "Aplicar", false, VipSombreros) 
        guiSetProperty(botonponer, "NormalTextColour", "FFAAAAAA") 
        SacarHat = guiCreateButton(121, 353, 91, 39, "Remover Sombrero", false, VipSombreros) 
        guiSetProperty(SacarHat, "NormalTextColour", "FFAAAAAA") 
        cerrarH = guiCreateButton(231, 352, 90, 41, "Cerrar", false, VipSombreros) 
        guiSetProperty(cerrarH, "NormalTextColour", "FFAAAAAA") 
    guiSetVisible(VipSombreros,false) 
    showCursor(false) 
  
    local SombrerosT = 
    { 
        { "Roulete", 1895,escala=0.3 }, 
        { "Mask skull", 6865,escala=0.09  }, 
        { "Ventilator", 1661,escala=0.7 }, 
        { "skull", 1736 }, 
        { "TV", 1518,escala=0.7}, 
        { "Arrow", 1318,escala=0.9 }, 
        { "Tree", 811,escala=0.3 }, 
        { "WW1 hat", 2052 }, 
        { "WW2 hat", 2053 }, 
        { "Captain 3", 2054,rz=90 }, 
        {"Turtle",1609,escala=0.2}, 
        {"Torch",3461,escala=0.5,rz=90}, 
        {"Mikey",2485,escala=1,rz=0}, 
        }; 
  
    for i,m_obj in ipairs( SombrerosT ) do 
  
            hRow = guiGridListAddRow( hGrid ); 
            -- 
            guiGridListSetItemText ( hGrid, hRow, 1, tostring( m_obj [ 1 ] ), false, false ); 
            if m_obj [ 2 ] then guiGridListSetItemData ( hGrid, hRow, 1, tostring( m_obj [ 2 ] ) ) end 
  
    end 
  
function poner ( ) 
    local row, col = guiGridListGetSelectedItem ( hGrid ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local Modelo = tonumber ( guiGridListGetItemData ( hGrid, row, 1 ) ) 
        local escala=1 
        local rz=0 
        local Nombre = "" 
        for k,v in pairs(SombrerosT) do 
            if v[2] == Modelo then 
                Nombre=v[1] 
                rz=v[3] 
                if v.escala ~= nil then escala=v.escala break end 
                if v.rz ~= nil then rz=v.rz break end 
            end 
        end 
        if Modelo ~= nil then 
            exports.UIPtexts:output("Te has colocado el sombrero '"..Nombre.."'",0,255,0) 
        end 
        rz = 180 
        xH,yH,aL = 0, 0, 0 
        if (Nombre == "Mask skull") then 
           rz = 230 
           xH,yH,aL = xH,yH,aL+0.07 
        end    
        if (Nombre == "Mikey") then 
           rz = 90 
           xH,yH,aL = xH,yH,aL+0.07 
        end   
  
        if (Nombre == "Ventilator") then 
           rz = 180 
           xH,yH,aL = xH,yH,aL+0.2 
        end 
         
        if (Nombre == "skull") then 
           rz = 180 
           xH,yH,aL = xH,yH,aL+0.1 
        end 
         
        if (Nombre == "Arrow") then 
           rz = 90 
           xH,yH,aL = xH,yH,aL+0.6 
        end 
         
        if (Nombre == "Tree") then 
           rz = 180 
           xH,yH,aL = xH,yH,aL+0.4 
        end 
        if (Nombre == "WW1 hat") then 
           rz = 90 
           xH,yH,aL = xH,yH,aL+0.01 
        end 
         
        if (Nombre == "WW2 hat") then 
           rz = 180 
           xH,yH,aL = xH+0.02,yH+0.03,aL+0.1 
        end 
         
        if (Nombre == "Captain 3") then 
           rz = 180 
           xH,yH,aL = xH,yH+0.02,aL+0.1  
        end 
         
        if (Nombre == "Turtle") then 
           rz = 180 
           xH,yH,aL = xH,yH,aL+0.2 
        end 
        sacarhat1 () 
        triggerServerEvent("PonerElSombrero",localPlayer,Modelo,escala,xH,yH,aL,rz) 
         
  
    end 
  
end 
addEventHandler ( "onClientGUIClick", botonponer, poner, false ) 
  
  
function mostratGui() 
    local VIP = getElementData(localPlayer,"VIP") 
    if VIP == "Si" then 
    if guiGetVisible(VipSombreros) then 
        guiSetVisible(VipSombreros, false) 
        showCursor(false) 
    elseif  VIP == "Si" then 
        guiSetVisible(VipSombreros, true) 
        showCursor(true) 
    end 
    end 
end 
addCommandHandler("sombreros",mostratGui,false) 
  
addEventHandler("onClientGUIClick", cerrarH, mostratGui,false) 
  
function sacarhat1 () 
local elplayer = getLocalPlayer() 
triggerServerEvent("sacarHat",localPlayer, elplayer) 
end 
addEventHandler("onClientGUIClick", SacarHat, sacarhat1,false) 

Link to comment

No hice comprobación alguna, así que, por favor, avísame en caso de cualquier error:

local hat = {} 
  
function hatsserver (Modelo,escala,xH,yH,aL,rz) 
local x, y, z = getElementPosition(source) 
hat[source] = createObject(Modelo, x, y, z, 0, 0, rz) --Tengo ciertas dudas respecto a la variable 'Modelo'. 
setObjectScale ( hat[source], escala) 
exports.bone_attach:attachElementToBone(hat[source],source,1,xH,yH,aL,0, 0, rz) 
end 
addEvent ("PonerElSombrero", true) 
addEventHandler ("PonerElSombrero", getRootElement(), hatsserver) 
  
function sacarhat (elplayer) 
if elplayer and hat[elplayer] then 
if ( isElement ( hat[elplayer] ) ) then 
        destroyElement ( hat[elplayer] ) 
end 
end 
end 
addEvent ("sacarHat", true) 
addEventHandler ("sacarHat", getRootElement(), sacarhat) 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...