What LUA scipt allows me to trigger something when the player dies?
For example:
Player dies, using the officer class -> this unit class is now disabled/player can't respawn as officer class.
Triggering event on death of a certain unit [solved]
Moderator: Moderators
-
Bob
- Brigadier General

- Posts: 633
- Joined: Thu May 27, 2010 4:28 am
- Location: at home
Triggering event on death of a certain unit [solved]
Last edited by Bob on Wed Jun 20, 2012 4:31 pm, edited 1 time in total.
-
razac920
- 2nd Lieutenant

- Posts: 365
- Joined: Sun Jan 16, 2011 12:42 am
Re: Triggering event on death of a certain unit
OnCharacterDeath(function(player,killer)
if IsCharacterHuman(player) and GetCharacterClass(player) == <index of officer class> then
SetClassProperty(<name of officer class>,"PointsToUnlock",<very big number>)
end
end)
index is the placement from top down in class selection menu, starting at 0
For a normal side, the order is soldier, rocketeer, sniper, engineer, officer, special, so officer is 5th and the index would be 4.
Optionally (but recommended) if you want to save memory and perform this check only once then you could do:
officerdisable = OnCharacterDeath(function(player,killer)
if IsCharacterHuman(player) and GetCharacterClass(player) == <index of officer class> then
SetClassProperty(<name of officer class>,"PointsToUnlock",<very big number>)
ReleaseCharacterDeath(officerdisable)
officerdisable = nil
end
end)
See the Battlefront2_scripting_system for more info on events, event callbacks, and lua functions
if IsCharacterHuman(player) and GetCharacterClass(player) == <index of officer class> then
SetClassProperty(<name of officer class>,"PointsToUnlock",<very big number>)
end
end)
index is the placement from top down in class selection menu, starting at 0
For a normal side, the order is soldier, rocketeer, sniper, engineer, officer, special, so officer is 5th and the index would be 4.
Optionally (but recommended) if you want to save memory and perform this check only once then you could do:
officerdisable = OnCharacterDeath(function(player,killer)
if IsCharacterHuman(player) and GetCharacterClass(player) == <index of officer class> then
SetClassProperty(<name of officer class>,"PointsToUnlock",<very big number>)
ReleaseCharacterDeath(officerdisable)
officerdisable = nil
end
end)
See the Battlefront2_scripting_system for more info on events, event callbacks, and lua functions
-
Bob
- Brigadier General

- Posts: 633
- Joined: Thu May 27, 2010 4:28 am
- Location: at home
Re: Triggering event on death of a certain unit
Are function, player and killer placeholders for something I have to insert or can I just leave them alone? This is the question that kept me away from LUA scripting since I started modding...
-
Marth8880
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: Triggering event on death of a certain unit
Bob wrote:just leave them alone?
-
razac920
- 2nd Lieutenant

- Posts: 365
- Joined: Sun Jan 16, 2011 12:42 am
Re: Triggering event on death of a certain unit
Sorry, at first I misunderstand your post. Yes, you can just keep the words "function", "killer", and "player" just as they are. "function" is a keyword that you can't change, but if you really wanted to, you could replace each instance of "player" or "killer" by any other word, and it would still work. The name doesn't matter, really. For example, suppose you write a function that takes two numbers and returns their difference. You could write
sub = function(a, b)
return a - b
end
or
sub = function(num1, num2)
return num1 - num2
end
When you call sub(7, 5) if you defined sub at the top, the function would assign 5 to a and 7 to and work. If you defined sub at bottom, the function would assign 5 to num1 and 7 to num2 and work. In short, only the order of inputs matters, not the names you give them.
Hope these helps calm your worries about LUA scripting; it's really amazingly useful!
sub = function(a, b)
return a - b
end
or
sub = function(num1, num2)
return num1 - num2
end
When you call sub(7, 5) if you defined sub at the top, the function would assign 5 to a and 7 to and work. If you defined sub at bottom, the function would assign 5 to num1 and 7 to num2 and work. In short, only the order of inputs matters, not the names you give them.
Hope these helps calm your worries about LUA scripting; it's really amazingly useful!
Last edited by razac920 on Wed Jun 20, 2012 3:49 pm, edited 4 times in total.
-
Bob
- Brigadier General

- Posts: 633
- Joined: Thu May 27, 2010 4:28 am
- Location: at home
Re: Triggering event on death of a certain unit
Alright then, thanks for the aid you twoMarth8880 wrote:Bob wrote:just leave them alone?
EDIT: One more thing, is there something I have to add when I want 2 SetClassPropertys after the 'then'? In good ol' Delphi I would have to put them between the Keywords BEGIN and END, but SWBF2 is obviously not written in Delphi.
EDIT#2: Never mind, just tried with nothing added and it worked.
------------------------------------------------------------------------------------------------------
Topic solved
