Jump to content

Ayudenme con esto.


xXALeXx

Recommended Posts

Mi intención con este script es que al poner el comando /tirararma, automáticamente salga una animación con un /me exportado de otro resource y que esta arma se vea en el suelo y desaparezca de la mano. Cuando lo inicio, solamente me sale la animación, el /me y desaparece el arma pero no se ve en el suelo, lo que tengo es lo siguiente:

servidor:

id = {} 
id[1] = 331 
id[2] = 333 
id[3] = 334 
id[4] = 335 
id[5] = 336 
id[6] = 337 
id[7] = 338 
id[8] = 339 
id[9] = 341 
id[22] = 346 
id[23] = 347 
id[24] = 348 
id[25] = 349 
id[26] = 350 
id[27] = 351 
id[28] = 352 
id[29] = 353 
id[32] = 372 
id[30] = 355 
id[31] = 356 
id[33] = 357 
id[34] = 358 
id[16] = 342 
id[17] = 343 
id[18] = 344 
id[39] = 363 
id[41] = 365 
id[42] = 366 
id[43] = 367 
id[14] = 325 
  
function getWeaponObjectFromID( id ) 
    if id then 
        object = id[id] 
        if object then 
            return object 
        else 
            return false 
        end 
    else  
        return false 
    end 
end 
  
function createWeaponOnFloor( x, y, z ) 
    id = getWeaponObjectFromID( source ) 
    object = createObject( id, x, y, z ) 
    setElementData( object, "WeaponID", source ) 
end 
addEvent( "createWeaponOnFloor", true ) 
addEventHandler( "createWeaponOnFloor", getRootElement(), createWeaponOnFloor ) 
  
function tirararma(source) 
Arma = getPedWeapon ( source ) 
    if takeWeapon ( source, Arma ) then 
    exports.chat:me( source, "deja algo en el suelo." ) 
    setPedAnimation ( source, "BOMBER", "BOM_Plant", 3000, false ) 
     
    x, y, z = getElementPosition( source ) 
    triggerClientEvent( "getThePosition", source, Arma, x, y, z ) 
    else 
    outputChatBox ( "No tienes un arma.", getRootElement(), 255, 255, 255, true ) 
    end 
end 
addCommandHandler("tirararma", tirararma) 
  

cliente:

function getThePosition( x, y, z ) 
    z2 = getGroundPosition( x, y, z ) 
    triggerServerEvent( "createWeaponOnFloor", source, x, y, z2 ) 
end 
addEvent( "getThePosition", true ) 
addEventHandler( "getThePosition", getLocalPlayer(), getThePosition) 

A parte, cuando introduzco el comando, me sale el siguiente error en la consola:

ERROR: tirararma\tirararma.lua:35: attempt to index local 'id' (a userdata value)

Link to comment

Pusiste 'source' en ves del ID del arma.

-- server side:

id = {} 
id[1] = 331 
id[2] = 333 
id[3] = 334 
id[4] = 335 
id[5] = 336 
id[6] = 337 
id[7] = 338 
id[8] = 339 
id[9] = 341 
id[22] = 346 
id[23] = 347 
id[24] = 348 
id[25] = 349 
id[26] = 350 
id[27] = 351 
id[28] = 352 
id[29] = 353 
id[32] = 372 
id[30] = 355 
id[31] = 356 
id[33] = 357 
id[34] = 358 
id[16] = 342 
id[17] = 343 
id[18] = 344 
id[39] = 363 
id[41] = 365 
id[42] = 366 
id[43] = 367 
id[14] = 325 
  
function getWeaponObjectFromID( id_ ) 
    if id_ then 
        object = id[id_] 
        if object then 
            return object 
        else 
            return false 
        end 
    else 
        return false 
    end 
end 
  
function createWeaponOnFloor( id, x, y, z ) 
    id = getWeaponObjectFromID( id ) 
    object = createObject( id, x, y, z ) 
    setElementData( object, "WeaponID", id ) 
end 
addEvent( "createWeaponOnFloor", true ) 
addEventHandler( "createWeaponOnFloor", getRootElement(), createWeaponOnFloor ) 
  
function tirararma(source) 
Arma = getPedWeapon ( source ) 
    if takeWeapon ( source, Arma ) then 
    exports.chat:me( source, "deja algo en el suelo." ) 
    setPedAnimation ( source, "BOMBER", "BOM_Plant", 3000, false ) 
    
    x, y, z = getElementPosition( source ) 
    triggerClientEvent( source, "getThePosition", source, Arma, x, y, z ) 
    else 
    outputChatBox ( "No tienes un arma.", getRootElement(), 255, 255, 255, true ) 
    end 
end 
addCommandHandler("tirararma", tirararma) 

-- client side:

function getThePosition( id, x, y, z ) 
    z2 = getGroundPosition( x, y, z ) 
    triggerServerEvent( "createWeaponOnFloor", localPlayer, id, x, y, z2 ) 
end 
addEvent( "getThePosition", true ) 
addEventHandler( "getThePosition", getLocalPlayer(), getThePosition) 

Link to comment

Okey, aquí va:

server:

id = {} 
id[1] = 331 
id[2] = 333 
id[3] = 334 
id[4] = 335 
id[5] = 336 
id[6] = 337 
id[7] = 338 
id[8] = 339 
id[9] = 341 
id[22] = 346 
id[23] = 347 
id[24] = 348 
id[25] = 349 
id[26] = 350 
id[27] = 351 
id[28] = 352 
id[29] = 353 
id[32] = 372 
id[30] = 355 
id[31] = 356 
id[33] = 357 
id[34] = 358 
id[16] = 342 
id[17] = 343 
id[18] = 344 
id[39] = 363 
id[41] = 365 
id[42] = 366 
id[43] = 367 
id[14] = 325 
  
id2 = {} 
id2[331] = 1 
id2[333] = 2 
id2[334] = 3 
id2[335] = 4 
id2[336] = 5 
id2[337] = 6 
id2[338] = 7 
id2[339] = 8 
id2[341] = 9 
id2[346] = 22 
id2[347] = 23 
id2[348] = 24 
id2[349] = 25 
id2[350] = 26 
id2[351] = 27 
id2[352] = 28 
id2[353] = 29 
id2[372] = 32 
id2[355] = 30 
id2[356] = 31 
id2[357] = 33 
id2[358] = 34 
id2[342] = 16 
id2[343] = 17 
id2[344] = 18 
id2[363] = 39 
id2[365] = 41 
id2[366] = 42 
id2[367] = 43 
id2[325] = 14 
  
function getWeaponObjectFromID( id_ ) 
    if id_ then 
        object = id[id_] 
        if object then 
            return object 
        else 
            return false 
        end 
    else 
        return false 
    end 
end 
  
function getWeaponObjectFromIDD( idD_ ) 
    if idD_ then 
        object = id2[idD_] 
        if object then 
            return object 
        else 
            return false 
        end 
    else 
        return false 
    end 
end 
  
function createWeaponOnFloor( id, ammo, x, y, z ) 
    id = getWeaponObjectFromID( id ) 
    objecto = createObject( id, x, y, z-0.9 ) 
    Cool = createColTube ( x, y, z, 0.5, 0.5 )  
    setElementData( Cool, "WeaponID", id ) 
    setElementData( Cool, "WeaponAmmo", ammo ) 
end 
addEvent( "createWeaponOnFloor", true ) 
addEventHandler( "createWeaponOnFloor", getRootElement(), createWeaponOnFloor ) 
  
function tirararma(source) 
Arma = getPedWeapon ( source ) 
Municion = getPedTotalAmmo( source ) 
    if takeWeapon ( source, Arma ) then 
    exports.chat:me( source, "deja algo en el suelo." ) 
    setPedAnimation ( source, "BOMBER", "BOM_Plant", 3000, false ) 
    
    x, y, z = getElementPosition( source ) 
    triggerClientEvent( source, "getThePosition", source, Arma, Municion, x, y, z ) 
    else 
    outputChatBox ( "No tienes un arma.", getRootElement(), 255, 255, 255, true ) 
    end 
end 
addCommandHandler("tirararma", tirararma) 
  
function ColShapeHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, Cool ) 
    if detection then 
        local ID = getElementData (Cool,"WeaponID") 
        local Ammo = getElementData (Cool,"WeaponAmmo") 
        local IIDD = getWeaponObjectFromIDD ( ID ) 
        exports.chat:me( thePlayer, "recoge algo del suelo." ) 
        setPedAnimation ( thePlayer, "BOMBER", "BOM_Plant", 3000, false ) 
        giveWeapon ( thePlayer, IIDD ,Ammo) 
        destroyElement ( objecto ) 
        destroyElement ( Cool ) 
    else 
        outputChatBox ( "No estás cerca de ningún arma.", getRootElement(), 255, 255, 255, true ) 
    end 
end 
addCommandHandler("recogerarma", ColShapeHit) 

client:

function getThePosition( id, ammo, x, y, z ) 
    z2 = getGroundPosition( x, y, z ) 
    triggerServerEvent( "createWeaponOnFloor", localPlayer, id, ammo, x, y, z ) 
end 
addEvent( "getThePosition", true ) 
addEventHandler( "getThePosition", getLocalPlayer(), getThePosition) 

Link to comment

De esa manera nunca va a funcionar, porque tendrias que haber creando una tabla con todas las armas, y insertar cada ves que alguien la tira y ahi ponerle otra tabla para poner al jugador al tocar un colshape y luego al usar el comando verificas si esta sobre uno.

id = {} 
id[1] = 331 
id[2] = 333 
id[3] = 334 
id[4] = 335 
id[5] = 336 
id[6] = 337 
id[7] = 338 
id[8] = 339 
id[9] = 341 
id[22] = 346 
id[23] = 347 
id[24] = 348 
id[25] = 349 
id[26] = 350 
id[27] = 351 
id[28] = 352 
id[29] = 353 
id[32] = 372 
id[30] = 355 
id[31] = 356 
id[33] = 357 
id[34] = 358 
id[16] = 342 
id[17] = 343 
id[18] = 344 
id[39] = 363 
id[41] = 365 
id[42] = 366 
id[43] = 367 
id[14] = 325 
  
id2 = {} 
id2[331] = 1 
id2[333] = 2 
id2[334] = 3 
id2[335] = 4 
id2[336] = 5 
id2[337] = 6 
id2[338] = 7 
id2[339] = 8 
id2[341] = 9 
id2[346] = 22 
id2[347] = 23 
id2[348] = 24 
id2[349] = 25 
id2[350] = 26 
id2[351] = 27 
id2[352] = 28 
id2[353] = 29 
id2[372] = 32 
id2[355] = 30 
id2[356] = 31 
id2[357] = 33 
id2[358] = 34 
id2[342] = 16 
id2[343] = 17 
id2[344] = 18 
id2[363] = 39 
id2[365] = 41 
id2[366] = 42 
id2[367] = 43 
id2[325] = 14 
  
weapons = { } 
onColShape = { } 
  
function getWeaponObjectFromID( id_ ) 
    if id_ then 
        object = id[id_] 
        if object then 
            return object 
        else 
            return false 
        end 
    else 
        return false 
    end 
end 
  
function getWeaponObjectFromIDD( idD_ ) 
    if idD_ then 
        object = id2[idD_] 
        if object then 
            return object 
        else 
            return false 
        end 
    else 
        return false 
    end 
end 
  
function createWeaponOnFloor ( id, ammo, x, y, z ) 
    local id = getWeaponObjectFromID ( id ) 
    local object = createObject ( id, x, y, z - 0.9 ) 
    local colshape = createColTube ( x, y, z, 0.5, 0.5 ) 
    table.insert ( 
        weapons, 
        { 
            object, 
            colshape 
        } 
    ) 
    setElementData ( colshape, "WeaponID", id ) 
    setElementData ( colshape, "WeaponAmmo", ammo ) 
    setElementData ( colshape, "TableID", #weapons ) 
    addEventHandler ( "onColShapeHit", colshape, ColShape ) 
    addEventHandler ( "onColShapeLeave", colshape, ColShape ) 
end 
addEvent ( "createWeaponOnFloor", true ) 
addEventHandler ( "createWeaponOnFloor", getRootElement(), createWeaponOnFloor ) 
  
function tirararma ( source ) 
    local Arma = getPedWeapon ( source ) 
    local Municion = getPedTotalAmmo ( source ) 
    if takeWeapon ( source, Arma ) then 
        exports.chat:me ( source, "deja algo en el suelo." ) 
        setPedAnimation ( source, "BOMBER", "BOM_Plant", 3000, false ) 
        triggerClientEvent ( source, "getThePosition", source, Arma, Municion, getElementPosition ( source ) ) 
    else 
        outputChatBox  ( "No tienes un arma.", getRootElement(), 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "tirararma", tirararma ) 
  
function ColShape ( thePlayer ) 
    if ( eventName == "onColShapeHit" ) then 
        onColShape [ thePlayer ] = source 
    else 
        onColShape [ thePlayer ] = nil 
    end 
end 
  
addCommandHandler ( "recogerarma", 
    function ( thePlayer ) 
        local colshape = onColShape [ thePlayer ] 
        if ( colshape and isElement ( colshape ) ) then 
            local detection = isElementWithinColShape ( thePlayer, colshape ) 
            if ( detection ) then 
                local ID = getElementData ( colshape, "WeaponID" ) 
                local Ammo = getElementData ( colshape, "WeaponAmmo" ) 
                local tableID = getElementData ( colshape, "TableID" ) 
                local IIDD = getWeaponObjectFromIDD ( ID ) 
                exports.chat:me ( thePlayer, "recoge algo del suelo." ) 
                setPedAnimation ( thePlayer, "BOMBER", "BOM_Plant", 3000, false ) 
                giveWeapon ( thePlayer, IIDD, Ammo ) 
                if ( isElement ( weapons [ tableID ] [ 1 ] ) ) then 
                    destroyElement ( weapons [ tableID ] [ 1 ] ) 
                end 
                if ( isElement ( weapons [ tableID ] [ 2 ] ) ) then 
                    destroyElement ( weapons [ tableID ] [ 2 ] ) 
                end              
            else 
                outputChatBox ( "No estás cerca de ningún arma.", thePlayer, 255, 255, 255, true ) 
            end 
        end 
    end 
) 

Link to comment
  • Recently Browsing   0 members

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