Posts: 513
Threads: 10
Joined: May 2014
Thanks: 138
Given 89 thank(s) in 75 post(s)
If you want to send a message to all players, you could use broadcast.
cRoot:Get():BroadcastChat()
Posts: 7
Threads: 0
Joined: Sep 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
09-12-2014, 07:15 AM
(This post was last modified: 09-12-2014, 07:22 AM by Lo_Pan.)
(09-12-2014, 05:59 AM)LO1ZB Wrote: Why do you use the same function for a Hook and a command?
It is called first from the hook, then you after sending the message to the player, you are returning "true", which means "hook successfully executed", if you want that the command get executed, you have to return "false".
I saw it on a wiki example.
In other words, i have no idea what that line of code does it seems, as i thought it was needed to make the command(s) work.
If i change true to false, it executes both commands, on just 1 command..
Painfully obvious by now i am a scripting noob!
(09-12-2014, 06:22 AM)Seadragon91 Wrote: If you want to send a message to all players, you could use broadcast.
cRoot:Get():BroadcastChat()
So in stead of this:
-- RollJoint:
function RollJoint(Player, j)
Player:SendMessage("§b" .. Player:GetName() .. " is rolling a joint.")
return false
end
change it to this: ?
-- RollJoint:
function RollJoint(Player, j)
cRoot:Get():BroadcastChat("§b" .. Player:GetName() .. " is rolling a joint.")
return false
end
Posts: 302
Threads: 8
Joined: Feb 2014
Thanks: 48
Given 30 thank(s) in 26 post(s)
(09-12-2014, 07:15 AM)Lo_Pan Wrote: I saw it on a wiki example.
In other words, i have no idea what that line of code does it seems, as i thought it was needed to make the command(s) work.
If i change true to false, it executes both commands, on just 1 command..
Painfully obvious by now i am a scripting noob!
If you set return to true inside the function:
user send command -> enter hook -> enter function -> finish
set it to false:
user send command -> enter hook -> enter function -> enter command handler -> enter function again -> finish
You shouldn't use the same function for both, unless you know what you are doing.
Posts: 7
Threads: 0
Joined: Sep 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
09-12-2014, 08:24 AM
(This post was last modified: 09-12-2014, 08:26 AM by Lo_Pan.)
(09-12-2014, 07:36 AM)LO1ZB Wrote: If you set return to true inside the function:
user send command -> enter hook -> enter function -> finish
set it to false:
user send command -> enter hook -> enter function -> enter command handler -> enter function again -> finish
You shouldn't use the same function for both, unless you know what you are doing.
That's the problem, I have no idea what I'm doing!
I thought the code with the HOOK was part of the command.
If I change the name of that, it fails and I get a "(no name)" error in console.
So I am actually more confused now then 10 minutes ago!
Btw, sorry for hijacking Guandor's topic, but as I had the same problem (in the beginning at least) I thought making a new topic for it would be a bit overkill.
Posts: 302
Threads: 8
Joined: Feb 2014
Thanks: 48
Given 30 thank(s) in 26 post(s)
09-12-2014, 08:34 AM
(This post was last modified: 09-12-2014, 08:34 AM by LO1ZB.)
(09-12-2014, 08:24 AM)Lo_Pan Wrote: That's the problem, I have no idea what I'm doing!
I thought the code with the HOOK was part of the command.
If I change the name of that, it fails and I get a "(no name)" error in console.
So I am actually more confused now then 10 minutes ago!
Btw, sorry for hijacking Guandor's topic, but as I had the same problem (in the beginning at least) I thought making a new topic for it would be a bit overkill.
When you change the name of the function, which is called in the hook, you have to create a function with that name.
Posts: 7
Threads: 0
Joined: Sep 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
09-12-2014, 08:52 AM
(This post was last modified: 09-12-2014, 07:39 PM by xoft.)
(09-12-2014, 08:34 AM)LO1ZB Wrote: When you change the name of the function, which is called in the hook, you have to create a function with that name.
Right, so, the name of the function in the hook is the same as the actuall function, which I have done but still it fails. See code bellow
The hook is PluginInfo and the function is PluginInfo, so that should be right then, right?!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | function Initialize(Plugin)
Plugin:SetName( "STONED" )
Plugin:SetVersion(1)
cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, PluginInfo);
cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, RollJoint);
cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, SmokeJoint);
PLUGIN = Plugin
cPluginManager.BindCommand( "/pi" , "STONED.pi" , PluginInfo, " - display plugin version." );
cPluginManager.BindCommand( "/j" , "STONED.j" , RollJoint, " - player is rolling a joint." );
cPluginManager.BindCommand( "/l" , "STONED.l" , SmokeJoint, " - player is smoking a joint." );
LOG( "Initialised " ..Plugin:GetName() .. " v." .. Plugin:GetVersion())
return true
end
function OnDisable()
LOG(PLUGIN:GetName() .. " is shutting down!" )
end
function PluginInfo(Player, pi)
Player:SendMessage( "§eSTONED v1.0.0.3" )
return false
end
function RollJoint(Player, j)
cRoot:Get():BroadcastChat( "§b" .. Player:GetName() .. " is rolling a joint." )
return false
end
function SmokeJoint(Player, l)
cRoot:Get():BroadcastChat( "§b" .. Player:GetName() .. " is smoking a joint." )
return false
end
|
Posts: 302
Threads: 8
Joined: Feb 2014
Thanks: 48
Given 30 thank(s) in 26 post(s)
09-12-2014, 09:25 AM
(This post was last modified: 09-12-2014, 07:40 PM by xoft.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | function Initialize(Plugin)
Plugin:SetName( "STONED" )
Plugin:SetVersion(1)
PLUGIN = Plugin
cPluginManager.BindCommand( "/pi" , "STONED.pi" , PluginInfo, " - display plugin version." );
cPluginManager.BindCommand( "/j" , "STONED.j" , RollJoint, " - player is rolling a joint." );
cPluginManager.BindCommand( "/l" , "STONED.l" , SmokeJoint, " - player is smoking a joint." );
LOG( "Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
return true
end
function OnDisable()
LOG(PLUGIN:GetName() .. " is shutting down!" )
end
function PluginInfo(Player)
Player:SendMessage( "§eSTONED v1.0.0.3" )
return true
end
function RollJoint(Player)
cRoot:Get():BroadcastChat( "§b" .. Player:GetName() .. " is rolling a joint." )
return true
end
function SmokeJoint(Player)
cRoot:Get():BroadcastChat( "§b" .. Player:GetName() .. " is smoking a joint." )
return true
end
|
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Gentlemen, please post your code with [ shcode=lua ] tag, not the [ php ] tag. Thank you.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Lo_Pan: to implement a command you don't need to use a hook at all. That hook is only for plugins that want to intercept **other plugins' commands** and modify or disable them. For normal command processing, just bind the command, nothing else.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Your callback is wrong. The first parameter the command callback receives is the Split - the text that the player entered, split at each space. The second parameter is the cPlayer object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function PluginInfo(a_Split, a_Player)
a_Player:SendMessage( "§eSTONED v1.0.0.3" )
return true
end
function RollJoint(a_Split, a_Player)
if (a_Split[2] ~= nil ) then
cRoot:Get():BroadcastChat( "§b" .. a_Player:GetName() .. " is rolling a joint with an extra " .. a_Split[2] .. " inside." )
else
cRoot:Get():BroadcastChat( "§b" .. a_Player:GetName() .. " is rolling a joint." )
end
return true
end
function SmokeJoint(a_Split, a_Player)
cRoot:Get():BroadcastChat( "§b" .. a_Player:GetName() .. " is smoking a joint." )
return true
end
|
|