• 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.
 
You both should learn to read then...

Code:
local area = {
frompos = {x= 347, y = 556 , z = 8},
topos = {x= 472, y = 664 , z = 0}  [B]<-- z is 0 .. how?[/B]
}


Code:
local players = 0  [B]<-- Put this after "local function check1(cid)" so it is inside the check1 function..[/B]
local function check1(cid)
 
Still crashing
Lua:
local area = {
frompos = {x=347, y=556, z=8},
topos = {x=472, y=664, z=1}
}
local reward, count = 2160, 5
tppos = {x=156, y=654, z=7, stackpos=1}
 
local 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)
			setPlayerStorageValue(cid, 74910, -1)
			setPlayerStorageValue(cid, 74911, -1)
			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
 
Example:
When stepin throne, script check if player is alone in area
- If player is alone he get teleported to temple and receive reward
- if isn't alone he receive msg 'you arent alone'
When stepout throne, script stop the check
 
I know that this isnt the thing but you should know that multi-floors wont work , you can't have a position

Code:
frompos [COLOR=#66CC66]=[/COLOR] [COLOR=#66CC66]{[/COLOR]x[COLOR=#66CC66]=[/COLOR][COLOR=#CC66CC]347[/COLOR], y[COLOR=#66CC66]=[/COLOR][COLOR=#CC66CC]556[/COLOR], z[COLOR=#66CC66]=[/COLOR][B][COLOR=#CC66CC]8 <---[/COLOR][/B][COLOR=#66CC66]}[/COLOR],topos [COLOR=#66CC66]=[/COLOR] [COLOR=#66CC66]{[/COLOR]x[COLOR=#66CC66]=[/COLOR][COLOR=#CC66CC]472[/COLOR], y[COLOR=#66CC66]=[/COLOR][COLOR=#CC66CC]664[/COLOR], z[COLOR=#66CC66]=[/COLOR][B][COLOR=#CC66CC]1<---[/COLOR][/B][COLOR=#66CC66]}[/COLOR]

That is what making him to get a reward even if he isn't alone,as for check stops , you need to have a onStepout in movement too.

And your script wont continure checking , i donno why you keep thisscript you have ..

Lua:
local area = {

frompos = {x=347, y=556, z=8},
topos = {x=472, y=664, z=8}
}
local reward, count = 2160, 5
tppos = {x=156, y=654, z=7, stackpos=1}
 
local 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)
			setPlayerStorageValue(cid, 74910, -1)
			setPlayerStorageValue(cid, 74911, -1)
			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!")
			event_checker = addEvent(check1,5*1000,cid)
		end
	end
	return true
end
 
 
function onStepIn(cid, item, position, fromPosition)
 
 
	if isPlayer(cid) then
		check1(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

If it crashed your server then get a new one.
 
Last edited:
When I change this:
Lua:
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

to this:
Lua:
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

make server crash (0.4 3884)

1. Why?
2. How to make stopevent when stepout then?
 
Last edited:
Lua:
local area = {
frompos = {x=347, y=556, z=6},
topos = {x=472, y=664, z=6}
}
local reward, count = 2160, 5
tppos = {x=156, y=654, z=7, stackpos=1}
 
local 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)
			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
		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

Just have to fix 'when stepout stop event check'
 
Here is
XML:
	<movevent type="StepIn" actionid="14910" event="script" value="Bloodshed/throne.lua"/>
	<movevent type="StepOut" actionid="14910" event="script" value="Bloodshed/throne.lua"/>
 
try this (haven't tested it)

Lua:
active_events = {}	
function onStepIn(cid, item, position, fromPosition)
	if isPlayer(cid) then
		active_events[(active_events[1] == nil and 1 or #active_events + 1)] = addEvent(check1, 10 * 1000,cid)
		doSendMagicEffect(getPlayerPosition(cid), 34)
	end
end
 
function onStepOut(cid, item, position, fromPosition)
	if isPlayer(cid) then
		for i = 1, #active_events do
			stopEvent(active_events[i])
		end
		active_events = {}
	end
	return true
end
 
Try this
Lua:
local area = 
{
	frompos = {x=347, y=556, z=6},
	topos = {x=472, y=664, z=6}
}
local reward = 2160
count = 5
tppos = {x=156, y=654, z=7, stackpos=1}
local event = {}
local 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)
			doSetStorage(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)
			doBroadcastMessage(getCreatureName(cid) .. " won!", MESSAGE_EVENT_ADVANCE)
			rtp = getThingFromPos(tppos)
			if rtp.itemid > 0 then
				doRemoveItem(rtp.uid)
			end
		else
			return doPlayerSendTextMessage(cid, 22, "You aren't the only survivor. Only one can win this event!")
		end
	end
	return true
end
 
 
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
 
	if isPlayer(cid) then
		event[cid] = addEvent(check1, 10 * 1000, cid)
		doSendMagicEffect(getCreaturePosition(cid), 34)
	end
	return true
end
 
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
 
	if isPlayer(cid) then
		if event[cid] ~= nil then
			stopEvent(event[cid])
		end
	end
	return true
end
 
Last edited:
Back
Top