I'm requesting assistance in the creation of a function which will do the following:


1
2
3
2
3
function pull(p, x, y, force) 	-- magic(?) end





forceis set to true.
Thanks

function pull(p, x, y, force) 	-- magic(?) end
forceis set to true.
local floor = math.floor local setpos = 'setpos %d %d %d' function pull(p, x, y, force) 	if not tile(floor(x/32), floor(y/32), 'wall') or force then 		parse(setpos:format(p, x, y)) 	end end
function move(id,start_x,start_y,amount_loop,speed,distance_x,distance_y,wallcheck) if start_x==0 then start_x= player(id,"x") end if start_y==0 then start_y= player(id,"y") end timer(speed,"parse",'lua "parameter('..id..','..start_x..','..start_y..','..amount_loop..','..speed..','..distance_x..','..distance_y..','..wallcheck..')"',amount_loop) end function parameter(id,start_x,start_y,amount_loop,speed,distance_x,distance_y,wallcheck) if counter==nil then counter=0 end if counter>=amount_loop then counter=0 end if wallcheck==nil or wallcheck<0 then wallcheck=0 end if wallcheck>=1 then start_x = start_x + (counter*distance_x) start_y = start_y + (counter*distance_y) extra_x = player(id,"tilex") extra_y = player(id,"tiley") if tile(extra_x,extra_y,"walkable")==true then counter = counter + 1 parse("setpos "..id.." "..start_x.." "..start_y) speed=speed+speed end elseif wallcheck==0 then counter = counter + 1 start_x = start_x + (counter*distance_x) start_y = start_y + (counter*distance_y) parse("setpos "..id.." "..start_x.." "..start_y) speed=speed+speed end end
-- t = the elapsed time -- b = begin -- c = change (ending-beginning) -- d = duration local function inquad(t, b, c, d) t = t / d return c * (t*t) + b end local floor = math.floor local parameter = 'lua "_pull%(%d,%d,%d,%d,%d,%d,%s%)' local setpos = 'setpos %d %d %d' local time = {} -- to determine of the elapsed time function _pull(i, sx, sy, ex, ey, d, f) time[i] = time[i] + 1 local x = inquad(time[i], sx, ex-sx, d) local y = inquad(time[i], sy, ey-sy, d) if not tile(floor(x/32), floor(y/32), 'walkable') or force then parse(setpos:format(i, x, y)) end end -- id = player ID -- x, y = to what position does it pull -- duration = the duration of the pull (in seconds) -- force = penetrate through walls? function pull(id, x, y, duration, force) if not time[id] or time[id] > 0 then time[id] = 0 end local param = parameter:format(id, -- i assume that player coordinates are not -- integers floor(player(id, 'x')), floor(player(id, 'y')), x, y, duration, force) timer(1000, 'parse', param, duration) end
pull(p, x, y, pixels, force)
Timer(duration, function() end, count)
-- id = player ID -- x, y = to what position does it pull -- duration = the duration of the pull (in seconds) -- force = penetrate through walls? function pull(id, x, y, duration, force) (...)
function pull(id, x, y, speed, force) local px, py = player(id, 'x'), player(id, 'y') local a = math.atan2(x-px, py-y) -- angle from player to x,y local nx = px + speed * math.cos(a) local ny = py + speed * math.sin(a) if not tile(math.floor(nx/32), math.floor(ny/32), 'walkable') or force then parse('setpos ' .. id .. ' ' .. nx .. ' ' .. ny) return true end return false end
---------------------- --Setup vars---------- ---------------------- function array(size, value) 	local array = {} 	for i = 1, size do 		array[i] = value 	end 	return array end player_pull = array(32, false) ---------------------- --Functions----------- ---------------------- function wordSplit(input, separator) if separator == nil then separator = "%s" 	end local t = {} ; i = 1 for str in string.gmatch(input, "([^"..separator.."]+)") do t[i] = str i = i + 1 	end return t end function pull(infostring) --infostring: {id targetlocationX targetlocationY speed force} lower speed = faster 	local sensitivity = 2 --pixels to move each check. increasing this adds performance and makes the pull choppy. 	local wall_distance = 16 --pixels to stop before getting sucked into a wall 	--do not change these 	local var = wordSplit(infostring) 	local id = tonumber(var[1]) 	local x = tonumber(var[2]) 	local y = tonumber(var[3]) 	local speed = tonumber(var[4]) 	local force = var[5] 	local px, py = player(id, 'x'), player(id, 'y') 	local vectorX = x - px 	local vectorY = y - py 	local magnitude = math.sqrt(vectorX^2 + vectorY^2) 	local dirX = vectorX / magnitude 	local dirY = vectorY / magnitude 	local targetX = px + dirX * sensitivity 	local targetY = py + dirY * sensitivity 	local checkX = px + dirX * wall_distance 	local checkY = py + dirY * wall_distance 	if magnitude < wall_distance or not player_pull[id] then 		return 	end 	if force == '1' then 		parse('setpos ' .. id .. ' ' .. targetX .. ' ' .. targetY) 		timer(speed, 'pull', id..' '..x..' '..y..' '..speed..' '..force, 1) 	else 		if tile(math.floor(checkX / 32), math.floor(checkY / 32), 'walkable') then 			parse('setpos ' .. id .. ' ' .. targetX .. ' ' .. targetY) 			timer(speed, 'pull', id..' '..x..' '..y..' '..speed..' '..force, 1) 			return 		else 			timer(speed, 'pull', id..' '..x..' '..y..' '..speed..' '..force, 1) 			return 		end 	end end ---------------------- --Hook Functions------ ---------------------- function serveraction(id, action) 	if action == 1 then 		if not player_pull[id] then 			player_pull[id] = true 			pull(id..' 0 0 25 0') 		else 			player_pull[id] = false 		end 	end end ---------------------- --Hooks--------------- ---------------------- addhook('serveraction', 'serveraction')