Jump to content
  • 0

detect users within the map


Question

Recommended Posts

Posted (edited)

Example adding it to items.

2201,Sunglasses,Sunglasses,5,5000,,100,,0,,0,0xFFFFFFFF,7,2,512,,0,0,12,{ callfunc "players2minimap"; },{},{}
Functions:
function	script	players2minimap	{
	While((playerattached()?IsEquipped(.itemid):0)){
		getmapxy(.@N$,.@B,.@C,0);
		while((playerattached()?.@V<($PlayerNumber<=0?.@V+1:$PlayerNumber):0)){
			set .@V,.@V+1; 
			if(isloggedin(getd("$RecordAID"+.@V))) getmapxy(.@map$,.@x[.@V],.@y[.@V],0,rid2name(getd("$RecordAID"+.@V)));
			if( .@N$ == .@map$ && getd("$RecordAID"+.@V) != getcharid(3) && isloggedin(getd("$RecordAID"+.@V))){
				viewpoint 1,.@x[.@V],.@y[.@V],.@V,0xFF0000;
			}
			if(.@V>=$PlayerNumber){
				sleep2 1+.delay;
				for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1) viewpoint 2,.@x[.@i],.@y[.@i],.@i,0xFF0000;
			}
		}
		if(playerattached()){ set .@V,0; } else { break; }
	}
	end;
	
OnInit:
	//=-=-=-=-=Configuration=-=-=-=-=-=
	set .delay,0; // Delay between refresh in Milliseconds. Default is one Millisecond.
	set .itemid,2201; // ID of item being used.
	//You can change the color of the markers
	//By searching for "FF0000" and replacing
	//It with a Hexidecimal number.
	//=-=-=-=-=-=-=Skorm=-=-=-=-=-=-=-=
	//Credits to goddameit for 
	//file architecture and  BlackHoleEvent.
	//Special thanks to joelolopez for
	//The idea, and testing. <3
}

-	script	BlackHoleEvent	-1,{
OnPCLoginEvent:
	setd "$RecordAID"+set($PlayerNumber,$PlayerNumber+1),getcharid(3);
	end;
OnInit:
OnTimer1000:
	initnpctimer;
OnPCLogoutEvent:
	for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1)
	{
		if(!isloggedin(getd("$RecordAID"+.@i)))
		{
			set $PlayerNumber,$PlayerNumber-1;
			setd "$RecordAID"+.@i,getd("$RecordAID"+(.@i+1));
			setd "$RecordAID"+(.@i+1),0;
			set .@i,.@i-1;
		}
	}
	end;
}
Tested small update to make sure the script fully runs after unequipped. Fully working done!

Edited by Skorm
  • Upvote 1
Posted (edited)

-	script	fi	-1,{
OnWhisperGlobal:
	if(!getgmlevel())
		end;
	getmapxy(.@N$,.@B,.@C,0);
	while( .@V < $PlayerNumber ){
		set .@V,.@V+1;
		getmapxy(.@map$,.@x,.@y,0,rid2name(getd("$RecordAID"+.@V)));
		if( .@N$ == .@map$ && getarg(3) == "" )||( getarg(3) != "" && getarg(3) == .@map$ ){
			viewpoint 0,.@x,.@y,.@V,0xFF0000;
		}
	}
}

-	script	BlackHoleEvent	-1,{
OnPCLoginEvent:
	setd "$RecordAID"+set($PlayerNumber,$PlayerNumber+1),getcharid(3);
	end;
OnInit:
OnTimer5000:
	initnpctimer;
	for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1)
	{
		if(!isloggedin(getd("$RecordAID"+.@i)))
		{
			if(!getd("$RecordAID"+.@i))
			{
				set $PlayerNumber,0;
				break;
			}
			setd "$RecordAID"+.@i,getd("$RecordAID"+(.@i+1));
			setd "$RecordAID"+(.@i+1),0;
			set .@i,.@i-1;
		}
	}
	end;
}

I think only 3 of them can be on the map at once... but w/e.

Edited by Skorm
Posted (edited)

I forgot to remove some old parts it's working now. I'm going to make one that updates constantly though give me a sec.

-	script	fis	-1,{
OnWhisperGlobal:
	if(!getgmlevel())
		end;
	getmapxy(.@N$,.@B,.@C,0);
	while( .@V < $PlayerNumber ){
		set .@V,.@V+1;
		getmapxy(.@map$,.@x,.@y,0,rid2name(getd("$RecordAID"+.@V)));
		if( .@N$ == .@map$ ){
			viewpoint 0,.@x,.@y,.@V,0xFF0000;
		}
	}
}

-	script	BlackHoleEvent	-1,{
OnPCLoginEvent:
	setd "$RecordAID"+set($PlayerNumber,$PlayerNumber+1),getcharid(3);
	end;
OnInit:
OnTimer5000:
	initnpctimer;
	for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1)
	{
		if(!isloggedin(getd("$RecordAID"+.@i)))
		{
			if(!getd("$RecordAID"+.@i))
			{
				set $PlayerNumber,0;
				break;
			}
			setd "$RecordAID"+.@i,getd("$RecordAID"+(.@i+1));
			setd "$RecordAID"+(.@i+1),0;
			set .@i,.@i-1;
		}
	}
	end;
}
Edited by Skorm
Posted (edited)

Lol I see where you're going with this.

- script fis -1,{OnWhisperGlobal:if(!getgmlevel())end;getmapxy(.N$,.B,.C,0);if(atoi(@whispervar0$)>0&&.s>0) {dispbottom "Player View is already active!";end;} else if(!atoi(@whispervar0$)){set .s,0;dispbottom "Closing View!";end;} else {set .s,1;dispbottom "Activating View!";}setnpctimer 0; attachnpctimer(strcharinfo(0)); startnpctimer;sleep2 2;while(.V<$PlayerNumber&&.s){set .V,.V+1;getmapxy(.map$,.x,.y,0,rid2name(getd("$RecordAID"+.V)));if( .N$ == .map$ ){viewpoint 1,.x,.y,.V,0xFF0000;sleep2 1;viewpoint 2,.x,.y,.V,0xFF0000;}if(.V>=$PlayerNumber) set .V,0;}sleep2 14999;end;OnTimer1:stopnpctimer;sleep2 1;set .Q,$PlayerNumber;while(.Q>0&&.s){set .Q,.Q-1;getmapxy(.@map$,.@x,.@y,0,rid2name(getd("$RecordAID"+.Q)));if( .N$ == .@map$ ){sleep2 1;viewpoint 1,.@x,.@y,.Q,0xFF0000;sleep2 1;viewpoint 2,.@x,.@y,.Q,0xFF0000;}if(.Q<=1) set .Q,$PlayerNumber;}end;}- script BlackHoleEvent -1,{OnPCLoginEvent:setd "$RecordAID"+set($PlayerNumber,$PlayerNumber+1),getcharid(3);end;OnInit:OnTimer5000:initnpctimer;for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1){if(!isloggedin(getd("$RecordAID"+.@i))){if(!getd("$RecordAID"+.@i)){set $PlayerNumber,0;break;}setd "$RecordAID"+.@i,getd("$RecordAID"+(.@i+1));setd "$RecordAID"+(.@i+1),0;set .@i,.@i-1;}}end;}

^ Can't be called from a function because of the Timer I added to try and fix the blinking, but I'll remove that re-add the character variables and call it from a function inside an item.

npc:fis 1 to activate 0 to disable.

Edit:

- script fis -1,{OnWhisperGlobal:if(!getgmlevel())end;getmapxy(.@N$,.@B,.@C,0);if(atoi(@whispervar0$)>0&&.@s>0) {dispbottom "Player View is already active!";end;} else if(!atoi(@whispervar0$)){set .@s,0;dispbottom "Closing View!";end;} else {set .@s,1;dispbottom "Activating View!";}while(.@V<$PlayerNumber&&.@s){set .@V,.@V+1;getmapxy(.@map$,.@x[.@V],.@y[.@V],0,rid2name(getd("$RecordAID"+.@V)));if( .@N$ == .@map$ ){viewpoint 1,.@x[.@V],.@y[.@V],.@V,0xFF0000;}if(.@V>=$PlayerNumber){sleep2 1;for(set .@i,1;.@i<$PlayerNumber;set .@i,.@i+1) viewpoint 2,.@x[.@i],.@y[.@i],.@i,0xFF0000;set .@V,0;}}end;}

^ much better way of doing it no more blinking ^_^. Sorry Forums keeps putting my code into one line. T_T

Edited by Skorm
Posted (edited)

sir can you do it like this

 

when headgear equipped

 

menu appear

 

selection detect and cancel

 

when the user select "detect"

 

then the players within the map will appear on

the mini map with blinking marks.

Edited by joelolopez
Posted

Probably not what I plan to do is just activate when you equipped the headgear and when you remove it, the markings will go away. No menu because bleh. I'll add that after I'm done if you still want it.

Right now I'm just working out the best way to show the markings.

Posted (edited)

Example adding it to items.

2201,Sunglasses,Sunglasses,5,5000,,100,,0,,0,0xFFFFFFFF,7,2,512,,0,0,12,{ callfunc "players2minimap"; },{},{}
Functions:
function	script	players2minimap	{
OnWhisperGlobal:
	While((playerattached()?IsEquipped(2201):0)){
		if(!playerattached()){ end; }
		getmapxy(.@N$,.@B,.@C,0);
		while((playerattached()?.@V<($PlayerNumber<=0?.@V+1:$PlayerNumber):0)){
			if(!playerattached()){ end; }
			set .@V,.@V+1; 
			if(isloggedin(getd("$RecordAID"+.@V))) getmapxy(.@map$,.@x[.@V],.@y[.@V],0,rid2name(getd("$RecordAID"+.@V)));
			if( .@N$ == .@map$ && getd("$RecordAID"+.@V) != getcharid(3) && isloggedin(getd("$RecordAID"+.@V))){
				viewpoint 1,.@x[.@V],.@y[.@V],.@V,0xFF0000;
			}
			if(.@V>=$PlayerNumber){
				sleep2 1;
				for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1) viewpoint 2,.@x[.@i],.@y[.@i],.@i,0xFF0000;
			}
		}
		if(playerattached()){ set .@V,0; } else { break; }
	}
	end;
}

-	script	BlackHoleEvent	-1,{
OnPCLoginEvent:
	setd "$RecordAID"+set($PlayerNumber,$PlayerNumber+1),getcharid(3);
	end;
OnInit:
OnTimer1000:
	initnpctimer;
OnPCLogoutEvent:
	for(set .@i,1;.@i<=$PlayerNumber;set .@i,.@i+1)
	{
		if(!isloggedin(getd("$RecordAID"+.@i)))
		{
			set $PlayerNumber,$PlayerNumber-1;
			setd "$RecordAID"+.@i,getd("$RecordAID"+(.@i+1));
			setd "$RecordAID"+(.@i+1),0;
			set .@i,.@i-1;
		}
	}
	end;
}
Tested small update to make sure the script fully runs after unequipped. Fully working done!

Post moved to answered post.

Edited by Skorm
Posted (edited)

sir its working great!!! but there still some bugs left like when i unequip the headgear the function still running

 

i still able to detect players w/o the headgear

Edited by joelolopez
Posted

Yeah It's fixed now the script wasn't running for a final time after the glasses were unequipped. Just added a second loop to fix the problem. Make sure you restart your server after implementing the new script. Thanks.

Posted (edited)

Hmm, how many players did you test it with? I updated the script a little bit the last loop wasn't running enough to remove all the icons, and you should stop double posting just update your existing post I refresh the page.

Edit: I'm getting no infinity loop, and it is detecting players on the map previously. The only problem I seem to have is after warping off the map the red dots still exist from the previous map. but I know how to fix that as well.

Edited by Skorm
Posted (edited)

Make sure you're grabbing my code from that same post after refreshing the page because I'm updating it as you find buggs. Also REMEMBER to restart your server after you added the code, because @reloadscripts is tricky with functions. Thanks.

Also I think you're having problems because the OnEquipped area of the item script only runs when the item's equipped try moving it to the first section, but I might need to add something to avoid stack continuum error.

Edited by Skorm
Posted (edited)

yep i know that sir lol ,

 

just another update sir when you login w/o the headgear the function wont run

unless you're going to logout again wearing the headgear

 

and when you login again that is the time u will be able to detect the players 1 by 1

 

1 logout and login 1 player detected ,some times all players are gone

Edited by joelolopez
Posted

I was able to emulate that infinity loop you were talking about. I added some kind of insanity check lol I had a few sleep2 1; in there aswell and it wasn't doing it but I think I got the problem so I took them out.

Posted

I think this is happening because when you logout with it on you literally break the function because it's still looping and looking for the account, and being a function it doesn't spit out that information to the prompt. Meh I can remove character variables and instead make temporary npc variables for each account using the glasses. Alternativly we might just beable to unequipped them when the user logs out with the OnPCLogoutEvent label.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...