• Override existing command help
    6 replies, posted
Hello, Im designing a Cellphone module for DarkRP, and I need to override the existing /call command. I was talking to FPtje, and he gave me this: [lua] local oldAddChatCommand = AddChatCommand function AddChatCommand(arg1, arg2) if arg1 == "/call" then -- Run my function here return end return AddChatCommand(arg1, arg2) end [/lua] And told me to tide it up. Well I somehow can't get it working. I only get "Timer infinitive looping" warning and it takes ages to load server. So could someone help me out? Thanks :D And yes, I know that the code he gave me doesn't work, but I tried to change it. And it still didn't :P
You making an infinite loop on line 7. Your calling a function , that will call itself , and will then call itself and ... you get the idea. Change like 7 to "return oldAddChatCommend( arg1 , arg2 )"
The code doesn't work because if the command isn't /call then it will loop itself all the time. [lua] local oldAddChatCommand = AddChatCommand function AddChatCommand(arg1, arg2) if arg1 == "/call" then -- Run my function here return end return oldAddChatCommand(arg1, arg2) end [/lua] Should work. If there is anything wrong after that then it's probably your function. [editline]25th September 2011[/editline] Ninja'd
[QUOTE=Blt950;32470693]Hello, Im designing a Cellphone module for DarkRP, and I need to override the existing /call command. I was talking to FPtje, and he gave me this: [lua] local oldAddChatCommand = AddChatCommand function AddChatCommand(arg1, arg2) if arg1 == "/call" then -- Run my function here return end return AddChatCommand(arg1, arg2) end [/lua] And told me to tide it up. Well I somehow can't get it working. I only get "Timer infinitive looping" warning and it takes ages to load server. So could someone help me out? Thanks :D And yes, I know that the code he gave me doesn't work, but I tried to change it. And it still didn't :P[/QUOTE] This is a very very bad methode by the way, I'm pretty sure all chat commands are stored in a table, like similar with normal concommands or hooks. Try to get said table with debug.getupvalue and then store it, "detouring" a function just to add a new command is pretty stupid.
[QUOTE=leiftiger;32470839]The code doesn't work because if the command isn't /call then it will loop itself all the time. [lua] local oldAddChatCommand = AddChatCommand function AddChatCommand(arg1, arg2) if arg1 == "/call" then -- Run my function here return end return oldAddChatCommand(arg1, arg2) end [/lua] Should work. If there is anything wrong after that then it's probably your function. [editline]25th September 2011[/editline] Ninja'd[/QUOTE] Thanks, seems to went one step forward the right way. But not completly working. I tried this to test it: [lua] local oldAddChatCommand = AddChatCommand function AddChatCommand(arg1, arg2) if arg1 == "/call" then print("YOU SHALL PASS") return end return oldAddChatCommand(arg1, arg2) end [/lua] It does not error, or print in server or client console. Something still wrong then maybe? At least the game loads properly now :) But still doesn't work completly as I expect it. [QUOTE=Wizard of Ass;32470921]This is a very very bad methode by the way, I'm pretty sure all chat commands are stored in a table, like similar with normal concommands or hooks. Try to get said table with debug.getupvalue and then store it, "detouring" a function just to add a new command is pretty stupid.[/QUOTE] Interesting, and thanks for the tip. I'm unfortently not that very familiar with "debug.getupvalue", so I can't make this by my self. Unless you could be kind and show your solution for this problem :)
[lua]variableName, chatCommandTable = debug.getupvalue(AddChatCommand,1);[/lua]
[b]Bump.[/b] I'm still stuck now after one week. Current code: The default DarkRP /call command does not respond now. Nothing prints in chat, console (server and client). And it does not call my own /call function. [lua] local oldAddChatCommand = AddChatCommand function AddChatCommand(arg1, arg2) if arg1 == "/call" then MakeACall(arg1, arg2) return end return oldAddChatCommand(arg1, arg2) end function MakeACall(ply, args) if args == "" then return "" end target = FindPlayer(args) // Bla bla bla, working code here. Just removed it since it's not important. return "" end [/lua]
Sorry, you need to Log In to post a reply to this thread.