Blocktrix
Welcome, Guest. Please Login or Register.
11/28/21 at 1:30pm

Home Home Help Help Search Search Login Login Register Register


Pages: 1
Help writing script (Read 28 times)
erp-matic
New Member
*


Tetridome.com

Posts: 14
Help writing script
09/14/08 at 12:13pm
 
I'm looking for some help in writing a simple script...
 
How would i write a script that would output 2 lines of text every 20 seconds and i would beable to start and end the running of the script by typing "/script1" or something like that?
Back to top
 
 
Email View Profile WWW sonsitdown   IP Logged
strikelight
Administrator
*****


Make Me King

Posts: 288
Re: Help writing script
Reply #1 - 09/14/08 at 12:47pm
 
Ok, I'll do this step by step, just so it's more instructional than just doing it for you.. I'll have it all together at the end of the post..
 
First, for your trigger, we would need to create an event binding for outbound partyline chat, which we would do as such:
 
Code:
addbind pmsgout erp:start
# erp:start will be our procedure bound to outbound partyline chat
 


 
Now, we will need to make the actual code to check the out-going text for the trigger:
Code:
proc erp:start {text} {
# grab the first 'word' of the outgoing text, and make it lowercase
  set cmd [string tolower [lindex [split $text] 0]]
# compare the cmd to what we are looking for
  if {$cmd == "/script1"} {
    # we'll need access to a global variable to check if script is running
    global erp
    # check that global variable now
    if {![info exists erp(timer)]} {
    # variable doesn't exist, or is currently turned off
      # create a timer event
      set erp(timer) [after 20000 erp:timer]
      # send a message saying we've started
      plinelog "Erp Timer started..."
    } else {
      # it was already on, let's turn it off
      catch {after cancel $erp(timer)}
      catch {unset erp(timer)}
      # display a message we've turned it off
      plinelog "Erp Timer disabled"
    }
  }
}
 


 
  Next, we'll need the actual timer code for the proc we are calling in the above code:
 
Code:
proc erp:timer {} {
  # define the lines of text
  set lines [list "line1 goes here" "line2 goes here"]
  # next loop through our lines
  foreach line $lines {
    # display the line
    plinemsg $line
  }
 # re-fire the timer
  global erp
  set erp(timer) [after 20000 erp:timer]
}
 


 
And done...
So putting it all together we get a small script like such:
 
Code:
addbind pmsgout erp:start
proc erp:start {text} {
  set cmd [string tolower [lindex [split $text] 0]]
  if {$cmd == "/script1"} {
    global erp
    if {![info exists erp(timer)]} {
      set erp(timer) [after 20000 erp:timer]
      plinelog "Erp Timer started..."
    } else {
      catch {after cancel $erp(timer)}
      catch {unset erp(timer)}
      plinelog "Erp Timer disabled"
    }
  }
}

proc erp:timer {} {
  set lines [list "line1 goes here" "line2 goes here"]
  foreach line $lines {
    plinemsg $line
  }
  global erp
  set erp(timer) [after 20000 erp:timer]
}

plinelog "erp-timer.tcl loaded"
 


 
Hope this helps...
Back to top
 
« Last Edit: 09/14/08 at 4:02pm by strikelight »  

-=) StrikeLight
-=) Blocktrix developer
-=) www.blocktrix.org
Email View Profile WWW   IP Logged
erp-matic
New Member
*


Tetridome.com

Posts: 14
Re: Help writing script
Reply #2 - 09/14/08 at 3:48pm
 
yes i believe that makes sense... i cant figure out how to edit the .tcl files or create my own. How do i do so?
Back to top
 
 
Email View Profile WWW sonsitdown   IP Logged
strikelight
Administrator
*****


Make Me King

Posts: 288
Re: Help writing script
Reply #3 - 09/14/08 at 4:01pm
 
Notepad or wordpad... and just save with a .tcl extension.
Back to top
 
 

-=) StrikeLight
-=) Blocktrix developer
-=) www.blocktrix.org
Email View Profile WWW   IP Logged
erp-matic
New Member
*


Tetridome.com

Posts: 14
Re: Help writing script
Reply #4 - 09/14/08 at 4:17pm
 
thx... my computer was being dumb b4.. i just reinstalled everything and was able to do it. thx!!!
Back to top
 
 
Email View Profile WWW sonsitdown   IP Logged
Pages: 1