Author Topic: request script  (Read 11523 times)

clEEn

  • Newbie
  • *
  • Posts: 21
request script
« on: October 04, 2008, 03:01:09 PM »
Can someone make a script like this: If i type like /! Invite (NICK) #channel and the Person I just invited join the channel, the script user give the guy op (+o).

juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #1 on: October 05, 2008, 05:26:20 AM »
Well i have script with does the task as required (details below). Save it as *.ice (Icechat 5 Script) file.

Code: [Select]
Dim Users()
Redim Users(0)
'The array storing names

'the function handling joins
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
    mynick = lcase(GetIdentifier("$me",ServerNumber))
    if InArray(Nickname, Users) = true then
        if isop(mynick, Channel, ServerNumber) then
            SendCommand "/mode "& Channel &" +o "&Nickname, ServerNumber
        end if
    end if
End Sub

'the function handling user input (doesn't handle menu items)
Function OUTTEXT(OutgoingText)
    ServerNumber = GetIdentifier("$currentservernumber")
    if left(OutgoingText, 8) = "/invite " then
        Tmp=mid(OutgoingText,9)
        Pos = instr(lcase(Tmp)," ")
        if Pos > 0 then
            Name = left (Tmp, Pos-1)
            Chan = mid(Tmp, Pos+1)
            if AddItem(Name) = false then SendCommand "/echo Nick "& Name &" already in list...", ServerNumber
        end if
    end if
    OUTTEXT = OutgoingText
End Function

'update dynamic array
function AddItem(name)
    if InArray(name, Users) = false then
        Size = UBound(Users)
        Users(Size) = name
        Size = Size+1
        Redim Preserve Users(Size)
        AddItem = true
    else
        AddItem = false
    end if
end function

'remove item from array
Sub RemItem(name)
    For i = 0 to UBound(Users)
        if (Users(i) = name) then
            Size = UBound(Users) - 1
            For j = i To Size
                Users(j) = Users(j + 1)
            Next
            ReDim Preserve Users(Size)
        end if
    Next
end Sub

'check if in array
Function InArray(item,A)
    For i=0 To UBound(A) Step 1
        If A(i)=item Then
            InArray=True
            Exit Function
        End If
    Next
    InArray=False
End Function

The folowing works as:
1. user types invite command with keyboard
2. script stores his name in array
3. other user joins and gets invited
4. script removes his name from array

P.s. this script may be buggy. Please provide info then.

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #2 on: October 05, 2008, 07:09:57 AM »
ok, i will test now :)

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #3 on: October 05, 2008, 08:07:23 AM »
It works just fine mate, thx alot!

juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #4 on: October 05, 2008, 09:12:16 AM »
A little bugfix (replace some functions above with these below):

In the join handling function a function call missed. Update:
Code: [Select]
'the function handling joins (fixed)
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
    mynick = lcase(GetIdentifier("$me",ServerNumber))
    if InArray(Nickname, Users) = true then
        if isop(mynick, Channel, ServerNumber) then
            RemItem(Nickname)
            SendCommand "/mode "& Channel &" +o "&Nickname, ServerNumber
        end if
    end if
End Sub

Another error was in array item removal. Update:
Code: [Select]
'remove item from array (fixed)
Sub RemItem(name)
    For i = 0 to UBound(Users)
        if (Users(i) = name) then
            For j = i To Size
                Users(j) = Users(j + 1)
            Next
            Size = Size - 1
            ReDim Preserve Users(Size)
            exit sub
        end if
    Next
end Sub

These updates fix security issue when not invited users may use remaining nick to get in. And now entry is being removed succefully. The behavior of script didn't change.
« Last Edit: October 05, 2008, 09:14:33 AM by juozas »

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #5 on: October 05, 2008, 09:37:00 AM »
Ok, i got this, I just added on the "mynick" to [FS]SundbomA, but it wont work..

Quote
Dim Users()
Redim Users(0)
'The array storing names

'the function handling joins (fixed)
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
    [FS]SundbomA = lcase(GetIdentifier("$me",ServerNumber))
    if InArray(Nickname, Users) = true then
        if isop([FS]SundbomA, Channel, ServerNumber) then
            RemItem(Nickname)
            SendCommand "/mode "& Channel &" +o "&Nickname, ServerNumber
        end if
    end if
End Sub

'the function handling user input (doesn't handle menu items)
Function OUTTEXT(OutgoingText)
    ServerNumber = GetIdentifier("$currentservernumber")
    if left(OutgoingText, 8) = "/invite " then
        Tmp=mid(OutgoingText,9)
        Pos = instr(lcase(Tmp)," ")
        if Pos > 0 then
            Name = left (Tmp, Pos-1)
            Chan = mid(Tmp, Pos+1)
            if AddItem(Name) = false then SendCommand "/echo Nick "& Name &" already in list...", ServerNumber
        end if
    end if
    OUTTEXT = OutgoingText
End Function

'update dynamic array
function AddItem(name)
    if InArray(name, Users) = false then
        Size = UBound(Users)
        Users(Size) = name
        Size = Size+1
        Redim Preserve Users(Size)
        AddItem = true
    else
        AddItem = false
    end if
end function

'remove item from array (fixed)
Sub RemItem(name)
    For i = 0 to UBound(Users)
        if (Users(i) = name) then
            For j = i To Size
                Users(j) = Users(j + 1)
            Next
            Size = Size - 1
            ReDim Preserve Users(Size)
            exit sub
        end if
    Next
end Sub

'check if in array
Function InArray(item,A)
    For i=0 To UBound(A) Step 1
        If A(i)=item Then
            InArray=True
            Exit Function
        End If
    Next
    InArray=False
End Function






juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #6 on: October 05, 2008, 09:47:52 AM »
it couldn't work becouse mynick is variable name and on it is stored yout current nick. if you remove the [ and ] chars on text you placed it may work.

if you want fixed nick, replace line
Code: [Select]
mynick = lcase(GetIdentifier("$me",ServerNumber))(there where it was) with
Code: [Select]
mynick = "[FS]SundbomA"
Also second line where variable mynick was, unchanged and you'll have static nick

And use [ code ] tag instead of [ quote ] (remove spaces)
« Last Edit: October 05, 2008, 09:50:43 AM by juozas »

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #7 on: October 05, 2008, 09:53:19 AM »
i get this error:

[18:52]  ->> ERROR:modScriptFunctions:invite.ice:Function:LoadScriptFile:End Function Error Number:1006 : Expected ')'

juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #8 on: October 05, 2008, 09:57:54 AM »
did you removed [ and ] on your var name (where you placed your name?). Only a-z, A-Z and 0-9 chars are allowed (i think), no [, ] and (, ) symbols

) means symbol that close function

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #9 on: October 05, 2008, 10:06:39 AM »
did you removed [ and ] on your var name (where you placed your name?). Only a-z, A-Z and 0-9 chars are allowed (i think), no [, ] and (, ) symbols

) means symbol that close function

where u mean?

juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #10 on: October 05, 2008, 10:09:59 AM »
did you removed [ and ] on your var name (where you placed your name?). Only a-z, A-Z and 0-9 chars are allowed (i think), no [, ] and (, ) symbols

) means symbol that close function

where u mean?
i mean you have to remove symbols [ and ] in text [FS]SundbomA - it's variable name, not a value... if it still not works copy original, replace functions and leave unchanged.

Be sure what do you do before changing anything

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #11 on: October 05, 2008, 10:12:51 AM »
so how i type it? like FSSundbomA?

juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #12 on: October 05, 2008, 10:14:43 AM »
yes, or remove line with

[FS]SundbomA = (etc.)

and in second nick have it in quotes

clEEn

  • Newbie
  • *
  • Posts: 21
Re: request script
« Reply #13 on: October 05, 2008, 10:35:37 AM »
im confused, can u type the whole script with name [FS]SundbumA or what nick it was?

juozas

  • Newbie
  • *
  • Posts: 13
Re: request script
« Reply #14 on: October 05, 2008, 10:56:53 AM »
Well, the code with all changes (nick is quoted):

Code: [Select]
Dim Users()
Redim Users(0)
'The array storing names

'the function handling joins (fixed)
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
    'the line were here is removed
    if InArray(Nickname, Users) = true then
        if isop("[FS]SundbumA", Channel, ServerNumber) then
            'notice [FS]SundbumA is in quotes
            RemItem(Nickname)
            SendCommand "/mode "& Channel &" +o "&Nickname, ServerNumber
        end if
    end if
End Sub

'the function handling user input (doesn't handle menu items)
Function OUTTEXT(OutgoingText)
    ServerNumber = GetIdentifier("$currentservernumber")
    if left(OutgoingText, 8) = "/invite " then
        Tmp=mid(OutgoingText,9)
        Pos = instr(lcase(Tmp)," ")
        if Pos > 0 then
            Name = left (Tmp, Pos-1)
            Chan = mid(Tmp, Pos+1)
            if AddItem(Name) = false then SendCommand "/echo Nick "& Name &" already in list...", ServerNumber
        end if
    end if
    OUTTEXT = OutgoingText
End Function

'update dynamic array
function AddItem(name)
    if InArray(name, Users) = false then
        Size = UBound(Users)
        Users(Size) = name
        Size = Size+1
        Redim Preserve Users(Size)
        AddItem = true
    else
        AddItem = false
    end if
end function

'remove item from array (fixed)
Sub RemItem(name)
    For i = 0 to UBound(Users)
        if (Users(i) = name) then
            For j = i To Size
                Users(j) = Users(j + 1)
            Next
            Size = Size - 1
            ReDim Preserve Users(Size)
            exit sub
        end if
    Next
end Sub

'check if in array
Function InArray(item,A)
    For i=0 To UBound(A) Step 1
        If A(i)=item Then
            InArray=True
            Exit Function
        End If
    Next
    InArray=False
End Function
« Last Edit: October 05, 2008, 10:58:48 AM by juozas »