• 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.
 
I'll test the script now, wait a moment

EDIT: LOL! THIS IS MY NOOB DAY! i used onStepIn on both functions, try it now
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 onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
 
	if isPlayer(cid) then
		if event[cid] ~= nil then
			stopEvent(event[cid])
		end
	end
	return true
end

Next time, you should check your console, that erros is displayed
Code:
[Warning - Event::loadScript] Event onStepOut not found (data/movements/scripts/lucas.lua)

EDIT 2: I still didn't test the script but should be working now
 
Try to split the functions in different files and store the table instead inside of the script in functions.lua, maybe once the player stepin/stepout it currently clears the table with the events before the event could be canceled.

try it like this:
Lua:
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

make another file and put this into it:
Lua:
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	if isPlayer(cid) then
		if event[cid] then
			stopEvent(event[cid])
		end
	end
	return true
end

and put this into functions.lua
Lua:
event = {}
function check1(cid)
local area = 
{
	frompos = {x=347, y=556, z=6},
	topos = {x=472, y=664, z=6}
}
local reward = 2160
local count = 5
local tppos = {x=156, y=654, z=7, stackpos=1}
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
 
Try to split the functions in different files and store the table instead inside of the script in functions.lua, maybe once the player stepin/stepout it currently clears the table with the events before the event could be canceled.

try it like this:
Lua:
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

make another file and put this into it:
Lua:
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	if isPlayer(cid) then
		if event[cid] then
			stopEvent(event[cid])
		end
	end
	return true
end

and put this into functions.lua
Lua:
event = {}
function check1(cid)
local area = 
{
	frompos = {x=347, y=556, z=6},
	topos = {x=472, y=664, z=6}
}
local reward = 2160
local count = 5
local tppos = {x=156, y=654, z=7, stackpos=1}
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

It stoppes the event BUT if player stay in throne then server crashes while checking
 
remove this stuff piece by piece and look if the server is still crashing.
Lua:
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
 
I got it working with storages
Lua:
local area = 
{
	frompos = {x=89, y=128, z=7},
	topos = {x=96, y=134, z=7}
}
local reward = 2160
count = 5
tppos = {x=98, y=122, z=7, stackpos=1}
local CHECK_STORAGE = 20088
local function check1(cid)
	local players = 0
	if isPlayer(cid) and getCreatureStorage(cid, CHECK_STORAGE) > 0 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
		doCreatureSetStorage(cid, CHECK_STORAGE, 1)
		addEvent(check1, 10 * 1000, cid)
		doSendMagicEffect(getCreaturePosition(cid), 34)
	end
	return true
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
 
	if isPlayer(cid) then
		doCreatureSetStorage(cid, CHECK_STORAGE, 0)
	end
	return true
end
 
and such so I can understand
This script grabs this:
* to kill a monster in that area receive a reward.
* but if you do not kill in that area do not receive anything, am I right?
 
Back
Top