• Clashing code?
    6 replies, posted
So, two seperate addons. Both work perfectly in a whisper server, but on a dedicated: only one works. I need both to work! 1)Folder structure: SERVERIP/addons/Join Command/lua/autorun/JC.lua JC.lua: [CODE] function JoinCommand( pl, text, teamonly ) if (text == "!join") and pl:IsUserGroup("user") then pl:PS_GivePoints(10000) pl:SetUserGroup( "patriot" ) pl:PS_GiveItem("Patriotic Jump Pack") pl:SendLua([[gui.OpenURL("OPENS GROUP PAGE")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined our Steam group via !join and was rewarded 10,000 points" ) end end end hook.Add( "PlayerSay", "Chat", JoinCommand )[/CODE] 2)Folder structure: SERVERIP/addons/Pack Command/lua/autorun/PC.lua PC.lua: [CODE] function PackCommand( pl, text, teamonly ) if (text == "!pack") then pl:SendLua([[gui.OpenURL("OPENS SERVER PACK PAGE")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has downloaded our server pack via !pack for even faster connect times!" ) end end end hook.Add( "PlayerSay", "Chat", PackCommand ) [/CODE] [B]How do I allow both of these to work? They both have info.txt files with different information inside.[/B] Thanks
Put PC.lua and JC.lua into "SERVERIP/addons/Pack Command/lua/autorun/server". Also, it would be easier to put both of these into one file so you don't have a mess of code and lua files in your autorun: [code] function JoinNPackCommands( pl, text, teamonly ) if (text == "!join") and pl:IsUserGroup("user") then pl:PS_GivePoints(10000) pl:SetUserGroup( "patriot" ) pl:PS_GiveItem("Patriotic Jump Pack") pl:SendLua([[gui.OpenURL("OPENS GROUP PAGE")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined our Steam group via !join and was rewarded 10,000 points" ) end end if (text == "!pack") then pl:SendLua([[gui.OpenURL("OPENS SERVER PACK PAGE")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has downloaded our server pack via !pack for even faster connect times!" ) end end end hook.Add( "PlayerSay", "Chat", JoinNPackCommands ) [/code]
The issue is that they both have the same hook identifier on the last line ("Chat").
Also with that first code, you realize you're rewarding the player for opening the Group Page and not actually joining it right
[QUOTE=NiandraLades;45229080]Also with that first code, you realize you're rewarding the player for opening the Group Page and not actually joining it right[/QUOTE] Yes I do. However, it is un-abusable from a non-admin perspective, as the player will be moved to a group where they can no longer call the command. If the player doesn't want to join then that's not my problem as I can't imagine they'll be back, if so! However, I have seen scripts where the server actually CHECKS if a steam ID has joined a group. If any of you could suggest how to do that, then please do! [editline]27th June 2014[/editline] [QUOTE=Willox;45229069]The issue is that they both have the same hook identifier on the last line ("Chat").[/QUOTE] Can I change the hook identifier to anything, say: "ServerCommands" or must it be that? The template of the script is not actually mine. I am unfimiliar with hooks and what must be defined! I just did the specifics of what actually happens in the function. [editline]27th June 2014[/editline] [QUOTE=Zephruz;45229059]Put PC.lua and JC.lua into "SERVERIP/addons/Pack Command/lua/autorun/server". Also, it would be easier to put both of these into one file so you don't have a mess of code and lua files in your autorun: [code] function JoinNPackCommands( pl, text, teamonly ) if (text == "!join") and pl:IsUserGroup("user") then pl:PS_GivePoints(10000) pl:SetUserGroup( "patriot" ) pl:PS_GiveItem("Patriotic Jump Pack") pl:SendLua([[gui.OpenURL("OPENS GROUP PAGE")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined our Steam group via !join and was rewarded 10,000 points" ) end end if (text == "!pack") then pl:SendLua([[gui.OpenURL("OPENS SERVER PACK PAGE")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has downloaded our server pack via !pack for even faster connect times!" ) end end end hook.Add( "PlayerSay", "Chat", JoinNPackCommands ) [/code][/QUOTE] Thank you Zephruz!
Why are you using a for loop to print a standard message on all the player's screen? Just use the PrintMessage function.. [url]http://wiki.garrysmod.com/page/Global/PrintMessage[/url]
[QUOTE=Jeezy;45229657]Why are you using a for loop to print a standard message on all the player's screen? Just use the PrintMessage function.. [url]http://wiki.garrysmod.com/page/Global/PrintMessage[/url][/QUOTE] That was the part of the framework which was already there. I didn't understand what it did or how important it was, so I kept it. I guess I don't really need to change it, do I? I mean it's barely using any more resources, is it? [editline]27th June 2014[/editline] Can anyone tell me why the 3rd command doesn't work? [CODE]function JoinNPackCommands( pl, text, teamonly ) if (text == "!join") and pl:IsUserGroup("user") then pl:PS_GivePoints(10000) pl:SetUserGroup( "patriot" ) pl:PS_GiveItem("Patriotic Jump Pack") pl:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/thehouseoffun")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined our Steam group via !join and was rewarded 10,000 points" ) end end if (text == "!pack") then pl:SendLua([[gui.OpenURL("http://steamcommunity.com/sharedfiles/filedetails/?id=270569564")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has downloaded our server pack via !pack for even faster connect times!" ) end end if (text == "!donate") then pl:SendLua([[gui.OpenURL("www.thofdonation.droppages.com")]]) -- Change ADDRESS to your chosen page. for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " is looking to donate via !donate to support the server!" ) end end end hook.Add( "PlayerSay", "Chat", JoinNPackCommands )[/CODE] SERVERIP/addons/chat-commands/lua/autorun/server/servercommands.lua EDIT: The third command 'works', the chat bit is printed but the URL is opened up. I'm sure that the dropbox .html file is good as I can view it in my web browser via that link! EDIT 2: Also why does my loading url only come up as black? [code] +sv_loadingurl "https://dl.dropboxusercontent.com/u/49149597/Gmod%20Server/loadurl.html" [/code] Is it something to do with dropbox not having www. before all the links? My google site used to work, except that was [code] +sv_loadingurl "www.sites.google.com/site/thofurl/home" [/code] All I did for that was add "www." after 'https://'
Sorry, you need to Log In to post a reply to this thread.