Author Topic: 2 Command Scripts interfering...  (Read 1896 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
2 Command Scripts interfering...
« on: December 20, 2014, 02:55:48 PM »
I have 2 lua files, group.lua and donate.lua, both in my autorun server. Lets say I lua_openscript group.lua and lua_openscript donate.lua right after, only !donate works because it was the last one I ran, is there a way to make it so both of them work at the same time?

Donate.lua
Code: [Select]
function donateCommand( pl, text, teamonly )
    if (text == "!donate") then
    pl:SendLua([[gui.OpenURL("http://sites.google.com/site/bigmacssw/donate")]]) -- Change ADDRESS to your chosen page.
end
end
hook.Add( "PlayerSay", "Chat", donateCommand )

Group.lua
Code: [Select]
function groupCommand( pl, text, teamonly )
    if (text == "!group") then
    pl:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/sandboxwars")]]) -- Change ADDRESS to your chosen page.
end
end
hook.Add( "PlayerSay", "Chat", groupCommand )


Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: 2 Command Scripts interfering...
« Reply #1 on: December 20, 2014, 03:14:41 PM »
Your hook add command uses the same "identifier" for both commands. "Chat"
That middle term has to be unique, or it overwrites previous.
From hook.Add
hook.Add( string eventName, any identifier, function func )
Quote
any identifier
The unique identifier, usually a string. This can be used to replace or remove existing hooks. If the identifier is not a string and IsValid(identifier) returns false on the hook's call, the hook will be removed.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: 2 Command Scripts interfering...
« Reply #2 on: December 20, 2014, 03:24:13 PM »
Your hook add command uses the same "identifier" for both commands. "Chat"
That middle term has to be unique, or it overwrites previous.
From hook.Add
hook.Add( string eventName, any identifier, function func )

Wow, Im so stupid I can't believe I missed that! Thanks alot!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: 2 Command Scripts interfering...
« Reply #3 on: December 20, 2014, 09:07:42 PM »
It's the small details that will get you everytime.
You're welcome.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming