• 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!

Check player in X,Y,Z and check time in NPC ?

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,855
Solutions
18
Reaction score
671
Hello.
Anyone can write for me script that give player 1 storage/s if he is in X,Y,Z area ?

Example:
- Player moves to X,Y,Z area
- script starts
- script checking how many seconds player stays in X,Y,Z area (includings floors [-1, -2, -3, -4])
- when players move out from X,Y,Z area the script stop

NPC:
- When player talk with npc and say "time" the NPC display the time:
" You already spend "X" time on X,Y,Z place


Anyone can write it for me ? TFS 0.3.6pl1 , i tried it but the storage count is broking my script...
 
Area time counter:
LUA:
planetAreaStorageTime = 3454

planetAreaLowValuesCorner = {x=32,y=23,z=4}
planetAreaHighValuesCorner = {x=545,y=545,z=7}

planetAreaPlayers = {}

function isOnPlanet(cid)
	return planetAreaPlayers[getPlayerGUID(cid)] ~= nil
end

function isOnPlanetArea(cid)
	return isInRange(getThingPosition(cid), planetAreaLowValuesCorner, planetAreaHighValuesCorner)
end

function enterPlanet(cid)
	planetAreaPlayers[getPlayerGUID(cid)] = os.time()
end

function leavePlanet(cid)
	doCreatureSetStorage(cid, planetAreaStorageTime, math.max(getCreatureStorage(cid, planetAreaStorageTime), 0) + os.time() - planetAreaPlayers[getPlayerGUID(cid)])
	planetAreaPlayers[getPlayerGUID(cid)] = nil
end

function onThink(cid)
	if not isOnPlanet(cid) and isOnPlanetArea(cid) then
		enterPlanet(cid)
	elseif isOnPlanet(cid) and not isOnPlanetArea(cid) then
		leavePlanet(cid)
	end

	return true
end

function onLogin(cid)
	if isOnPlanetArea(cid) then
		enterPlanet(cid)
	end
	registerCreatureEvent(cid, "planetAreaCheck")

	return true
end

function onLogout(cid)
	if isOnPlanet(cid) then
		leavePlanet(cid)
	end

	return true
end
Creaturescripts.xml
XML:
<event type="login" name="planetAreaLogin" event="script" value="planetArea.lua"/>
<event type="logout" name="planetAreaLogout" event="script" value="planetArea.lua"/>
<event type="think" name="planetAreaCheck" event="script" value="planetArea.lua"/>
 
Last edited:
Back
Top