09-12-2014, 06:22 AM 
		
	
	
		If you want to send a message to all players, you could use broadcast.
cRoot:Get():BroadcastChat()
	
	
	
	
cRoot:Get():BroadcastChat()
| 
					I can't create any commands.
				 | 
| 
		
		
		09-12-2014, 06:22 AM 
		
	 
		If you want to send a message to all players, you could use broadcast. cRoot:Get():BroadcastChat() (09-12-2014, 05:59 AM)LO1ZB Wrote: Why do you use the same function for a Hook and a command? 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. 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 
		
		
		09-12-2014, 07:36 AM 
		
	 (09-12-2014, 07:15 AM)Lo_Pan Wrote: I saw it on a wiki example. 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.   (09-12-2014, 07:36 AM)LO1ZB Wrote: If you set return to true inside the function: 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. (09-12-2014, 08:24 AM)Lo_Pan Wrote: That's the problem, I have no idea what I'm doing! When you change the name of the function, which is called in the hook, you have to create a function with that name.   (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?! 
-- This will initialize the plugin to the server.
function Initialize(Plugin)
        Plugin:SetName("STONED")
        Plugin:SetVersion(1)
        
        -- Hooks
        
        cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, PluginInfo);        
        cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, RollJoint);
        cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, SmokeJoint);       
        PLUGIN = Plugin
         
        -- Command Bindings
        
        cPluginManager.BindCommand("/pi", "STONED.pi", PluginInfo, " - display plugin version."); -- PluginInfo binding
        cPluginManager.BindCommand("/j", "STONED.j", RollJoint, " - player is rolling a joint."); -- RollJoint binding       
        cPluginManager.BindCommand("/l", "STONED.l", SmokeJoint, " - player is smoking a joint."); -- SmokeJoint binding
        
        LOG("Initialised " ..Plugin:GetName() .. " v." .. Plugin:GetVersion())
        return true
end
function OnDisable()
        LOG(PLUGIN:GetName() .. " is shutting down!")
end
-- Commands
-- PluginInfo
function PluginInfo(Player, pi)
        Player:SendMessage("§eSTONED v1.0.0.3")
        return false
end
-- RollJoint: 
function RollJoint(Player, j)
        cRoot:Get():BroadcastChat("§b" .. Player:GetName() .. " is rolling a joint.")
        return false
end
-- SmokeJoint:
function SmokeJoint(Player, l)
        cRoot:Get():BroadcastChat("§b" .. Player:GetName() .. " is smoking a joint.")
        return false
end
function Initialize(Plugin)
        Plugin:SetName("STONED")
        Plugin:SetVersion(1)
        PLUGIN = Plugin
         
        -- Command Bindings
        
        cPluginManager.BindCommand("/pi", "STONED.pi", PluginInfo, " - display plugin version."); -- PluginInfo binding
        cPluginManager.BindCommand("/j", "STONED.j", RollJoint, " - player is rolling a joint."); -- RollJoint binding       
        cPluginManager.BindCommand("/l", "STONED.l", SmokeJoint, " - player is smoking a joint."); -- SmokeJoint binding
        
        LOG("Initialised " .. Plugin:GetName()  .. " v." .. Plugin:GetVersion())
        return true
end
function OnDisable()
        LOG(PLUGIN:GetName() .. " is shutting down!")
end
-- PluginInfo
function PluginInfo(Player)
        Player:SendMessage("§eSTONED v1.0.0.3")
        return true
end
-- RollJoint: 
function RollJoint(Player)
        cRoot:Get():BroadcastChat("§b" .. Player:GetName() .. " is rolling a joint.")
        return true
end
-- SmokeJoint:
function SmokeJoint(Player)
        cRoot:Get():BroadcastChat("§b" .. Player:GetName() .. " is smoking a joint.")
        return true
end
		
		
		09-12-2014, 07:37 PM 
		
	 
		Gentlemen, please post your code with [ shcode=lua ] tag, not the [ php ] tag. Thank you.
	 
		
		
		09-12-2014, 07:39 PM 
		
	 
		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.
	 
		
		
		09-12-2014, 07:45 PM 
		
	 
		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. 
-- PluginInfo
function PluginInfo(a_Split, a_Player)
        a_Player:SendMessage("§eSTONED v1.0.0.3")
        return true
end
 
-- RollJoint:
function RollJoint(a_Split, a_Player)
        if (a_Split[2] ~= nil) then
                -- The player gave us a parameter for the command:
                cRoot:Get():BroadcastChat("§b" .. a_Player:GetName() .. " is rolling a joint with an extra " .. a_Split[2] .. " inside.")
        else
                -- There was no parameter, so it's a simple joint:
                cRoot:Get():BroadcastChat("§b" .. a_Player:GetName() .. " is rolling a joint.")
        end
        return true
end
 
-- SmokeJoint:
function SmokeJoint(a_Split, a_Player)
        cRoot:Get():BroadcastChat("§b" .. a_Player:GetName() .. " is smoking a joint.")
        return true
end
 | 
| 
					« Next Oldest | Next Newest »
				 |