General > Developers Corner

2 Command Scripts interfering...

(1/1)

Jaden Zepeda:
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: ---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 )
--- End code ---

Group.lua

--- Code: ---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 )
--- End code ---

JamminR:
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.

--- End quote ---

Jaden Zepeda:

--- Quote from: JamminR 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 )

--- End quote ---

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

JamminR:
It's the small details that will get you everytime.
You're welcome.

Navigation

[0] Message Index

Go to full version