Personal tools

Lua/Events/Shared/PlayerNetworkValueChange

From JC2-MP Documentation

< Lua
Jump to: navigation, search


This is deprecated as of 0.2.

It has been replaced by NetworkObjectValueChange


Name    PlayerNetworkValueChange
Arguments (in table)    Player player, string key, object value
Return option    None


Description

Fired when Player:SetNetworkValue is called from any module on the server. It is not fired by calling Player:SetValue.

Example

Server

Use '/set playername key value' to set players' values on both server and client.

function Foo(args)
	print(tostring(args.player).."'s "..args.key.." was set to "..tostring(args.value))
end
 
Events:Subscribe("PlayerNetworkValueChange", Foo)
 
function ConsoleSet(args)
	local words = args.text:split(" ")
 
	if #words == 3 then
		local player = Player.Match(words[1])[1]
		if player then
			player:SetNetworkValue(words[2], words[3])
		else
			print("Player not found!")
		end
	else
		print("Invalid arguments!")
	end
end
 
Console:Subscribe("set", ConsoleSet)

Client

Prints any value changes to the chat. Used in combination with the server script above.

function Foo(args)
	Chat:Print(
		tostring(args.player).."'s "..args.key.." was set to "..tostring(args.value),
		Color.Yellow
	)
end
 
Events:Subscribe("PlayerNetworkValueChange", Foo)

See also