• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Watch others/TV system

Sportacus

Intermediate OT User
Joined
Aug 3, 2008
Messages
718
Reaction score
100
Hey guys, haven't seen anyone else post these functions on here, figured people would find them useful.

Personally, I've used them to make an Academy/School tutorial where players go to classrooms, and then they watch a "video" on what the class is about, such as showing special features that your server may have, like crafting systems, or special events.

I find showing a player through a visual aid instead of text, explains to players better on what they have to do.

You can also do all sorts of things, like make commercials for players to watch, set up pvp arenas with in game streams that people can watch from the player or referees prospective.

Or just simply use it as a way to watch other players play the game, such as they did on pokemon servers.


Anyway, here is the scripts, you can either put them in your functions, or make a new file in your lib called tvsystem.lua or whatever you want to name it.


Code:
function doPlayerWatchOther(cid, target)

	if not isCreature(cid) then return true end

	local hasOutfitCond = getCreatureCondition(cid, CONDITION_OUTFIT) and getCreatureOutfit(cid).lookType or -1
	setPlayerStorageValue(cid, 99282, getCreatureSpeed(cid))
	setPlayerStorageValue(cid, 99283, hasOutfitCond)

	setPlayerStorageValue(cid, 99285, target)
	doCreatureSetNick(cid, "") --, " ")

	local o = getCreatureOutfit(cid)
	local olddir = getCreatureLookDir(cid)
	local oldpos = getThingPos(cid)

	doCreatureSetHideHealth(cid, true)
	doPlayerLock(cid)

	local dir = "data/npc/TVNPC.xml"
	local a = io.open(dir, "a+")
	local b = a:read("*all")
	a:close()

	local npcname = 'name="'..getCreatureName(cid)..' watching tv"'
	local npchealth = 'health now="'..getCreatureHealth(cid)..'" max="'..getCreatureMaxHealth(cid)..'"'
	local npcoutfit = 'look type="'..o.lookType..'" head="'..o.lookHead..'" body="'..o.lookBody..'" legs="'..o.lookLegs..'" feet="'..o.lookFeet..'"'

	b = string.gsub(b, 'name="(.-)"', npcname)
	b = string.gsub(b, 'health now="(.-)" max="(.-)"', npchealth)
	b = string.gsub(b, 'look type="(.-)" head="(.-)" body="(.-)" legs="(.-)" feet="(.-)"', npcoutfit)

	local c = io.open(dir, "w")
	c:write(b)
	c:close()

	o.lookType = 814

	doCreatureSetOutfit(cid, o, -1)
	doTeleportThing(cid, getThingPos(target), false)

	local n = doCreateNpc("TVNPC", oldpos)
	doCreatureSetLookDir(n, olddir)
	setPlayerStorageValue(n, 9891, getPlayerSex(cid))
	doChangeSpeed(cid, -getCreatureSpeed(cid))
	doChangeSpeed(cid, getCreatureSpeed(target))

end

function doPlayerStopWatching(cid)

	if not isCreature(cid) then return true end

	doPlayerUnlock(cid)
	doCreatureSetNick(cid, "") --, getCreatureName(cid))

	local pos = {}
	local speed = getPlayerStorageValue(cid, 99282)
	local npc = getCreatureByName(getCreatureName(cid).." watching tv.")
	local olddir = 0
		if isCreature(npc) then
			olddir = getCreatureLookDir(npc)
			local pos = getThingPos(npc)
			doRemoveCreature(npc)
			doTeleportThing(cid, pos, false)
		end
	doChangeSpeed(cid, -getCreatureSpeed(cid))
	doChangeSpeed(cid, speed)
	doCreatureSetHideHealth(cid, false)
	doCreatureSetLookDir(cid, olddir)
	doCreatureSetNick(cid, getCreatureName(cid))
	setPlayerStorageValue(cid, 99285, -1)

	local outfit = getPlayerStorageValue(cid, 99283)
		if outfit >= 1 then
			local newOutfit = getCreatureOutfit(cid)
			newOutfit.lookType = outfit
			doCreatureSetOutfit(cid, newOutfit, -1)
		else
			doCreatureRemoveCondition(cid, CONDITION_OUTFIT)
		end

end


function getWatchingPlayersFromPos(cid, pos)
	local ret = {}

	local cp = {}
	cp.x = pos.x
	cp.y = pos.y
	cp.z = pos.z

	for a = 0, 255 do
		cp.stackpos = a
		local b = getTileThingByPos(cp).uid
		if isCreature(b) and getCreatureOutfit(b).lookType == 814 and getPlayerStorageValue(b, 99285) == cid then
			table.insert(ret, b)
		end
	end
return ret
end

and you'll need to make a NPC file called TVNPC.lua

heres the script for that

Code:
<?xml version="1.0" encoding="UTF-8"?>

<npc name="NAME DOES NOT MATTER" speed="0">

	<health now="310" max="310"/>

	<look type="510" head="79" body="85" legs="91" feet="85"/>

	<parameters>


	</parameters>

</npc>

And thats it for the function. I know I didn't post an example script using these functions, but currently the only thing I am using these functions for is the school system I mentioned above, which is currently in use, so I won't be releasing that.
 
Last edited:
If it possibles i waiting for complete release. I want that TV System is epic :)
 
What-- you mean "doCreatureSetNick"? easy shit. Just adding a new property to player.cpp
@OnT: Thanks! Saved some work for me. What's the NPC for tho?
 
Back
Top