Jump to content

Walking style synchronisation


arer

Recommended Posts

Hi. I observed bad thing - when someone changes walking style, only he can see this. Everyone see "strongman" walking style for everyone.
How to fix synchronisation of this?

 

I have this script:
 

 

local window
local showed = false
local styles = {
	{"Normal", 0},
	{"Woman", 129},
	{"Woman2", 133},
}


function createStylePanel()
	if showed then return end
	local sw, sh = guiGetScreenSize()
	window = guiCreateWindow(sw/1.4, sh/4, sw/4.5, sh/2, "Style", false)
	grid = guiCreateGridList(0, 0.06, 1, 0.75, true, window)
	col1 = guiGridListAddColumn(grid, "Styl chodzenia", 0.9)
	button1 = guiCreateButton(0, 0.82, 1, 0.07, "Ustaw styl", true, window)
	addEventHandler("onClientGUIClick", button1, selectStyle, false)
	addEventHandler("onClientGUIDoubleClick", grid, selectStyle, false)
	button2 = guiCreateButton(0, 0.9, 1, 0.07, "Zamknij", true, window)
	addEventHandler("onClientGUIClick", button2, hideStylePanel, false)
	showCursor(true)
	showed = true
	for i,v in ipairs(styles) do
		local row = guiGridListAddRow(grid)
		guiGridListSetItemText(grid, row, col1, v[1], false, false)
		guiGridListSetItemData(grid, row, col1, v[2], false, false)
	end
end
addCommandHandler("ws", createStylePanel)

function hideStylePanel()
	removeEventHandler("onClientGUIClick", button1, selectStyle, false)
	removeEventHandler("onClientGUIDoubleClick", grid, selectStyle, false)
	removeEventHandler("onClientGUIClick", button2, hideStylePanel, false)
	destroyElement(window)
	showCursor(false)
	showed = false
end

function selectStyle()
	local item = guiGridListGetSelectedItem(grid)
	if item == -1 then return end
		local styl = guiGridListGetItemData(grid, item, 1)
		local styl_text = guiGridListGetItemText(grid, item, 1)
		outputChatBox("Zmieniasz swój styl chodzenia na: "..styl_text)
		setPedWalkingStyle(localPlayer, styl)
		hideStylePanel()
end

 

Link to comment
1 hour ago, aka Blue said:

Trigger to serverside and use the setPedWalkingStyle there, in the server side.

 

Could you please help me with this?
 

I make this on server side:
 

function styl(playerSource)
	triggerClientEvent(playerSource, "styl", playerSource)
	setPedWalkingStyle(playerSource, styl)
end

and this is triggering from client script:
 

function selectStyle()
	local item = guiGridListGetSelectedItem(grid)
	if item == -1 then return end
		local styl = guiGridListGetItemData(grid, item, 1)
		local styl_text = guiGridListGetItemText(grid, item, 1)
		outputChatBox("Zmieniasz swój styl chodzenia na: "..styl_text)
		addEventHandler("styl", localPlayer, selectStyle)
		hideStylePanel()
end

 

Not working :(

Link to comment
  • Moderators

Try this:

Client

function selectStyle()
	local item = guiGridListGetSelectedItem(grid)
	if item == -1 then return end
	local styl = guiGridListGetItemData(grid, item, 1)
	local styl_text = guiGridListGetItemText(grid, item, 1)
	outputChatBox("Zmieniasz swój styl chodzenia na: "..styl_text)
	triggerServerEvent( "doServer:SetPedWalkingStyle", localPlayer, styl )
	hideStylePanel()
end

Server

addEvent( "doServer:SetPedWalkingStyle", true )
addEventHandler( "doServer:SetPedWalkingStyle", root,
	function ( styl )
		setPedWalkingStyle(source, tonumber(styl))
	end
)

 

Edited by DNL291
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...