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: 4537 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"vanimTable.ifp["block"], v)
        end

    end
)


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

client.lua


local animationManagerWindow nil
local replaceAnimationLabelplayAnimationLabel nilnil
local restoreDefaultsButtonstopAnimationButton nilnil
local replaceAnimationGridListplayAnimationGridList nilnil

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 customAnimationBlockIndexcustomAnimationBlock in ipairs globalLoadedIfps ) do 
        local rowIndex guiGridListAddRow playAnimationGridList" + "..customAnimationBlock.friendlyName )
        guiGridListSetItemData playAnimationGridListrowIndex1customAnimationBlockIndex )
    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 playAnimationGridListrowIndex1customAnimationName )
    end
end

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

        outputChatBox ("Press 'X' to toggle Animation Manager"255255255)

        showCursor true )

        animationManagerWindow guiCreateWindow(118116558371"Animation Manager"false)
        guiWindowSetSizable(animationManagerWindowfalse)

        replaceAnimationLabel guiCreateLabel(122624519"Replace Animations With"falseanimationManagerWindow)
        guiSetFont(replaceAnimationLabel"default-bold-small")
        guiLabelSetHorizontalAlign(replaceAnimationLabel"center"false)

        replaceAnimationGridList guiCreateGridList(1249245255falseanimationManagerWindow)
        guiGridListAddColumn(replaceAnimationGridList"Animation Blocks"0.9)
        
        restoreDefaultsButton guiCreateButton(4931417441"Restore Defaults"falseanimationManagerWindow)
        playAnimationLabel guiCreateLabel(2942624519"Play Animation"falseanimationManagerWindow)
        guiSetFont(playAnimationLabel"default-bold-small")
        guiLabelSetHorizontalAlign(playAnimationLabel"center"false)
        
        stopAnimationButton guiCreateButton(32931417441"Stop Animation"falseanimationManagerWindow)
        playAnimationGridList guiCreateGridList(29449245255falseanimationManagerWindow)
        guiGridListAddColumn(playAnimationGridList"Animation Blocks"0.9)

        -- load IFP files and add them to the play animation gridlist
        for customAnimationBlockIndexcustomAnimationBlock in ipairs globalLoadedIfps ) do 
            local ifp engineLoadIFP customAnimationBlock.pathcustomAnimationBlock.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 replaceAnimationGridListcustomAnimationBlock.friendlyName )
            guiGridListSetItemData replaceAnimationGridListrowIndex1ifpIndex )
        end

        PopulatePlayAnimationGridListWithBlocks ()
    end
local function ReplacePedBlockAnimations playerifpIndex )
    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 = {
    245678
}


globalPedAnimationBlock = {
    -- Complete list of all animations in ped blockit 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 iswe 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 playerfalse )
    end 
)

addEvent ("onCustomAnimationSyncRequest"true )
addEventHandler ("onCustomAnimationSyncRequest"root,
    function ( player )
        table.insert synchronizationPlayersplayer )
        triggerLatentClientEvent player"onClientCustomAnimationSyncRequest"50000falseplayerplayerAnimations )
    end 
)

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

addEvent ("onCustomAnimationSet"true )
addEventHandler ("onCustomAnimationSet"root,
    function ( playerblockNameanimationName )
        SetAnimation playerblockNameanimationName )
        triggerClientEvent synchronizationPlayers"onClientCustomAnimationSet"playerblockNameanimationName ) 
    end 
)

addEvent ("onCustomAnimationReplace"true )
addEventHandler ("onCustomAnimationReplace"root,
    function ( playerifpIndex )
        playerAnimationsplayer ].replacedPedBlock ifpIndex
        triggerClientEvent synchronizationPlayers"onClientCustomAnimationReplace"playerifpIndex )
    end 
)

addEvent ("onCustomAnimationRestore"true )
addEventHandler ("onCustomAnimationRestore"root,
    function ( playerblockName )
        playerAnimationsplayer ].replacedPedBlock nil
        triggerClientEvent synchronizationPlayers"onClientCustomAnimationRestore"playerblockName )
    end 
)

function SetAnimation playerblockNameanimationName )
    if not playerAnimationsplayer then playerAnimationsplayer ] = {} end 
    if blockName == false then
        playerAnimationsplayer ].current nil
    else
        playerAnimationsplayer ].current = { blockNameanimationName }
    end 
end 


Postaw piwo autorowi tego posta
 

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


MeeShuffle

Programista/Grafik






Wiek: 32
Na forum: 4394 dni
Posty: 2758
Nick w MP: Shuffle

Piwa: 8575

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