Page 1 of 1

GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 8:17 am
by lokaum
Hello People,

The problem is:

Code: Select all

Compiling: c:\cr2a\pkg\opt\uuogetstatus\getstatus.src
Token '(' cannot follow token 'StrFormatTime'
Function StrFormatTime() is not defined.
Error compiling statement at c:\cr2a\pkg\opt\uuogetstatus\getstatus.src, Line 66
Error in function 'UUOLog', File: c:\cr2a\pkg\opt\uuogetstatus\getstatus.src, Line 68

Error in function UUOLog
File: c:\cr2a\pkg\opt\uuogetstatus\getstatus.src, Line 68

Getstatus.src:

Code: Select all

use os;
use uo;
use file;
use util;
use basic;
use basicio;

program Install()

	Print("Loaded: GetStatus...");
	return 1;

endprogram

const RQST_TYPE_STATS := 0x04;
const RQST_TYPE_SKILLS := 0x05;
const OFFSET_REQUEST_TYPE := 0x05;
const OFFSET_MOB_SERIAL := 0x06;

exported function OnGetStatus(mobile, byref packet)

	var request_type := packet.GetInt8(OFFSET_REQUEST_TYPE);

	case ( request_type )
		RQST_TYPE_STATS:
			var mob_serial := packet.GetInt32(OFFSET_MOB_SERIAL);
			var mob_lookup := SystemFindObjectBySerial(mob_serial);
			if ( mob_lookup )
				if ( mobile.Serial != mob_lookup.Serial )
					if ( mob_lookup.Concealed )
						if ( mobile.CMDLevel )
							return 0;
						else
							UUOLog(mobile, mob_lookup, "Defender: Concealed");
							return 1;
						endif
					elseif ( mob_lookup.Hidden )
						if ( mobile.CMDLevel )
							return 0;
						else
							UUOLog(mobile, mob_lookup, "Defender: Hidden");
							return 1;
						endif
					elseif ( Distance(mobile, mob_lookup) > 23 )
						if ( mobile.CMDLevel )
							return 0;
						else
							UUOLog(mobile, mob_lookup, "Defender Distance: "+Distance(mobile, mob_lookup));
							return 1;
						endif
					endif
				endif
			endif
		default:
			return 0;
	endcase

	return 0;

endfunction

function UUOLog(attacker, defender, description)

	if ( defender.IsA(POLCLASS_NPC) )
		return 1;
	endif

	var date := StrFormatTime("%m/%d/%y at %I:%M:%S %p");
	var text_log := Array{};
	text_log.Append("UUOGetStatus - "+date);
	text_log.Append("	Attacker	"+attacker.name+" ["+attacker.acctname+"]"+" ["+attacker.ip+"]");
	text_log.Append("	Defender	"+defender.name+" ["+defender.acctname+"]"+" ["+defender.ip+"]");
	text_log.Append("	Action		"+description);
	text_log.Append("");
	text_log.Append("");

	var result := AppendToFile(":UUOGetStatus:UUOGetStatus.txt", text_log);

endfunction
Can anyone help me?

Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 9:48 am
by runtest
StrFormatTime()

Where is this defined?
I do not see it in the docs?

If its a custom, where is that stored?

Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 9:51 am
by Pierce
Util:StrFormatTime is from Pol97.
If you use Pol95 you have to write your own function for that.
Perhaps it's possible that you'll find a file named time.inc in your
scripts/include/ folder. Depending on your script base.

Here is an old one from i think Pol 94 that should do what you need:

Code: Select all

const yearlen := 3600*24*365;
const leadyearlen := 3600*24*366;
const daylen := 3600*24;
const hourlen := 3600;
const minlen := 60;

function GetTimeString()

var abstime := polcore().systime;

var year := 1970;
var month := 1;
var day :=1;
var hour :=0;
var mn :=0;

while(abstime >= yearlen)
	if(mod_fast(year,4) ==0) //LeadYear
		abstime := abstime-leadyearlen;
	else
		abstime := abstime-yearlen;
	endif
	year := year+1;
endwhile

var monthlenlist := { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, };
var monthname:={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec",};

if(mod_fast(year,4) ==0)
	monthlenlist[2] := 29;
endif

var monthlen := monthlenlist[month]*daylen;

//find the month
while(abstime  >= monthlen)
	abstime := abstime-monthlen;
	month := month+1;
	monthlen := monthlenlist[month]*daylen;
endwhile

//the day
while(abstime >= daylen)
	abstime := abstime-daylen;
	day := day+1;
endwhile

//find the hour
while(abstime >= 3600)
	abstime := abstime-3600;
	hour := hour+1;
endwhile

//minute
while(abstime >= 60)
	abstime := abstime-60;
	mn := mn+1;
endwhile

var macro :=0;

if ((hour>=6) && (hour<=13))
macro := (13 - hour);
if (macro==0)
macro :=666;
endif
endif

if (macro==666)
  return "Macroing is allowed for another " + (60 - mn) + " mins";
endif

if (macro==0)
  return "Macroing is not allowed at this time, you will be jailed when caught";
else
  return "Macroing is allowed for another " + macro + " hrs " + (60 - mn) + " mins";
endif

endfunction

function GetDate()

var abstime := polcore().systime;

var year := 1970;
var month := 1;
var day :=1;
var hour :=0;
var mn :=0;

while(abstime >= yearlen)
	if(mod_fast(year,4) ==0) //LeadYear
		abstime := abstime-leadyearlen;
	else
		abstime := abstime-yearlen;
	endif
	year := year+1;
endwhile

var monthlenlist := { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, };
var monthname:={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec",};

if(mod_fast(year,4) ==0)
	monthlenlist[2] := 29;
endif

var monthlen := monthlenlist[month]*daylen;

//find the month
while(abstime  >= monthlen)
	abstime := abstime-monthlen;
	month := month+1;
	monthlen := monthlenlist[month]*daylen;
endwhile

//the day
while(abstime >= daylen)
	abstime := abstime-daylen;
	day := day+1;
endwhile

//return (monthname[month] + " " + day + ", " + year );
return (day + "." + month + "." + year );

endfunction

function GetFormatedDate(format)

var abstime := polcore().systime;

var year := 1970;
var month := 1;
var mm := "01";
var dd := "01";
var day :=1;
var hour :=0;
var mn :=0;

while(abstime >= yearlen)
	if(mod_fast(year,4) ==0) //LeadYear
		abstime := abstime-leadyearlen;
	else
		abstime := abstime-yearlen;
	endif
	year := year+1;
endwhile

var monthlenlist := { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
var monthname:={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"};

if(mod_fast(year,4) ==0)
	monthlenlist[2] := 29;
endif

var monthlen := monthlenlist[month]*daylen;

//find the month
while(abstime  >= monthlen)
	abstime := abstime-monthlen;
	month := month+1;
	monthlen := monthlenlist[month]*daylen;
	if(month < 10)
		mm := ("0"+ CStr(month));
	else
		mm := month;
	endif
endwhile

//the day
while(abstime >= daylen)
	abstime := abstime-daylen;
	day := day+1;
	if(day < 10)
		dd := ("0"+ CStr(day));
	else
		dd := day;
	endif
endwhile

case (format)
	"yyyymmdd"	 :	return (CStr(year) + CStr(mm) + CStr(dd));
	"yyyy.mm.dd" :	return (year + "." + mm + "." + dd);
	"dd.mm.yyyy" :	return (dd + "." + mm + "." + year );
	"d.m.yyyy"	 :	return (day + "." + month + "." + year );
	"mon day year" : return (monthname[month] + " " + day + ", " + year );
	"ddmm"		: return (CStr(dd) +" " +monthname[month]);
endcase

endfunction


function mod_fast(n,d)
var ndbl := CDbl(n)/CDbl(d);
var nint := CDbl(n/d);
if(ndbl > nint)
	var rest := (ndbl-nint)*CDbl(d);
	if(rest > CDbl(CInt(rest)) )
		rest := CInt(rest)+1;
	else
		rest := CInt(rest);
	endif
	return rest;
else
	return 0;
endif

endfunction

function GetFormatedTime(format)

var abstime := polcore().systime;

var year := 1970;
var month := 1;
var mm := "01";
var dd := "01";
var day :=1;
var hour :=0;
var mn :=0;
var hh := 0;
var mi := 0;
var ss := 0;

while(abstime >= yearlen)
	if(mod_fast(year,4) ==0) //LeadYear
		abstime := abstime-leadyearlen;
	else
		abstime := abstime-yearlen;
	endif
	year := year+1;
endwhile

var monthlenlist := { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
var monthname:={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"};

if(mod_fast(year,4) ==0)
	monthlenlist[2] := 29;
endif

var monthlen := monthlenlist[month]*daylen;

//find the month
while(abstime  >= monthlen)
	abstime := abstime-monthlen;
	month := month+1;
	monthlen := monthlenlist[month]*daylen;
	if(month < 10)
		mm := ("0"+ CStr(month));
	else
		mm := month;
	endif
endwhile

//the day
while(abstime >= daylen)
	abstime := abstime-daylen;
	day := day+1;
	if(day < 10)
		dd := ("0"+ CStr(day));
	else
		dd := day;
	endif
endwhile

//the hour
while(abstime >= hourlen)
	abstime := abstime-hourlen;
	hour := hour+1;
	if(hour < 10)
		hh := ("0"+ CStr(hour));
	else
		hh := hour;
	endif
endwhile

//the minute
while(abstime >= minlen)
	abstime := abstime-minlen;
	mn := mn+1;
	if(mn < 10)
		mi := ("0"+ CStr(mn));
	else
		mi := mn;
	endif
endwhile

ss := abstime;
if(ss < 10)
 ss := "0" + CStr(ss);
endif

case (format)
	"hhmmss"	 :	return (CStr(hh) + CStr(mi) + CStr(ss));
	"hh:mm:ss" :	return (hh + ":" + mi + ":" + ss);
	"hh" :		return (hh);
	"mm" :		return (mi);
endcase

endfunction


Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 11:19 am
by lokaum
Pierce,

this script that you keep here... is to players don't see staffers hidden, right?

Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 12:06 pm
by Pierce
Huh?
No, that is an include file. If you put these lines i wrote above inside e.g. scripts/include/time.inc
you can rewrite your script without the StrFormatTime that your Pol95 Server don't
accept.

Your script will then look this way (4 lines changed/added):

Code: Select all

use os;
use uo;
use file;
use util;
use basic;
use basicio;

include "include/time";

program Install()

Print("Loaded: GetStatus...");
return 1;

endprogram

const RQST_TYPE_STATS := 0x04;
const RQST_TYPE_SKILLS := 0x05;
const OFFSET_REQUEST_TYPE := 0x05;
const OFFSET_MOB_SERIAL := 0x06;

exported function OnGetStatus(mobile, byref packet)

var request_type := packet.GetInt8(OFFSET_REQUEST_TYPE);

case ( request_type )
RQST_TYPE_STATS:
var mob_serial := packet.GetInt32(OFFSET_MOB_SERIAL);
var mob_lookup := SystemFindObjectBySerial(mob_serial);
if ( mob_lookup )
if ( mobile.Serial != mob_lookup.Serial )
if ( mob_lookup.Concealed )
if ( mobile.CMDLevel )
return 0;
else
UUOLog(mobile, mob_lookup, "Defender: Concealed");
return 1;
endif
elseif ( mob_lookup.Hidden )
if ( mobile.CMDLevel )
return 0;
else
UUOLog(mobile, mob_lookup, "Defender: Hidden");
return 1;
endif
elseif ( Distance(mobile, mob_lookup) > 23 )
if ( mobile.CMDLevel )
return 0;
else
UUOLog(mobile, mob_lookup, "Defender Distance: "+Distance(mobile, mob_lookup));
return 1;
endif
endif
endif
endif
default:
return 0;
endcase

return 0;

endfunction

function UUOLog(attacker, defender, description)

if ( defender.IsA(POLCLASS_NPC) )
return 1;
endif

var format := "yyyymmdd";
var format2 := "hhmmss";
var date := "[" + GetFormatedDate(format) + GetFormatedTime(format2)+ "]";
var text_log := Array{};
text_log.Append("UUOGetStatus - "+date);
text_log.Append(" Attacker "+attacker.name+" ["+attacker.acctname+"]"+" ["+attacker.ip+"]");
text_log.Append(" Defender "+defender.name+" ["+defender.acctname+"]"+" ["+defender.ip+"]");
text_log.Append(" Action "+description);
text_log.Append("");
text_log.Append("");

var result := AppendToFile(":UUOGetStatus:UUOGetStatus.txt", text_log);

endfunction


Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 1:34 pm
by MontuZ
095 doesn't support packethooks or did I miss something?

Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 2:36 pm
by Pierce
You're right MontuZ. I didn't realize the exported function.
My mistake. I'am on 97 for my excuse :)
But nevertheless, if lokaum puts it in a 95 way it will work.
I think MontuZ will give you the right 95 answer now, lokaum.

Re: GetStatus problem [POL095]

Posted: Fri Aug 22, 2008 6:22 pm
by MontuZ
You mean 096, Pierce? If so then yeah the code they posted for formatting time should work. Also don't forget to set CoreRequired to the current POL version you're using(95/96) otherwise I don't think it'll load when POL starts...

Time isn't really required anyway, I don't remember why I even put it in there, lol.