Blocktrix Forums
https://www.blocktrix.net/cgi-bin/Ya.cgi
Blocktrix >> Script Requests and Scripting Help >> Help writing script
https://www.blocktrix.net/cgi-bin/Ya.cgi?num=1221412405

Message started by erp-matic on 09/14/08 at 12:13pm

Title: Help writing script
Post by erp-matic on 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?

Title: Re: Help writing script
Post by strikelight on 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...

Title: Re: Help writing script
Post by erp-matic on 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?

Title: Re: Help writing script
Post by strikelight on 09/14/08 at 4:01pm

Notepad or wordpad... and just save with a .tcl extension.

Title: Re: Help writing script
Post by erp-matic on 09/14/08 at 4:17pm

thx... my computer was being dumb b4.. i just reinstalled everything and was able to do it. thx!!!

Blocktrix Forums