TriggerBoy Script

DCH++ has been abandoned, this forum serves mainly as an archive

Moderator: Moderators

Locked
bugayev
Posts: 9
Joined: 2005-01-05 00:02

TriggerBoy Script

Post by bugayev » 2005-01-17 02:02

Ok. I have my hub up and running (thanks again to everyone who helped with that) and I've installed the TriggerBoy script.

However, I want to edit it slightly so that it will trigger when i type, say -punch hub --> then displaying "bugayev punches hub".

I can get it to do this quite easily - I just added a new variable called [parm] which subsitutes everything EXCEPT the trigger word.

This is great.

BUT

How can I tell the script to only trigger if -punch appears at the start of a line:

so it works for "-punch hub"

but not for "to punch, type -punch followed by the name of the thing you want to hit."

(at the moment, it says "bugayev punches followed by the name of the thing you want to hit")

Can anyone shed any light on how I can do this?

shufty
Posts: 11
Joined: 2004-01-30 03:08

Post by shufty » 2005-01-17 04:32

Code: Select all

local punch = string.sub( msg, 1, 10 )
if punch == "-punch hub" then 
dchpp.sendToAll( "* "..client:getNick().." punches hub|" ) 
return dchpp.ACTION_STOP 
end
not looked at lua much, but i think this should do it

yakko
Posts: 258
Joined: 2003-01-27 01:04
Contact:

Post by yakko » 2005-01-17 18:56

there's a Me.lua script on the DCH++ page that does IRC style /me commands. My hub users really like that one.

bugayev
Posts: 9
Joined: 2005-01-05 00:02

Post by bugayev » 2005-01-18 02:37

Ok, so I tried using the /me script instead. However, when I try and add any more commands, nothing gets parsed..

Any LUA/DCH++ gurus got any pointers that I may be missing?

Thanks

FleetCmd
Posts: 22
Joined: 2003-05-20 12:19
Location: Hungary
Contact:

Post by FleetCmd » 2005-01-18 04:41

bugayev wrote:Ok, so I tried using the /me script instead. However, when I try and add any more commands, nothing gets parsed..

Any LUA/DCH++ gurus got any pointers that I may be missing?

Thanks
Could you post the script you made?

bugayev
Posts: 9
Joined: 2005-01-05 00:02

Post by bugayev » 2005-01-18 19:45

sorry, i completely forgot! :P

Code: Select all

--Action script by Ben Carmichael
--Taken from the /me script by Sedulus


dchpp.loadLib( "math" )


function dchpp.clientMessage( client, msg ) 
	
	local user = client:getNick()
	local cmd = nil
	local parm = nil

	--substitutes for 3 letter commands
	
	local cmd = string.sub( msg, 1, 4 ) 
	
	if cmd == "+me " or cmd == "/me " then 
		dchpp.sendToAll( "* "..user.." "..string.sub( msg, 5 ).."|" ) 
		return dchpp.ACTION_STOP 
	end 

	--substitutes for 4 letter commands

	cmd = string.sub( msg, 1, 5 )
	parm = string.sub( msg, 5 )

	local answer
	local action

	if cmd == "-slap " or cmd == "+slap " then
		
		local numberOfOptions = 3

		action = {

		[1] answer = user.." slaps "..parm,
		[2] answer = user.." hits "..parm.." in the face with a rotting fish!",
		[3] answer = user.." spanks "..parm.."!",

		}

		local p = math.random(numberOfOptions)

		action[p]

		answer = user.." slaps "..parm

		dchpp.sendToAll( "* "..user.." slaps "..parm.."|" ) 
		return dchpp.ACTION_STOP 

	end
	
	if cmd == "-nuke " or cmd == "+nuke " then

		local numberOfOptions = 2

		action = {

		[1] answer = user.." authorises a nuclear strike against "..parm.." and launches missiles!",
		[2] answer = "Forces under the control of "..user.." find "..parm.." and carry out a deadly nuclear strike!",

		}

		local p = math.random(numberOfOptions)

		action[p]
	
	end


	
	
	--substitutes for 5 letter commands

		
	cmd = string.sub( msg, 1, 6 )
	parm = string.sub( msg, 6 )

	if cmd == "-punch " or cmd == "+punch " then

		local numberOfOptions = 2

		action = {

		[1] answer = user.." punches "..parm.." in the nose!",
		[2] answer = user.." punches "..parm.."!",
		}

		local p = math.random(numberOfOptions)

		action[p]

	end


		dchpp.sendToAll( "* "..answer.."|" ) 
		return dchpp.ACTION_STOP 


end
It's not the most efficient way of doing it, obviously. The script DOES work when i comment out everything after the /me, but doesnt work for any of the other conditions. I've tried it with /me commented out and other stuff active, but that doesn't work. I'm completely stumped.

PseudonympH
Forum Moderator
Posts: 366
Joined: 2004-03-06 02:46

Post by PseudonympH » 2005-01-18 20:40

Code: Select all

	if cmd == "-slap " or cmd == "+slap " then
		
		local numberOfOptions = 3

		action = {

		[1] answer = user.." slaps "..parm,
		[2] answer = user.." hits "..parm.." in the face with a rotting fish!",
		[3] answer = user.." spanks "..parm.."!",

		}

		local p = math.random(numberOfOptions)

		action[p]

		answer = user.." slaps "..parm

		dchpp.sendToAll( "* "..user.." slaps "..parm.."|" ) 
		return dchpp.ACTION_STOP 

	end
I don't know what you're trying to do here, but that sure as hell looks like incorrect lua code to me. Try this:

Code: Select all

if cmd == "-slap " or cmd == "+slap " then

	local action = {
		user.." slaps "..parm,
		user.." hits "..parm.." in the face with a rotting fish!",
		user.." spanks "..parm.."!",
	}

	local p = math.random( table.getn(action) )

	dchpp.sendToAll( "* "..action[p].."|" ) 
	return dchpp.ACTION_STOP 
end
You'll need to make the rest look like this code as well, of course. :)

yakko
Posts: 258
Joined: 2003-01-27 01:04
Contact:

Post by yakko » 2005-01-18 22:40

the /me script appends what the user adds so

Code: Select all

/me slaps everyone in the hub
would say

Code: Select all

*yakko slaps everyone in the hub
You don't need to add a bunch of stuff then...let the users get creative with it themselves.

bugayev
Posts: 9
Joined: 2005-01-05 00:02

Post by bugayev » 2005-01-18 23:35

Well, I tried substituting PseudoNymph's LUA for my own and there's still nothing. i even went so far as to put it into a new script, but nothing happened.

Is there some kind of restriction on the use of SendToAll which could be stopping the message from being sent?

Am I missing some critical piece of code?

This is really starting to frustrate me.

Yakko - my users do use /me for a lot of the stuff they do to each other! Its a great script, I just want to provide a few shortcuts and fun ones for them to have without having to type the full sentence. I managed to get it working under SDCH, but that was vbscript and I have to say I'm a lot better at that than LUA!

FleetCmd
Posts: 22
Joined: 2003-05-20 12:19
Location: Hungary
Contact:

Post by FleetCmd » 2005-01-19 02:42

cmd = string.sub( msg, 1, 5 )
parm = string.sub( msg, 5 )

local answer
local action

if cmd == "-slap " or cmd == "+slap " then
Your substring is only five characters long (string.sub: 1, 5), but in the if-then-condition, the "-slap " is 6... You should modify the cmd = ... lines to add one more character because of the spaces.

bugayev
Posts: 9
Joined: 2005-01-05 00:02

Post by bugayev » 2005-01-19 07:57

brilliant!

unfortunately, it still doesnt work :(.

for some reason, every time i have more than one set of triggers, NONE of them work. If i comment everything except /me, then /me works.

:?: :?: :?: :?:

Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 09:32
Contact:

Post by Sedulus » 2005-01-19 08:21

Code: Select all

-- vim:ts=4:sw=4:noet

dchpp.loadLib( "math" )

local function oneOf( tbl ) return tbl[math.random( table.getn( tbl ) )] end

local Actions = {
    ["+me"] = function( nick, arg )
        return "* " .. nick .. " " .. arg
    end,
    ["/me"] = function( nick, arg )
        return "* " .. nick .. " " .. arg
    end,
    ["+slap"] = function( nick, arg )
        return oneOf( {
            "* " .. nick .. " slaps " .. arg,
            "* " .. nick .. " hits " .. arg .. " in the face with a rotten fish",
            "* " .. nick .. " spanks " .. arg,
        } )
    end,
}

function dchpp.clientMessage( client, msg )
    local ret,_,cmd,arg = string.find( msg, "^(%S+)%s+(.*)$" )
    if not ret then
        return
    end
    if Actions[cmd] then
        dchpp.sendToAll( Actions[cmd]( client:getNick(), arg ) .. "|" )
        return dchpp.ACTION_STOP
    end
end
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)

bugayev
Posts: 9
Joined: 2005-01-05 00:02

Post by bugayev » 2005-01-19 21:33

Thanks Sedulus *bows down and worships*

That's done the trick nicely!

Thanks to everyone who helped me with this one - its greatly appreciated!

PseudonympH
Forum Moderator
Posts: 366
Joined: 2004-03-06 02:46

Post by PseudonympH » 2005-01-20 15:50

Showoff :P

Locked