Forum

> > CS2D > Scripts > Portal name
Forums overviewCS2D overview Scripts overviewLog in to reply

English Portal name

6 replies
To the start Previous 1 Next To the start

old Portal name

tos12345678
User Off Offline

Quote
Whether there is a parse spawnobject (orange portal) with name and trigger? Can I name this spawnobject (not editor)?

old Re: Portal name

tos12345678
User Off Offline

Quote
I mean Name, Trigger which I can interact with
e.g. When i enter this portal, it is exit.

Put simply this spawnobject have a name: test1 and trigger: test2
to interact with others e.g. delay, dynWall and similar.
I want to this object
1
parse("spawnobject 22 "..player(id,"tilex").." "..player(id,"tiley"))
exitting after 30seconds.

old Re: Portal name

VADemon
User Off Offline

Quote
No, you need a Lua script for this (to trigger entities from portal enter/exit)
I will do one tomorrow - PM me if I forget.

old Portal Trigger

VADemon
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
portaltrigger = {}
portaltrigger.pos = {}

addhook("movetile", "portaltrigger_movetile")

-- movetile is also triggered when player is teleported or setpos is used
function portaltrigger_movetile(id, tilex, tiley)
	tilex, tiley = tonumber(tilex), tonumber(tiley)
	--msg("movetile: ".. id ..", ".. tilex ..", ".. tiley)
	
	if portaltrigger.pos[tilex] and portaltrigger.pos[tilex][tiley] then
		local oid = objectat(tilex, tiley, 22) or objectat(tilex, tiley, 21)
		--msg("oid is ".. tostring(oid))
		if oid then
			parse("trigger portaltrg@".. tilex .. "_".. tiley)
		end
		
	--else
		--msg(tilex ..", ".. tiley .." doesnt exist")
	end
end

-- Multiplayer Trigger BUG
--[[
addhook("trigger", "portaltrigger_trigger")
yellow = 0
blue = 0
function portaltrigger_trigger(trigger, source)
	msg("trigger: ".. trigger .." src: ".. tostring(source))
	
	if trigger and trigger == "yellow" then
		yellow = yellow + 1
	elseif trigger and trigger == "blue" then
		blue = blue + 1
	end
	
	parse("hudtxt 0 \"yellow = ".. yellow .."\" 0 420")
	parse("hudtxt 1 \"blue = ".. blue .."\" 0 435")
end
]]
function portaltrigger.init()
	local elist = entitylist()
	for i, e in pairs(elist) do
	
		local name = entity(e.x, e.y, "name")
		for keyword, tilex, tiley in name:gmatch("(%w+)@(%d+)_(%d+)") do
			
			if keyword and tilex and tiley then
				keyword = keyword:lower()
				tilex, tiley = tonumber(tilex), tonumber(tiley)
				if keyword == "portaltrg" then
					print("PortalTrigger registered at ".. tilex ..",".. tiley)
					if not portaltrigger.pos[tilex] then portaltrigger.pos[tilex]={} end
					portaltrigger.pos[tilex][tiley] = true
				end
			end
		end
	end
end
portaltrigger.init()

How To:
1) Put this script to sys/lua/autorun
OR
1) Name this script the same as your map and add it to maps/ e.g. /maps/<mapname>.lua & /maps/<mapname>.map

Make entities:
2) Spawn any Orange/Blue portal. For example, Portal is at position X14, Y18 - it works for Entity portal and for Player portals in-game created with Portal Gun
3) Create Entity in Editor that will be triggered when player visits portal at X14, Y18:
Example: cs2d entity env_explode put "portaltrg@14_18" as Name!
- Every time a player goes to a portal at X14 Y18 it will be triggered
4) Done. You can have many entities to trigger when player visits this portal.
You can also give this entity many names e.g. "portaltrg@14_18,portaltrg@10_10" - I think CS2D allows it, but please test it

PS: So it's the other way around. You can spawn any portals with spawnentity, but instead of saying in spawnentity what will be triggered, you must have entities on map with the Name: field specified, telling that it will be triggered once a player visits a portal at X,Y. "portaltrg@X_Y"
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview