English Trigger_IF tutor needed!

4 replies
Goto Page
To the start Previous 1 Next To the start
04.05.16 05:46:22 pm
Up
ExEc ExE
User
Offline Off
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
04.05.16 05:53:44 pm
Up
TrialAndError
User
Offline Off
user DC has written:
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.
04.05.16 06:30:34 pm
Up
Fraizeraust
Moderator
Offline Off
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:
Code:
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.
Code:
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.
04.05.16 06:52:27 pm
Up
ExEc ExE
User
Offline Off
@user Fraizeraust: Kudos for the help, I'll start making the .lua for the map I'll keep you updated if I screw something up.
04.05.16 11:01:33 pm
Up
VADemon
User
Offline Off
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 Fraizeraust: it will never work, the condition will always return false because of the and
Code:
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)?
To the start Previous 1 Next To the start