• Lua Hook Help
    6 replies, posted
I'm trying to make a ULX addon to give roles, but it won't work. The detective is old code, and I want the role code to trigger when the round starts. I tried it on the traitor command, but it wont work. Error code: [IMG]http://i.imgur.com/GiwRysD.png[/IMG] Lua code: [CODE]local CATEGORY_NAME = "Britannia TTT" function ulx.group(calling_ply) calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]]) end local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true) group:help(" Shows link to our Steam Group." ) group:defaultAccess(ULib.ACCESS_ADMIN) function ulx.traitor(calling_ply) hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function() if ply:GetRoleString() != "traitor" then calling_ply:SetRole(ROLE_TRAITOR) calling_ply:AddCredits(2)) end end function ulx.detective(calling_ply) calling_ply:SetRole(ROLE_DETECTIVE) calling_ply:AddCredits(1) end local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true) local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true) traitor:help("Robi ciebie zdrajcą") traitor:defaultAccess(ULib.ACCESS_ADMIN) detective:help("Robi ciebie detektywem") detective:defaultAccess(ULib.ACCESS_ADMIN)[/CODE]
[lua]local CATEGORY_NAME = "Britannia TTT" function ulx.group(calling_ply) calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]]) end local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true) group:help(" Shows link to our Steam Group." ) group:defaultAccess(ULib.ACCESS_ADMIN) function ulx.traitor(calling_ply) hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function() if ply:GetRoleString() != "traitor" then calling_ply:SetRole(ROLE_TRAITOR) calling_ply:AddCredits(2) end end) end function ulx.detective(calling_ply) calling_ply:SetRole(ROLE_DETECTIVE) calling_ply:AddCredits(1) end local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true) local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true) traitor:help("Robi ciebie zdrajcą") traitor:defaultAccess(ULib.ACCESS_ADMIN) detective:help("Robi ciebie detektywem") detective:defaultAccess(ULib.ACCESS_ADMIN) [/lua] You had one too many )'s and missing an end for the hook. edit: Cloudflare keeps thinking that code above is bad and keeps asking for captchas :v
[QUOTE=Mrkrabz;48188132][/lua]local CATEGORY_NAME = "Britannia TTT" function ulx.group(calling_ply) calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]]) end local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true) group:help(" Shows link to our Steam Group." ) group:defaultAccess(ULib.ACCESS_ADMIN) function ulx.traitor(calling_ply) hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function() if ply:GetRoleString() != "traitor" then calling_ply:SetRole(ROLE_TRAITOR) calling_ply:AddCredits(2) end end) end function ulx.detective(calling_ply) calling_ply:SetRole(ROLE_DETECTIVE) calling_ply:AddCredits(1) end local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true) local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true) traitor:help("Robi ciebie zdrajcą") traitor:defaultAccess(ULib.ACCESS_ADMIN) detective:help("Robi ciebie detektywem") detective:defaultAccess(ULib.ACCESS_ADMIN) [/lua] You had one too many )'s and missing an end for the hook. edit: Cloudflare keeps thinking that code above is bad and keeps asking for captchas :v[/QUOTE] Isn't it supposed to be there to finish the "(" at hook.add( ?
[QUOTE=gronnmann;48188159]Isn't it supposed to be there to finish the "(" at hook.add( ?[/QUOTE] Yes, but you were missing an end for the hook as you opened a function.
[QUOTE=Mrkrabz;48188172]Yes, but you were missing an end for the hook as you opened a function.[/QUOTE] I'm pretty new to all the lua coding and this is my first hook. Now I tried to make it this way: [CODE]local CATEGORY_NAME = "Britannia TTT" function ulx.group(calling_ply) calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]]) end local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true) group:help(" Shows link to our Steam Group." ) group:defaultAccess(ULib.ACCESS_ADMIN) function ulx.traitor(calling_ply) hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function()end if ply:GetRoleString() != "traitor" then calling_ply:SetRole(ROLE_TRAITOR) calling_ply:AddCredits(2) end end function ulx.detective(calling_ply) calling_ply:SetRole(ROLE_DETECTIVE) calling_ply:AddCredits(1) end local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true) local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true) traitor:help("Robi ciebie zdrajcą") traitor:defaultAccess(ULib.ACCESS_ADMIN) detective:help("Robi ciebie detektywem") detective:defaultAccess(ULib.ACCESS_ADMIN)[/CODE] I get this error: [IMG]http://i.imgur.com/sNTWqg7.png[/IMG]
[QUOTE=gronnmann;48188261]I'm pretty new to all the lua coding and this is my first hook. Now I tried to make it this way: [CODE]local CATEGORY_NAME = "Britannia TTT" function ulx.group(calling_ply) calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]]) end local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true) group:help(" Shows link to our Steam Group." ) group:defaultAccess(ULib.ACCESS_ADMIN) function ulx.traitor(calling_ply) hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function()end if ply:GetRoleString() != "traitor" then calling_ply:SetRole(ROLE_TRAITOR) calling_ply:AddCredits(2) end end function ulx.detective(calling_ply) calling_ply:SetRole(ROLE_DETECTIVE) calling_ply:AddCredits(1) end local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true) local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true) traitor:help("Robi ciebie zdrajcą") traitor:defaultAccess(ULib.ACCESS_ADMIN) detective:help("Robi ciebie detektywem") detective:defaultAccess(ULib.ACCESS_ADMIN)[/CODE] I get this error: [IMG]http://i.imgur.com/sNTWqg7.png[/IMG][/QUOTE] As he said, you are missing an end to close the third argument of the hook.Add function and a closing parenthesis to close the hook.Add function. Also, the name of the function is hook.Add, not hook.add. Capitalization matters.
I fixed it. Thanks everyone for the help.
Sorry, you need to Log In to post a reply to this thread.