• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

StepIn StepOut {little fix}

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,858
Reaction score
96
Location
Brazil
Hello,
how can I make this script:

When player kill a onKill script will check if he is alone in place(from xyz to xyz)
- if he is alone then reward.
- if he isn't alone then do nothing.
 
Lua:
local area = {frompos = {x=1,y=1,z=1}, topos = {x=1,y=1,z=1}}


local reward , count = 2665, 3


function onKill(cid,target)
	local players = 0
	if isPlayer(cid) and isPlayer(target) then
		for _,pid in ipairs(getPlayersOnline()) do 
			if (pid ~= cid) and isInRange(getThingPos(pid), area.frompos, area.topos) then
				players = players+1
			end
		end
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
		end
	end
	return true
end

Have been too much away of scripting so maybe there is some errors.
 
not working because your script is wrong!!

Lua:
local area = {frompos = {x= 33250, y = 31064 , z = 10}, topos = {x= 33259, y = 31071 , z = 10}}local reward , count = 2160, 5


function check1(cid)
	local players = 0
	
	if isPlayer(cid) and isInRange(getThingPos(cid), area.frompos, area.topos) then
		
		for _,pid in ipairs(getPlayersOnline()) do 
			if (pid ~= cid) and isInRange(getThingPos(pid), area.frompos, area.topos) then
				players = players+1
			end
		end
		
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
		else 
			doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"There is player")
		end
		addEvent(check1,6*1000,cid)
	end
	
	return true
end


function onStepIn(cid, item, position, fromPosition)


	if isPlayer(cid) then
		check1(cid)
		doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR	,"Check started.")
	end
	
	return true
end
 
Last edited:
It's not working yet

Lua:
local area = {frompos = {x= 33250, y = 31064 , z = 10}, topos = {x= 33259, y = 31071 , z = 10}}local reward , count = 2160, 5
 
 
function check1(cid)
	local players = 0
 
	if isPlayer(cid) and isInRange(getThingPos(cid), area.frompos, area.topos) then
 
		for _,pid in ipairs(getPlayersOnline()) do 
			if (pid ~= cid) and isInRange(getThingPos(pid), area.frompos, area.topos) then
				players = players+1
			end
		end
 
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
		else 
			doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"There is player")
		end
		addEvent(check1,6*1000,cid)
	end
 
	return true
end
 
 
function onStepIn(cid, item, position, fromPosition)
 
 
	if isPlayer(cid) then
		check1(cid)
		doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR	,"Check started.")
	end
 
	return true
end
 
Last edited:
Actually I just tested it and it is working.. Unless you want to tell me good details about what isn't working what errors you get i cant help out.

By the way it checks in one floor only so you need to make it like that.

How mine work :

When you step in it starts to check every 5 seconds, and as long as you are still within the checking place then it will keep checking up until you get out.

Steps :

1- Remove allyour scripts concerning that..
2- Make a new file call it whatever, paste in my second script, then go register it into movement (actioid, scriptname ,stepin)
3- Test
 
Last edited:
No errors and nothing happens :(
dev0.4 3884

Maybe I'm wrong but I think this code is not workin'
Lua:
	local players = 0
 
	if isPlayer(cid) and isInRange(getThingPos(cid), area.frompos, area.topos) then
 
		for _,pid in ipairs(getPlayersOnline()) do 
			if (pid ~= cid) and isInRange(getThingPos(pid), area.frompos, area.topos) then
				players = players+1
			end
		end
 
I didn't test this, i made it fast but i think is working
Lua:
local area =
{
	frompos = {x=347,y=550,z=0},
	topos = {x=466,y=653,z=8}
}
local reward, count = 2665, 3
 

local players = 0
local started = false
local event
local function check1(cid)
	started = true
	if isPlayer(cid) then
		for _,pid in ipairs(getPlayersOnline()) do 
			if pid ~= cid and isInRange(getCreaturePosition(pid), area.frompos, area.topos) then
				players = players + 1
			end
		end
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
			started = false
		else
			event = addEvent(check1, 1 * 1000, cid)
		end
	end
	return true
end
 
function onStepOut(cid, item, position, fromPosition)
 
	if isPlayer(cid) and started then
		stopEvent(event)
	end
	return true
end
 
That checking tile must be in range , and as i told you the check must be in 1 floor only.

If you did all that then maybe the inRange function is wrong : (just change it with this even if they look the same)
serverdirec/lib/032-position.lua
Lua:
function isInRange(position, fromPosition, toPosition)
	return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z
		and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end
 
StepIn and StepOut all in one script
When step in check
When stepout stop check

StepOut NOT WORKING
Lua:
local area = {
frompos = {x= 347, y = 556 , z = 8},
topos = {x= 472, y = 664 , z = 0}
}
local reward, count = 2160, 5
tppos = {x=156, y=654, z=7, stackpos=1}



local players = 0
local function check1(cid)
	if isPlayer(cid) then
		for _,pid in ipairs(getPlayersOnline()) do 
			if pid ~= cid and isInRange(getCreaturePosition(pid), area.frompos, area.topos) then
				players = players + 1
			end
		end
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
			setGlobalStorageValue(74999, -1)
			db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 74910")
			db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 74911")
			doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
			doRemoveCondition(cid, CONDITION_INFIGHT)
			broadcastMessage(getCreatureName(cid) .. " won!", MESSAGE_EVENT_ADVANCE)
			rtp = getThingfromPos(tppos)
			doRemoveItem(rtp.uid,1)
		else
			addEvent(check1, 10 * 1000, cid)
		end
	end
	return true
end
 
 
function onStepIn(cid, item, position, fromPosition)
 
 
	if isPlayer(cid) then
		addEvent(check1, 10 * 1000,cid)
		doSendMagicEffect(getPlayerPosition(cid), 34)
	end
end

function onStepOut(cid, item, position, fromPosition)

	if isPlayer(cid) then
		stopEvent(check1)
	end
	return true
end
 
Last edited:
Lua:
local area = {frompos = {x= 347, y = 556 , z = 8},
topos = {x= 472, y = 664 , z = 0}
}
local reward, count = 2160, 5
local tppos = {x=156, y=654, z=7, stackpos=1}
 
 
 


function check1(cid)
	local players = 0
	if isPlayer(cid) then
		for _,pid in ipairs(getPlayersOnline()) do 
			if pid ~= cid and isInRange(getCreaturePosition(pid), area.frompos, area.topos) then
				players = players + 1
			end
		end
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
			setGlobalStorageValue(74999, -1)
			db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 74910")
			db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 74911")
			doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
			doRemoveCondition(cid, CONDITION_INFIGHT)
			broadcastMessage(getCreatureName(cid) .. " won!", MESSAGE_EVENT_ADVANCE)
			doRemoveItem(getThingfromPos(tppos).uid,1)
		else
			event_check = addEvent(check1, 10 * 1000, cid)
		end
	end
	return true
end
 
 
function onStepIn(cid, item, position, fromPosition)
 
	if isPlayer(cid) then
		addEvent(check1, 10 * 1000,cid)
		doSendMagicEffect(getPlayerPosition(cid), 34)
	end
end
 
function onStepOut(cid, item, position, fromPosition)
 
	if isPlayer(cid) and event_check then
		stopEvent(event_check)
	end
	return true
end
 
Working but, just a problem.
If player ISN'T alone server crash

PS.: Player stepIn and wait for check (he isn't alone) then he receive reward and server crash.
1. Why are him receiving the reward?
2. Why is the server crashing?
 
Last edited:
When stepin start check (if player is alone in area he receive reward. If isn't do nothing)
When stepout stop check

If player ISN'T alone server crash

PS.: Player stepIn and wait for check (he isn't alone) then he receive reward and server crash.
1. Why are him receiving the reward?
2. Why is the server crashing?

Lua:
local area = {
frompos = {x= 347, y = 556 , z = 8},
topos = {x= 472, y = 664 , z = 0}
}
local reward, count = 2160, 5
tppos = {x=156, y=654, z=7, stackpos=1}

local players = 0
local function check1(cid)
	if isPlayer(cid) then
		for _,pid in ipairs(getPlayersOnline()) do 
			if pid ~= cid and isInRange(getCreaturePosition(pid), area.frompos, area.topos) then
				players = players + 1
			end
		end
		if players < 1 then 
			doPlayerAddItem(cid,reward,count)
			setGlobalStorageValue(74999, -1)
			db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 74910")
			db.executeQuery("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 74911")
			doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
			doRemoveCondition(cid, CONDITION_INFIGHT)
			broadcastMessage(getCreatureName(cid) .. " won!", MESSAGE_EVENT_ADVANCE)
			rtp = getThingfromPos(tppos)
			doRemoveItem(rtp.uid,1)
		else
			doPlayerSendTextMessage(0, cid, 22, "You aren\'t the only survivor. Only one can win this event!")
		end
	end
	return true
end
 
 
function onStepIn(cid, item, position, fromPosition)
 
 
	if isPlayer(cid) then
		event_check = addEvent(check1, 10 * 1000,cid)
		doSendMagicEffect(getPlayerPosition(cid), 34)
	end
	return true
end

function onStepOut(cid, item, position, fromPosition)

	if isPlayer(cid) and event_check then
		stopEvent(event_check)
	end
	return true
end
 
Last edited:
First mistake you have a z-coordinate = 0 so lol.

Second get the local players inside the function, it is as if you didnt use anything i did lol.
 
Back
Top