• Need help making a hook/function
    6 replies, posted
Developer API Hooks are available for use in development, listed as: ConquestSystem_PointCaptured, Args = TeamName, PointName ConquestSystem_CapturedPointTick, Args = TeamName, PointName - this hook is called once per second. ConquestSystem_PointLost, Args = TeamName, PointName Gamemode: DarkRP [MilitaryRP Theme] If anyone here is familar with conquest system, im trying to set up something that whenever a team captures a point, It prints for everyone "The [Team] Has captured [Pointname]!" im new to lua coding can someone help me out Addon page: https://github.com/Bambofy/ConquestSystem
hook.Add("ConquestSystem_PointLost", "flagCaptured", function(teamName, pointName) print("The " .. teamName .. " has captured " .. pointName) end)
Not working
All hooks in that AI are serverside. You can learn about the different states on the wiki: Game States. SERVER and CLIENT. If you want it transferred to the client, you have to learn the net system: Net Library Usage.
I mean, for his use if he just wants to let players know he could use http://wiki.garrysmod.com/page/Player/ChatPrint
Serverside: -- First you need to add a network string with a name that is probably not already used by the gamemode or any addons. util.AddNetworkString( "team_Point_Captured" ) -- The next line should only be added if it has not been already. local ply = FindMetaTable( "Player" ) -- Next, you should send the net message to the client when a point is captured. hook.Add( "ConquestSystem_PointCaptured", "_captured", function( teamName, pointName ) net.Start( "team_Point_Captured" ) net.WriteString( teamName ) net.WriteString( pointName ) net.Send( ply ) end) Clientside: -- The client should receive the net message from the server. net.Receive( "team_PointCaptured", function() -- Next, the messages should be read in order from when they were sent. local teamName = net.ReadString() local pointName = net.ReadString() -- Lastly, the message should be printed to the player's chat using the PrintMessage function with the HUD_PRINTTALK Enum. PrintMessage( HUD_PRINTTALK, teamName .. " has captured " .. pointName .. "." ) end)
Why are you looking the MetaTable of the player and sending that? Player metatable != player entity. Instead of using net.Send, you could just use net.Broadcast also there is no need for any kind of networking anyway, and you example wouldn't work anyway - PrintMessage is serverside so he could have just used that in the hook.
Sorry, you need to Log In to post a reply to this thread.