1. Post #1
    NnyAskC's Avatar
    April 2006
    98 Posts
    Okay so I was trying to follow along with the
    Hook Tutorial from the GMod Wiki unfortunately it was never 100% finished.

    So I created a tweaked version to display death info in my DarkRP server.


    Code:
    // Hook Testing
    
    
    Msg("Loading Custom Scripts Test. \n")
    
    if SERVER then
        AddCSLuaFile ("CustomScripts.lua")
    end
    include("CustomScripts.lua")
    
    local deathHookTest = function(victim, inflictor, killer)
        if killer:IsPlayer(true)then -- Only prints if the killer is a player.
      Msg( killer:Nick() .. " killed " ..victim:Nick() .. "\n" )
     end
     if killer:IsPlayer(false)then -- Only prints if the killer is a prop.
         Msg( killer:Nick() .. " killed " ..victim:Nick().. " with " .. inflictor:GetOwner() .. "'s prop!\n")
     end
    end
    
    hook.Add( "PlyerDeath", "Displays Player Deaths", deathHookTest )
    1. Now here is where my questions come in. I added the "if SERVER" and "include" bits based off of looking at other things, but because the bits I used were all listed as "shared", how needed is this and how should it properly be used in this context?

    2. I added include("CustomScripts.lua") to my cl_init.lua and AddCSLuaFile("CustomScripts.lua") to the init.lua. From what I've gathered, include is for client an addcsluafile is for server, is this correct, and was it needed in this case?

    3. What would be a better way to launch the script other than how I have done by connecting it to DarkRP files?

    4. This is an error, it will spam "Loading Custom Scripts Test." and then hault with the error "[darkrp\gamemode\CustomScripts.lua:15] chunk has too many syntax levels". Line 15 is "Msg( killer:Nick() .. " killed " .. victim:Nick() .. " with " .. inflictor:GetOwner() .. "'s prop!\n")"

    Needless to say, it doesn't work.

    So, anyone care to help me on any of these aspects? I tried a few tweaks but still get some level of no effect or error.

    Thank you.

  2. Post #2
    I had to buy my own title because no one loves me
    BL00DB4TH's Avatar
    April 2011
    225 Posts
    I don't know why it's returning that error, but if you're checking to see if it's not a player, then using a method specific to the player entity (ply:Nick()), it's not going to work.

    Also I'm not sure that "if killer:IsPlayer(false)" is actually valid to check if it's not a player. I could be wrong, but I would use either this:

    if not killer:IsPlayer()

    or

    if killer:IsPlayer() == false

    Personally I prefer the first one. Again I'm not sure why it would throw that particular error, but there are more errors down the road later.

    Include is for both client and server; if you include a file in init.lua, it should be a serverside file. If you include one in cl_init.lua, it should be clientside. AddCSLua file is for sending a clientside file from server to client. You still need to include it clientside, though.

  3. Post #3

    July 2007
    864 Posts
    if !killer:IsPlayer() then