Page 1 of 1

auto-logoff when coming in contact with someone else

Posted: Sun May 01, 2011 6:54 pm
by Apotheosis
Hello, I figured out how to do everything else I need to do for this one macro... but logoff when coming in contact with someone else who isn't in party. Is there a way to do this? I want a farm a spot, bot not take it over should someone else come.

I've tried searching but have some up empty. If someone could point me in the correct location I would appreciate it.

Thank you.

Re: auto-logoff when coming in contact with someone else

Posted: Sun May 01, 2011 7:56 pm
by rock5
You would have to search by object type so you can search for type "PT_PLAYER". There is no function that does that normally I think but you could use the evalfunc argument in player:findNearestnameOrId() function. Check out my MillersRanchChickens.xml waypoint file for an example on how to do this. I use about 3 separate eval functions in it.

If you need more help, let use know.

Re: auto-logoff when coming in contact with someone else

Posted: Sun May 01, 2011 8:48 pm
by Apotheosis
I will educate myself over the next couple of days and try and get it going. If I have problems, I'll come back with with some test script to see if you can clear it up. Thanks for trying to poke me in the right direction. :mrgreen:

Re: auto-logoff when coming in contact with someone else

Posted: Wed May 04, 2011 9:17 am
by Alkaiser
I made this for myself. No parameters are required.
player:PlayerInRange() in waypoint would scan for players within 300 range and return true if player detected.
You could add more obj.Name conditions after obj.Name ~= "<UNKNOWN>" for the names of party members you don't want to count.

Code: Select all

function CPlayer:PlayerInRange(_range,_X,_Z)
	_range = _range or 300
	_X = _X or self.X
	_Z = _Z or self.Z
	local dist = 0
	local function isInDist(x1, y1, x2, y2, radius)
		if( x2 >= x1-radius and x2 <= x1+radius and
			y2 >= y1-radius and y2 <= y1+radius ) then
			dist = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)
			if( dist <= radius*radius ) then
				dist = math.floor(math.sqrt(dist)+0.5)	
				return true
			else
				return false
			end
		end
		return false
	end
	local found = false
	local doOnce = true
	local obj = nil
	local objectList = CObjectList()
	objectList:update()
	for i = 0,objectList:size() do
		obj = objectList:getObject(i)
		if( obj.Type == PT_PLAYER and obj.Name ~= self.Name and obj.Name ~= "<UNKNOWN>" ) then
			if( isInDist(_X, _Z, obj.X, obj.Z, _range) ) then
				if( doOnce ) then
					cprintf(cli.red,"Player Detection! ")
					printf("NAME\n")
					printf("                  ----\n")
					doOnce = false
				end
				printf("                  %s - ", obj.Name)
				printf("%s\n", dist)
				found = true
			end
		end
	end
	return found
end
I just made an addition (haven't tested yet).
Change "player1","player2" etc. to the names of the players you want to ignore.

Code: Select all

function CPlayer:PlayerInRange(_range,_X,_Z)
	_range = _range or 300
	_X = _X or self.X
	_Z = _Z or self.Z
	local dist = 0
	local function isInDist(x1, y1, x2, y2, radius)
		if( x2 >= x1-radius and x2 <= x1+radius and
			y2 >= y1-radius and y2 <= y1+radius ) then
			dist = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)
			if( dist <= radius*radius ) then
				dist = math.floor(math.sqrt(dist)+0.5)	
				return true
			else
				return false
			end
		end
		return false
	end
	local function evalPlayerName(_name)
		local playerNames = {"player1","player2","player3","player4"}
		for k, v in ipairs(playerNames) do
			if _name == v then return false end
		end
		return true
	end
	local found = false
	local doOnce = true
	local obj = nil
	local objectList = CObjectList()
	objectList:update()
	for i = 0,objectList:size() do
		obj = objectList:getObject(i)
		if( obj.Type == PT_PLAYER and obj.Name ~= self.Name and obj.Name ~= "<UNKNOWN>" and evalPlayerName(obj.Name) ) then
			if( isInDist(_X, _Z, obj.X, obj.Z, _range) ) then
				if( doOnce ) then
					cprintf(cli.red,"Player Detection! ")
					printf("NAME\n")
					printf("                  ----\n")
					doOnce = false
				end
				printf("                  %s - ", obj.Name)
				printf("%s\n", dist)
				found = true
			end
		end
	end
	return found
end

Re: auto-logoff when coming in contact with someone else

Posted: Wed May 04, 2011 8:25 pm
by Apotheosis
Thank you very much Alkaiser. This is very helpful.