This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Need some help with mirc-script to tcl

Old posts that have not been replied to for several years.
Locked
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Need some help with mirc-script to tcl

Post by zeuz »

It feels like i'm asking for too much, but it's worth a try. Currently i'm running the script on my own client (mirc). I would like to use my eggdrop to run the script instead.

What the script does is answer on !lexp <from-level> <to-level> <optional: exp per item> with experience between from-level and to-level, and, if stated, calculates amount of items needed for that amount of experience. (It's for a game called runescape.)

I know that this may be too much to ask for, but it would be greatly appreciated. Some lines is in swedish, so ask if you don't understand. I have never worked with tcl, but have some basic knowledge in c++ and some other languages, so any hints and things like that is welcome.

Here's the code:

Code: Select all

alias levelexp {
  var %outputnum = 0
  var %points = 0
  var %lvl = 1
  while (%lvl < $$1) {
    %points = $int($calc(%points + %lvl + 300 * 2 ^ (%lvl / 7.0)))
    %outputnum = $int($calc(%points / 4))
    inc %lvl 1 
  }
  return $int(%outputnum)
}

alias tusen {
  var %word = $null
  var %length = $len($$1)
  var %i = 0
  var %left = 0  
  while (%i < %length) {
    var %pos = $calc(%length - %i - 2)
    if (%pos <= 0) { %left = $left($$1, $calc(%length - %i)) }    
    else { %left = $mid($$1, %pos, 3) }
    %word = %left %word
    inc %i 3  
  }
  return %word
}

alias lexp {
  if ($nick != $null) var %nick = $nick
  else %nick = $me  
  if ($$1 !isnum 1-1000) {
    .notice %nick Syntax error! Använd !lexp <level> <level> utan streck
    halt
  }
  if ($1 > 150 || $2 > 150) {
    .notice %nick För hög högsta level! Max är 150! 
    halt
  } 
  else if ($2) {
    var %expsak = $3
    var %lvls = $calc($$2 - $$1)
    var %expkvar = $calc($levelexp($$2) - $levelexp($$1))
    if ($3) {
      msg # Level $$1 $+ - $+ $$2 $+ : $tusen(%expkvar) exp - Antal "Saker": $tusen($int($calc(%expkvar / %expsak)))       
    }
    else {  
      msg # Level $$1 $+ - $+ $$2 $+ : $tusen(%expkvar) exp
    }
  }
  else {
    msg # Level 1 $+ - $+ $$1 $+ : $tusen($levelexp($$1)) exp 
  } 
}

on *:TEXT:!lexp*:#runescape.se:{ $lexp($$2, $3, $4) }
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Tried to write it myself, this is how it look likes this far:

Code: Select all

bind pub - !lexp  msg:levelexp

proc msg:levelexp { nick uhost handle channel firstlevel } {
    set outputnum 0
    set points 0
    set level 1

    while {$level < $firstlevel} {
        set points [expr $points + $level + 300 * pow(2,$level / 7.0)]
        set outputnum [expr $points / 4]
        incr $level
    }
    puthelp "PRIVMSG $channel :$firstlevel - $outputnum experience"
    return 0
}
Any help is very much appreciated, this is my first tcl script ever (if it counts since it don't work as planned :P), started to read some a couple of hours ago.
Last edited by zeuz on Mon May 02, 2005 1:52 pm, edited 1 time in total.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

If you trace the code, so we can understand it more (since, atleast me, we don't know mirc language very well), then we can provide more help on this script.
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Code: Select all

alias levelexp {
  var %outputnum = 0
  var %points = 0
  var %lvl = 1
  while (%lvl < $$1) {
    %points = $int($calc(%points + %lvl + 300 * 2 ^ (%lvl / 7.0)))
    %outputnum = $int($calc(%points / 4))
    inc %lvl 1
  }
  return $int(%outputnum)
} 
Is a function that calculates the experience for the stated level. $$1 is the level stated when calling the function. I didn't make the formula for it though. Need to know anything more about it?

This is the error im getting:
Tcl error [msg:levelexp]: can't read "1": no such variable

Same function in php if that helps:

Code: Select all

function GetLevelExperience($level)
{
	$outputnum = 0;
	$points = 0;
	$lvl = 1;
	while($lvl < $level) {
		$points += floor($lvl + 300 * pow(2, $lvl / 7.0));
		$outputnum = floor($points / 4);
		$lvl++;
	}
	return $outputnum;
}
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Anyone knows what i've done wrong?
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

"incr $level" should be "incr level" (gets rid of the error, dont know if it'll do what you expect)
photon?
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Works now, thanks spock! :)

Now for the other part, not sure on how to solve that.

What i want it to do is when !lexp is used in a channel it will call lexp. lexp will then check to see if the user tries something funny, like going over level 99 or trying with negative numbers etc. When that is checked and ok it should msg the channel with the help of rslvlexp wich returns the experience needed for a stated level, or the experience between two levels.

Example:
<user> !lexp 14
<bot> Level 1-14: xxx exp
<user> !lexp 14 21
<bot> Level 14-21: xxx exp

This is how the script currently looks like:

Code: Select all

bind pub - !lexp lexp

#
# returns amount of experience needed for the stated level
#
proc rslvlexp { nick uhost handle channel firstlevel } {
    set outputnum 0
    set points 0
    set level 1

    while {$level < $firstlevel} {
        set points [expr floor($points + $level + 300 * pow(2,$level / 7.0))]
        set outputnum [expr round(floor($points / 4))]
        incr level
    }
    #puthelp "PRIVMSG $channel :$firstlevel - $outputnum experience"
    return $outputnum
}

#
# proc to call when !lexp is used
#
proc lexp { nick uhost handle channel firstlevel secondlevel } {


    return 0
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

lets take
!lexp 14
for an example.

you want to pass 14 to rslvlexp and then output the result ?

Also, if 2 numbers were entered with !lexp (for example !lexp 14 21) what should be done with the other ?
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Yup, thats how i want it to work. If the user enters two levels it should return the experience between thoose. Something like this: rslvlexp(21) - rslvlexp(14).
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

Code: Select all

bind pub - !lexp lexp 
proc rslvlexp p { 
  set points 0
  set level 1
  while {$level<$p} {
    set points [expr floor($points + $level + 300 * pow(2,$level / 7.0))] 
    incr level 
  }
  set outputnum [expr round(floor($points / 4))]
} 

proc lexp {n u h c a} { 
  if ![llength [split $a]] return
  if {[scan $a "%s %s" f s] < 2} { 
    if {$f<=0||$f>99} return
    puthelp "PRIVMSG $c :[rslvlexp $f]"
  } {
    if {$f<=0||$f>99||$s<=0||$s>99} return
    puthelp "PRIVMSG $c :[expr [rslvlexp $s] - [rslvlexp $f]]"
  }
  return
}
photon?
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Thats great, thanks! :) Just one more thing, how can i add a third argument? As the mirc-script is now you can type !lexp 5 10 20 and get the amount of items needed for that amount of experience. Like !lexp <level1> <level2> <experience you get when doing something>

[expr [rslvlexp $s] - [rslvlexp $f] / $x] where $x is the third one...


How can i check that $s, $f and... $x? is numeric? Just noticed that some people tend to try chars...
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

bind pub - !lexp lexp 
proc rslvlexp p { 
  set points 0 
  set level 1 
  while {$level<$p} { 
    set points [expr floor($points + $level + 300 * pow(2,$level / 7.0))] 
    incr level 
  } 
  set outputnum [expr round(floor($points / 4))] 
} 

proc lexp {n u h c a} { 
  if ![llength [split $a]] return 
  if {[scan $a "%s %s %s" f s x] == 1} { 
    if {$f<=0||$f>99} return 
    puthelp "PRIVMSG $c :[rslvlexp $f]" 
  } elseif {[scan $a "%s %s %s" f s x] == 2} { 
    if {$f<=0||$f>99||$s<=0||$s>99} return 
    puthelp "PRIVMSG $c :[expr [rslvlexp $s] - [rslvlexp $f]]" 
  } elseif {[scan $a "%s %s %s" f s x] == 3} {
    if {$f<=0||$f>99||$s<=0||$s>99||$x<=0||$x>99} return 
    puthelp "PRIVMSG $c :[expr {([rslvlexp $s] - [rslvlexp $f]) / $x}]"
  }
  return 
}
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

Code: Select all

bind pub - !lexp lexp 
proc rslvlexp p { 
  set points 0
  set level 1
  while {$level<$p} {
    set points [expr floor($points + $level + 300 * pow(2,$level / 7.0))] 
    incr level 
  }
  set outputnum [expr round(floor($points / 4))]
} 
proc lexp {n u h c a} { 
  if ![llength [split $a]] return
  foreach n [split $a] {
    if {$n<=0||$n>99} {
      puthelp "PRIVMSG $c :something funny happened"
      return
    }
  }
  set n [scan $a "%i %i %i" f s x]
  if {$n<2} { 
    puthelp "PRIVMSG $c :[rslvlexp $f]"
  } elseif {$n<3} {
    puthelp "PRIVMSG $c :[expr [rslvlexp $s] - [rslvlexp $f]]"
  } {
    puthelp "PRIVMSG $c :[expr ([rslvlexp $s] - [rslvlexp $f])/$x]"   
  }
  return
}
edit: bleh! fz beat me. didnt refresh thread before starting :evil:
photon?
z
zeuz
Voice
Posts: 9
Joined: Sun May 01, 2005 4:39 am
Location: Sweden

Post by zeuz »

Thanks both of you! :)
Locked