Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2019-07-22, 16:45


Quin







Wiek: 25
Na forum: 4678 dni
Posty: 79

Piwa: 3

Respekt: 38

Siemka, napisa?em skrypt na customowe animacje ale mam problem poniewa? animacje widoczne tylko u mnie a inni widz? normalne animacje i chcia?bym je zsynchronizowa? tak aby ka?dy je widzia? ale nie do ko?ca wiem jak to zrobi?.

M?j kod:
local animTable = {

    ifp = {},

    anims = {
        Tutaj animacje
    }

}

addEventHandler("onClientResourceStart", resourceRoot,
    function()

        animTable.ifp["block"] = "ped"
        animTable.ifp["ifp"] = engineLoadIFP("IFP/ped.ifp", animTable.ifp["block"])

        for _, v in ipairs(animTable.anims) do
            engineReplaceAnimation(localPlayer, "ped", v, animTable.ifp["block"], v)
        end

    end
)


Wiem ?e jest to mo?liwe poniewa? znalaz?em taki skrypt

client.lua


local animationManagerWindow = nil
local replaceAnimationLabel, playAnimationLabel = nil, nil
local restoreDefaultsButton, stopAnimationButton = nil, nil
local replaceAnimationGridList, playAnimationGridList = nil, nil

local isShowingAnimationBlocksInPlayGridList = true
local currentBlockNameSelected = nil

local isLocalPlayerAnimating = false

local function PopulatePlayAnimationGridListWithBlocks ()
    isShowingAnimationBlocksInPlayGridList = true
    currentBlockNameSelected = nil

    guiGridListClear ( playAnimationGridList )

    -- Add IFP blocks to the play animation gridlist
    for customAnimationBlockIndex, customAnimationBlock in ipairs ( globalLoadedIfps ) do 
        local rowIndex = guiGridListAddRow ( playAnimationGridList, " + "..customAnimationBlock.friendlyName )
        guiGridListSetItemData ( playAnimationGridList, rowIndex, 1, customAnimationBlockIndex )
    end
end

local function PopulatePlayAnimationGridListWithCustomBlockAnimations ( ifpIndex )
    isShowingAnimationBlocksInPlayGridList = false
    currentBlockNameSelected = globalLoadedIfps [ifpIndex].blockName

    guiGridListClear ( playAnimationGridList )
    guiGridListAddRow ( playAnimationGridList, ".." )

    -- Add IFP blocks to the play animation gridlist
    for _, customAnimationName in ipairs ( globalLoadedIfps [ifpIndex].animations ) do 
        local rowIndex = guiGridListAddRow ( playAnimationGridList, "  "..customAnimationName )
        guiGridListSetItemData ( playAnimationGridList, rowIndex, 1, customAnimationName )
    end
end

addEventHandler("onClientResourceStart", resourceRoot,
    function()
        triggerServerEvent ( "onCustomAnimationSyncRequest", resourceRoot, localPlayer )

        outputChatBox ("Press 'X' to toggle Animation Manager", 255, 255, 255)

        showCursor ( true )

        animationManagerWindow = guiCreateWindow(118, 116, 558, 371, "Animation Manager", false)
        guiWindowSetSizable(animationManagerWindow, false)

        replaceAnimationLabel = guiCreateLabel(12, 26, 245, 19, "Replace Animations With", false, animationManagerWindow)
        guiSetFont(replaceAnimationLabel, "default-bold-small")
        guiLabelSetHorizontalAlign(replaceAnimationLabel, "center", false)

        replaceAnimationGridList = guiCreateGridList(12, 49, 245, 255, false, animationManagerWindow)
        guiGridListAddColumn(replaceAnimationGridList, "Animation Blocks", 0.9)
        
        restoreDefaultsButton = guiCreateButton(49, 314, 174, 41, "Restore Defaults", false, animationManagerWindow)
        playAnimationLabel = guiCreateLabel(294, 26, 245, 19, "Play Animation", false, animationManagerWindow)
        guiSetFont(playAnimationLabel, "default-bold-small")
        guiLabelSetHorizontalAlign(playAnimationLabel, "center", false)
        
        stopAnimationButton = guiCreateButton(329, 314, 174, 41, "Stop Animation", false, animationManagerWindow)
        playAnimationGridList = guiCreateGridList(294, 49, 245, 255, false, animationManagerWindow)
        guiGridListAddColumn(playAnimationGridList, "Animation Blocks", 0.9)

        -- load IFP files and add them to the play animation gridlist
        for customAnimationBlockIndex, customAnimationBlock in ipairs ( globalLoadedIfps ) do 
            local ifp = engineLoadIFP ( customAnimationBlock.path, customAnimationBlock.blockName )
            if not ifp then
                outputChatBox ("Failed to load '"..customAnimationBlock.path.."'")
            end
        end

        -- now add replaceable ifps to the other grid list
        for _, ifpIndex in ipairs ( globalReplaceableIfpsIndices ) do 
            local customAnimationBlock = globalLoadedIfps [ ifpIndex ]
            local rowIndex = guiGridListAddRow ( replaceAnimationGridList, customAnimationBlock.friendlyName )
            guiGridListSetItemData ( replaceAnimationGridList, rowIndex, 1, ifpIndex )
        end

        PopulatePlayAnimationGridListWithBlocks ()
    end
) 

local function ReplacePedBlockAnimations ( player, ifpIndex )
    local customIfpBlockName = globalLoadedIfps [ ifpIndex ].blockName
    for _, animationName in pairs ( globalPedAnimationBlock.animations ) do 
        -- make sure that we don't replace a partial animation
        if not globalPedAnimationBlock.partialAnimations [ animationName ] then 
            engineReplaceAnimation ( player, "ped", animationName, customIfpBlockName, animationName )
        end
    end
end 

local function HandleReplacedAnimationGridListDoubleClick ()
    local replacedAnimGridSelectedRow, replacedAnimGridSelectedCol = guiGridListGetSelectedItem ( replaceAnimationGridList ); 
    if replacedAnimGridSelectedRow and replacedAnimGridSelectedRow ~= -1 then 
        local ifpFriendlyName = guiGridListGetItemText( replaceAnimationGridList, replacedAnimGridSelectedRow, replacedAnimGridSelectedCol ) 
        local ifpIndex = guiGridListGetItemData(replaceAnimationGridList, replacedAnimGridSelectedRow, replacedAnimGridSelectedCol )
        ReplacePedBlockAnimations ( localPlayer, ifpIndex )
        triggerServerEvent ( "onCustomAnimationReplace", resourceRoot, localPlayer, ifpIndex )
        outputChatBox ("Replaced 'ped' block animations with '"..ifpFriendlyName.."'", 255, 255, 255)
    end
end 

local function HandlePlayAnimationGridListDoubleClick ()
    local playAnimGridSelectedRow, playAnimGridSelectedCol = guiGridListGetSelectedItem ( playAnimationGridList ); 
    if playAnimGridSelectedRow and playAnimGridSelectedRow ~= -1 then 
        local itemText = guiGridListGetItemText( playAnimationGridList, playAnimGridSelectedRow, playAnimGridSelectedCol )
        if isShowingAnimationBlocksInPlayGridList then  
            local ifpIndex = guiGridListGetItemData(playAnimationGridList, playAnimGridSelectedRow, playAnimGridSelectedCol )
            PopulatePlayAnimationGridListWithCustomBlockAnimations ( ifpIndex )
        else
            if itemText == ".." then 
                PopulatePlayAnimationGridListWithBlocks ( )
            else
                local animationName = guiGridListGetItemData(playAnimationGridList, playAnimGridSelectedRow, playAnimGridSelectedCol )
                setPedAnimation ( localPlayer, currentBlockNameSelected, animationName )
                triggerServerEvent ( "onCustomAnimationSet", resourceRoot, localPlayer, currentBlockNameSelected, animationName )
                isLocalPlayerAnimating = true
            end
       end
    end 
end 

addEventHandler( "onClientGUIDoubleClick", resourceRoot,
    function ( button, state, absoluteX, absoluteY )
        if button == "left" and state == "up" then 
            if source == replaceAnimationGridList then 
                HandleReplacedAnimationGridListDoubleClick ( )
            elseif source == playAnimationGridList then 
                HandlePlayAnimationGridListDoubleClick ( )
            end 
        end
    end 
)

addEventHandler( "onClientGUIClick", resourceRoot,
    function ( button, state )
        if button == "left" and state == "up" then 
            if source == restoreDefaultsButton then 
                -- restore all replaced animations of "ped" block
                engineRestoreAnimation ( localPlayer, "ped" )
                triggerServerEvent ( "onCustomAnimationRestore", resourceRoot,  localPlayer, "ped" )
                outputChatBox ("Restored ped block animations", 255, 255, 255)
            elseif source == stopAnimationButton then 
                setPedAnimation ( localPlayer, false )
                triggerServerEvent ( "onCustomAnimationSet", resourceRoot, localPlayer, false, false )
            end 
        end
    end 
)
 
bindKey ( "X", "down", 
    function ( key, keyState )
        if ( keyState == "down" ) then
            local isAnimationMangerWindowVisible = guiGetVisible ( animationManagerWindow )
            guiSetVisible ( animationManagerWindow, not isAnimationMangerWindowVisible )
            showCursor ( not isAnimationMangerWindowVisible )
        end
    end
)

addEvent ("onClientCustomAnimationSyncRequest", true )
addEventHandler ("onClientCustomAnimationSyncRequest", root,
    function ( playerAnimations )
        for player, anims in pairs ( playerAnimations ) do 
            if isElement ( player ) then 
                if anims.current then 
                    setPedAnimation ( player, anims.current[1], anims.current[2] ) 
                end
                if anims.replacedPedBlock then 
                    ReplacePedBlockAnimations ( player, anims.replacedPedBlock )
                end
            end
        end 
    end 
)

addEvent ("onClientCustomAnimationSet", true )
addEventHandler ("onClientCustomAnimationSet", root,
    function ( blockName, animationName )
        if source == localPlayer then return end
        if blockName == false then 
            setPedAnimation ( source, false )
            return
        end 
        setPedAnimation ( source, blockName, animationName )
    end 
)

addEvent ("onClientCustomAnimationReplace", true )
addEventHandler ("onClientCustomAnimationReplace", root,
    function ( ifpIndex )
        if source == localPlayer then return end
        ReplacePedBlockAnimations ( source, ifpIndex )
    end 
)

addEvent ("onClientCustomAnimationRestore", true )
addEventHandler ("onClientCustomAnimationRestore", root,
    function ( blockName )
        if source == localPlayer then return end
        engineRestoreAnimation ( source, blockName )
    end 
)


setTimer ( 
    function ()
        if isLocalPlayerAnimating then 
            if not getPedAnimation (localPlayer) then
                isLocalPlayerAnimating = false
                triggerServerEvent ( "onCustomAnimationStop", resourceRoot, localPlayer )
            end
        end
    end, 100, 0
)


animations_client.lua ----- tutaj wyrzuci?em animacje z listy bo limit liter na stronie


globalLoadedIfps = {
    [1] = { friendlyName = "PARKOUR", blockName = "parkour", path = "Animations/parkour.ifp", animations = { 'BckHndSpingBTuck', 'BckHndSping','CartWheel','FrntHndSpring','HandPlant' } },
    [2] = { friendlyName = "ASSASSIN'S CREED", blockName = "assassin_creed", path = "Animations/Assassins_creed_ped.ifp", animations = { } },
    [3] = { friendlyName = "ZOMBIE", blockName = "zombie", path = "Animations/zombie_ped.ifp", animations = {  } },
    [4] = { friendlyName = "GTA III", blockName = "gta3", path = "Animations/gta3_ped.ifp", animations = {  } },
    [5] = { friendlyName = "GTA VC STORIES", blockName = "gtavc_stories", path = "Animations/gtavc_stories_ped.ifp", animations = { } },
    [6] = { friendlyName = "GTA VC MODDED", blockName = "gtavc_modded", path = "Animations/gtavc_modded_ped.ifp", animations = {  } },
    [7] = { friendlyName = "GTA IV", blockName = "gtaiv", path = "Animations/gta4_ped.ifp", animations = { } },
    [8] = { friendlyName = "GTA V", blockName = "gtav", path = "Animations/gta5_ped.ifp", animations = {  } },
    [9] = { friendlyName = "360 DAB", blockName = "dab", path = "Animations/StandingWebsterAerialBack360.ifp", animations = { 'weapon_crouch' } }
}

globalReplaceableIfpsIndices = {
    2, 4, 5, 6, 7, 8
}


globalPedAnimationBlock = {
    -- Complete list of all animations in ped block, it is the default block
    -- in gta sa 
    animations = {
        Tutaj animacje
    },

    -- We will use this for checking whether animation is partial or not for ped block
    -- if it is, we won't replace it. Partial animations can be played using setPedAnimation.
    partialAnimations = {
        ["CAR_alignHI_LHS"] = true,
        ["CAR_alignHI_RHS"] = true,
        ["DAM_armL_frmFT"] = true,
        ["endchat_01"] = true,
        ["endchat_02"] = true,
        ["endchat_03"] = true,
        ["facanger"] = true,
        ["facgum"] = true,
        ["facsurp"] = true,
        ["facsurpm"] = true,
        ["factalk"] = true,
        ["facurios"] = true,
        ["FightA_M"] = true,
        ["FightA_block"] = true,
        ["flee_lkaround_01"] = true,
        ["handscower"] = true,
        ["HIT_walk"] = true,
        ["IDLE_chat"] = true,
        ["pass_Smoke_in_car"] = true,
        ["phone_in"] = true,
        ["phone_out"] = true,
        ["phone_talk"] = true,
        ["SHOT_leftP"] = true,
        ["SHOT_partial"] = true,
        ["SHOT_partial_B"] = true,
        ["SHOT_rightP"] = true,
        ["Shove_Partial"] = true,
        ["Smoke_in_car"] = true,
        ["Walk_DoorPartial"] = true,
    }
}


sync_animations_server.lua


-- since we're only interested in ped block, we don't need support for other blocks
-- you might want to rename playerAnimations.replacedPedBlock to playerAnimations.replacedBlocks 
-- to add support for replacing more blocks and keeping them sync 

local playerAnimations = {  } -- current = {}, replacedPedBlock = {}
local synchronizationPlayers = {}

local SetAnimation -- function

addEventHandler ( "onPlayerJoin", root,
    function ( )
        playerAnimations [ source ] = {}
    end
)

for _, player in pairs ( getElementsByType ("player") ) do 
    playerAnimations [ player ] = {}
end

addEvent ("onCustomAnimationStop", true )
addEventHandler ("onCustomAnimationStop", root,
    function ( player )
        SetAnimation ( player, false )
    end 
)

addEvent ("onCustomAnimationSyncRequest", true )
addEventHandler ("onCustomAnimationSyncRequest", root,
    function ( player )
        table.insert ( synchronizationPlayers, player )
        triggerLatentClientEvent ( player, "onClientCustomAnimationSyncRequest", 50000, false, player, playerAnimations )
    end 
)

addEventHandler ( "onPlayerQuit", root,
    function ( )
        for i, player in pairs ( synchronizationPlayers ) do
            if source == player then 
                table.remove ( synchronizationPlayers, i )
                break
            end 
        end 
        playerAnimations [ source ] = nil
    end
)

addEvent ("onCustomAnimationSet", true )
addEventHandler ("onCustomAnimationSet", root,
    function ( player, blockName, animationName )
        SetAnimation ( player, blockName, animationName )
        triggerClientEvent ( synchronizationPlayers, "onClientCustomAnimationSet", player, blockName, animationName ) 
    end 
)

addEvent ("onCustomAnimationReplace", true )
addEventHandler ("onCustomAnimationReplace", root,
    function ( player, ifpIndex )
        playerAnimations[ player ].replacedPedBlock = ifpIndex
        triggerClientEvent ( synchronizationPlayers, "onClientCustomAnimationReplace", player, ifpIndex )
    end 
)

addEvent ("onCustomAnimationRestore", true )
addEventHandler ("onCustomAnimationRestore", root,
    function ( player, blockName )
        playerAnimations[ player ].replacedPedBlock = nil
        triggerClientEvent ( synchronizationPlayers, "onClientCustomAnimationRestore", player, blockName )
    end 
)

function SetAnimation ( player, blockName, animationName )
    if not playerAnimations[ player ] then playerAnimations[ player ] = {} end 
    if blockName == false then
        playerAnimations[ player ].current = nil
    else
        playerAnimations[ player ].current = { blockName, animationName }
    end 
end 


Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-07-23, 13:50


MeeShuffle

Programista/Grafik






Wiek: 33
Na forum: 4536 dni
Posty: 2758
Nick w MP: Shuffle

Piwa: 8578

Respekt: 535,3
Respekt: 535,3

server - wykonuje si? dla wszystkich

client - wykonuje si? dla danej osoby


Wynosza? z tego wnioski, po stronie clienta zr?b wywolanie kt?re striggeruje setPedAnimation na stron? server i tam zrobi wykonanie tej funkcji :)

Postaw piwo autorowi tego posta
 

 
Tagi: synchronizacja :: customowych :: animacji
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Synchronizacja customowych animacji Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku