Here are examples on how to use the new hooks:
CanOpenDoor
This will give admins power to open/close all doors
OnPlayerChatCode:function PLUGIN:CanOpenDoor( player, lock ) -- Check if the level of the player is 1 or more (1 = moderator, 2 = owner) if( player:GetComponent("BaseNetworkable").net.connection.authLevel >= 1 ) then -- If level is more then moderator level, then he may open and close anydoors return true end end
This will mute a player and log what he tried to say.
OnEntityBuiltCode:function PLUGIN:OnPlayerChat(arg) -- here you will get the name of the player, and on second the steamid of the player print(arg.connection.player.displayName .. " - " .. rust.UserIDFromPlayer(arg.connection.player) .. ": Tried to talk but was muted") -- he you will get the full line of what he was trying to say print("He tried to say: " .. arg:GetString(0, "text")) -- return false = cancel the message return false end
This will log who tried to build a structure (wall/stairs/foundations/windows/etc)
and destroy it immediately.
OnItemCraftCode:function PLUGIN:OnEntityBuilt( heldentity, gameobject ) -- here you will get the playername that built the thing, and on second you will first get the buildingblock (:GetComponent("BuildingBlock")) -- and then the name of the buildingblock print(heldentity.ownerPlayer.displayName .. " tried to build a " .. gameobject:GetComponent("BuildingBlock").blockDefinition.name) -- Here it will show you how to destroy a buildingblock, you need to get the BaseEntity Component first to call the function Kill gameobject:GetComponent("BaseEntity"):Kill(ProtoBuf.Mode.None,0,0,new(UnityEngine.Vector3._type,nil) ) end
This will log who tried to craft something, and make the craft time go down to 50%
This will block players from crafting anything.Code:function PLUGIN:OnItemCraft( itemcrafttask ) -- here you will first get the player that is trying to craft -- in second you will get the name of the item that he is trying to craft print(itemcrafttask.owner.displayName .. " has started to craft a " .. itemcrafttask.blueprint.targetItem.displayname) -- this will make the craft time be lowered by 50% itemcrafttask.endTime = UnityEngine.Time.get_time() + itemcrafttask.blueprint.time/2 return itemcrafttask end
OnPlayerLootCode:function PLUGIN:OnItemCraft( itemcrafttask ) -- here you will first get the player that is trying to craft -- in second you will get the name of the item that he is trying to craft print(itemcrafttask.owner.displayName .. " has started to craft a " .. itemcrafttask.blueprint.targetItem.displayname) -- this will cancel the craft itemcrafttask.cancelled = true return itemcrafttask end
This will log any players that try to loot another player, and if the target player is an admin, it will cancel the looting.
Code:function PLUGIN:OnPlayerLoot( sourceplayerloot, target ) -- Check if the sourcePlayer is trying to loot a player (and not an item like a wood storage box) if(target:GetComponent("BasePlayer")) then -- Trying to loot a player local sourcePlayer = sourceplayerloot:GetComponent("BasePlayer") local targetPlayer = target:GetComponent("BasePlayer") print(sourcePlayer.displayName .. " is Starting to loot a player named: " .. targetPlayer.displayName) -- Check if player is trying to loot an admin if( targetPlayer:GetComponent("BaseNetworkable").net.connection.authLevel >= 1 ) then -- If trying to loot an admin, close the loot sourceplayerloot:Clear() rust.SendChatMessage( sourcePlayer , "SERVER", "You may not loot an admin" ) end end end
CanOpenDoor OnPlayerChat OnEntityBuilt OnItemCraft OnPlayerLoot
Discussion in 'Rust Development' started by Reneb, Nov 25, 2014.