Forum

> > CS2D > Maps/Editor > Trigger_IF tutor needed!
ForenübersichtCS2D-Übersicht Maps/Editor-ÜbersichtEinloggen, um zu antworten

Englisch Trigger_IF tutor needed!

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Trigger_IF tutor needed!

ExEc ExE
User Off Offline

Zitieren
So I've started working on a new map and I'm wondering if there's a tutorial on the new (To myself) Trigger_IF.

I need to know if its possible to do stuff like:
1. Give every player on T/CT side 250 armor and 250 health on round start
2. Equip random player from T/CT side with weapons on round start.
3. Random command?!

Would really appreciate some help as I'm s**t at writing just a simplest line of commands

alt Re: Trigger_IF tutor needed!

TrialAndError
User Off Offline

Zitieren
user DC hat geschrieben
Trigger_If is intended for one line Lua codes only. You should consider to use a map Lua file (this is a Lua file which is in the maps folder and has the name <NAME OF MAP>.lua - it will be automatically loaded with the map). Create a Lua function in it which does what you want to do in your Trigger_If and put the name of this function in your Trigger_If. Everything else is quite dirty and bad practice.


If you tend to do long lines of code in the "Trigger_If", the game would most likely crash or freeze.

alt Re: Trigger_IF tutor needed!

GeoB99
Moderator Off Offline

Zitieren
As user TrialAndError mentioned on his post, you can't do these stuff with Trigger_If, at least not in a clean way. You must make straight Lua scripts for that. There's a tutorial into how you can use this trigger nevertheless (thread cs2d How to use Trigger_If) but none of those tips in the tutorial is suitable for your needs.

1. To give 250 health & 250 armor for every player, cs2d lua hook spawn hook is the best way with parse function and few commands as you can see within the code below:
1
2
3
4
5
6
7
8
function spawn_(id)
	if (player( id, 'team' ) == 1 and player( id, 'team' ) == 2) then
		parse('sethealth ' .. id .. ' 250')
		parse('setarmor ' .. id .. ' 250')
	end
end

addhook("spawn","spawn_")

2. Same with spawn hook but with different ways.
1
2
3
4
5
6
7
8
9
function spawnWP(id)
	for _, id in ipairs( player(0, 'table') ) do
		local player1 = math.random(1, 'team1')
		local player2 = math.random(1, 'team2')
		return "" -- Weapon IDs here
	end
end

addhook("spawn","spawnWP")
Two local variables assigned to math.random function so on spawn it'll be given weapons to random players. Not sure though if it works so I beg pardon and would like if someone corrects any wrong syntax or structure of the second snippet of code (if there are any).

3. You can do same by writing Lua scripts. I cannot be arsed randomly to make you another script as it depends on you what do you need.

alt Re: Trigger_IF tutor needed!

VADemon
User Off Offline

Zitieren
Basically, cs2d entity trigger_if wasn't intended to run Lua scripts. Instead you should use cs2d cmd mp_luamap to load map-specific scripts which will also be uploaded to players (so they download .map + .lua)

1) @user GeoB99: it will never work, the condition will always return false because of the and
1
2
3
4
5
6
addhook("spawn", "spawn_sethp")
function spawn_sethp(id)
-- but the maxhealth will remain 100
          parse('sethealth ' .. id .. ' 250')
          parse('setarmor ' .. id .. ' 250')
end

2) This one is a bit tricky. Do you want to keep it fair (everyone has a chance to get this rare equip, but then a team might not have this rarely equipped player for some time) or balanced (both team ALWAYS have this equip, but sometimes it's always the FIRST player to spawn who'll the rare items)?
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Maps/Editor-ÜbersichtCS2D-ÜbersichtForenübersicht