Help needed with mirc script

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Hi guys,

Hoping someone here can help me with this script as i seem to be doing my nut in on this one. Basically what this script is going to do is the following:
When someone types !uptime , the bot will first message the channel with it's own uptime, and then it will message the server's ( wow server for my lan ) uptime by querying column 'uptime' in table 'uptime' in databse 'realmd'.

The problem I'm having is i seem to be getting errors such as "* /if: insufficient parameters (line 4, uptime.mrc) " and if i remove that line it just shows the same thing just on a different line, if state aswell.

I'm sort of okay with c++, but throw in sql scripting and a slightly different format mirc scripting uses, i tend to just lose it.

Code is
on *:TEXT:!uptime:#:{
msg $chan $me has been online for $uptime(mirc,1) $+ .
var %sql = $mysql_connect(localhost, 3306, 18475, realmd, trinity,trinity)
if ( $portfree(3443) != $true ){
var %test = $mysql_query(%sql, SELECT uptime FROM uptime WHERE `realmid` = 1 ORDER BY `starttime` DESC LIMIT 1 )
var %uptime = $mysql_fetch_row(%test,1)
var $secs = (%uptime % 60)
var $mins = (%uptime / 60 % 60)
var $hours = (%uptime / 3600 % 24)
var $days = (%uptime / 86400)

if ( %days > 0 ){
msg $chan Server uptime: $days days, %hours hours, %minutes minutes and %secs seconds.
}
elseif ( %hours > 0 ) {
msg $chan Server uptime: %hours hours, %minutes minutes and %secs seconds.

}
elseif ( %mins > 0 ){
msg $chan Server uptime: %minutes minutes and %secs seconds.
}
elseif ( %secs > 0 ){
msg $chan Server uptime: %secs seconds.
}
else { msg $chan Server not online }
}

}

As far as the $portfree parameter goes, i don't see a problem with it not recognizing as i have another script running a different command which has the exact same line, just doesn't want to work here.

Just shout if you need anymore info
 
Last edited:

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
The best thing to do when struggeling with SQL is to get the query to work in the server first, then take it into code.

You may have two problems:
  1. table and column the same name
  2. column name in quotes

try something like
Code:
SELECT [tblUptime].[uptime] FROM uptime AS [tblUptime] WHERE [realmid] = 1 ORDER BY [starttime] DESC LIMIT 1

You don't have to put the square brackets in but i suppose it's good practice...

I don't do SQL that much, and haven't worked with mysql since varsity, but something like that should work...
 

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
closing } in the if statement?

Code:
on *:TEXT:!uptime:#:
{
	msg $chan $me has been online for $uptime(mirc,1) $+ .
	var %sql = $mysql_connect(localhost, 3306, 18475, realmd, trinity,trinity)
	if ( $portfree(3443) != $true )
	{
		var %test = $mysql_query(%sql, SELECT uptime FROM uptime WHERE `realmid` = 1 ORDER BY `starttime` DESC LIMIT 1 )
		var %uptime = $mysql_fetch_row(%test,1)
		var $secs = (%uptime % 60)
		var $mins = (%uptime / 60 % 60)
		var $hours = (%uptime / 3600 % 24)
		var $days = (%uptime / 86400)

		if ( %days > 0 )
		{
			msg $chan Server uptime: $days days, %hours hours, %minutes minutes and %secs seconds.
		}
		elseif ( %hours > 0 ) 
		{
			msg $chan Server uptime: %hours hours, %minutes minutes and %secs seconds.
		}
		elseif ( %mins > 0 )
		{
			msg $chan Server uptime: %minutes minutes and %secs seconds.
		}
		elseif ( %secs > 0 )
		{
			msg $chan Server uptime: %secs seconds.
		}
		else 
		{ 
			msg $chan Server not online 
		}
	}
}

Looks fine to me ? Notepad++ is my new best friend
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Query definitely works, i have checked it. reason my column and table is the same is because there is a column named 'uptime' in table 'uptime' strange i know.

Plus the first error hits line 4 saying "/if (insufficient parameters)". So what i did, just to pass that for the time being was scrapped that line, i.e. took it out complete. Then calling it again, the error comes back but this time hits line 12 instead of line 4. Also since no errors were encountered between these lines, im assuming that the code is correct.

As far as { are concerned, counting all the opening and closing {} i end up with 0 so im guessing thats not the problem either. It has something to do with the parameter of the /if statements, infact all of them, which i assume are the statements inside the brackets which it is not recognising for what reason i don't know as i've declared the variables.

It probably has something to do with the weird way mirc's scripting language works, which can be a bugger to figure out
 

Drake2007

Expert Member
Joined
Oct 23, 2008
Messages
4,413
Heh, I wrote a bot for mIRC that went spamming for a cell phone app that my bro wrote.
It got K-lined regularly.

Just checking you have realmid and uptime fields in the uptime table? Confusing that, try give stuff more unique names.
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Just checking you have realmid and uptime fields in the uptime table?.
Yup like i said, ive run the query through phpmyadmin and returns the correct result

Confusing that, try give stuff more unique names.
Meaning?

Edit: SQL Querry result
Code:
Showing rows 0 - 0 (1 total, Query took 0.0166 sec)
SELECT uptime
FROM uptime
WHERE `realmid` =1
ORDER BY `starttime` DESC
LIMIT 1
 
Last edited:

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
According to this your syntax seems correct:

Code:
if (<value1> <operator> <value2>) { <commands> }

Maybe try this:
Code:
if ([b]![/b]$portfree(3443)){

[b]And be carefull of your variable names:[/b]
var $days = (%uptime / 86400)
if ( %days > 0 )

[b]Shouldn't that be[/b]
var $days = (%uptime / 86400)
if ( [b]$[/b]days > 0 )

???
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Ye sorry bout that, was trying to troubleshoot by changing the % with $ and visa versa. I was probably half way through changing it back before i posted. my bad :erm:

Anyways same error, insufficient parameters. I have come to a conclusion mirc is worst than a women on pms and it's error reporting is left much to be desired.

But i'll try anything, it won't get me that easily
 

Drake2007

Expert Member
Joined
Oct 23, 2008
Messages
4,413
try assign $portfree(3443) to a variable before using it in the If test case?

I agree mirc's scripting language is rather counter intuitive, have to debug everything with echo statements.
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Ok, so im doing what i think would be the best way to get it up to the end, or thats the way i was taught in C++. Start basic and add on from there.

Sooo, i've scrapped the portfree thing and all if statements, just a basic query, fetch and then print.

New code:
Code:
on *:TEXT:!uptime:#:{
  msg $chan $me has been online for $uptime(mirc,1) $+ .
  var %sql = $mysql_connect(localhost, 3306, 18475, realmd, trinity,trinity)
  
  var %test = $mysql_query(%sql, SELECT uptime FROM uptime WHERE `realmid` = 1 ORDER 

                                                       BY `starttime` DESC LIMIT 1 )
  var %uptime = $mysql_fetch_row( %test,1 )
  var %secs = ( %uptime % 60 )
  var %mins = ( %uptime / 60 % 60 )
  var %hours = ( %uptime / 3600 % 24 )
  var %days = ( %uptime / 86400 )
           msg $chan Server Uptime = $+ %days $+ day(s) $+ %hours $+ hour(s) $+ 

%mins $+ minute(s) and  $+ %secs $+ seconds
            

 }

No errors but get the following output.

[23:49] <Toady> !uptime
[23:49] <WoWBot> WoWBot has been online for 12hrs 13mins 1sec.
[23:49] <WoWBot> Server Uptime =( SQLrowDE270B0C / 86400 )day(s)( SQLrowDE270B0C / 3600 % 24 )hour(s)( SQLrowDE270B0C / 60 % 60 )minute(s) and( SQLrowDE270B0C % 60 )seconds

So, the var are getting fetched properly, not sure what that SQLrowDE... is all about but im assuming the fetch row is incorrect as the results returned to %uptime is incorrect
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
i've tried every single combination thinkable (%test,1) and (%test,0)

if i put the 1 or 0 first then i get No such Com '1' open (line 123, mysql.mrc)

mysql.mrc handles all the mysql connects and interactions
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
im surprised no one has slapped mirc owner in the face for making scripting so hard. Probably find kark like this would drive a man insane but i guess thats the worst part of programming.. fault finding
 

Drake2007

Expert Member
Joined
Oct 23, 2008
Messages
4,413
http://www.mircscripts.org/comments.php?cid=1393

you call the query with mysql_query, then you retrieve the results with $mysql_getfield(). It is important to keep in mind that you must use $mysql_getfield() only AFTER the query has completed. Usually you would retrieve the results in the "on 1:SIGNAL:mysql:{" event. For an example of how to do this, please refer to the mysql_qds.mrc script file, or to the bottom part of the main mysql.mrc script.

That the same script though?
 
Top