www.tombraiderforums.com

Go Back   www.tombraiderforums.com > Tomb Raider Modding > Tomb Raider Level Editor > Tomb Raider Level Editor Tutorials

Closed Thread
 
Thread Tools
Old 19-08-14, 09:39   #1
AkyV
Moderator
 
Join Date: Dec 2011
Location: Hungary
Posts: 2,493
Default TRNG Reloading ammo

This tutorial will show an example for a setup if you want to change clips manually when the ammunition runs out.
This example is about Uzi, having the default (30 bullets per clip pairs) clip size.

This is how it works:
For example, Lara has 110 Uzi bullets in the inventory. So if she extracts Uzis now, then this is what will show up on the screen:

3/20

It means there are 3 full clip pairs “in the backpack”, plus 20 (10+10) bullets in the weapons (330+20=110).
Now she starts firing. Number 20 starts counting down.
When the ammo in the weapons reaches 0, then Lara can’t fire (the player is pressing CTRL, though), and this is what you can see on the screen:

3/0

There are two possibilities to load a new clip pair into the weapons now:

- Holster the weapons and extract them again. (Because that would be illogical if Lara extracted empty weapons.) Now you’ll hear the extracting sound (hardcoded).
- Hit Key R (“Reload”). Now you’ll hear the reloading sound (thanks to the setup, see below).

So the counter will change on the screen:

2/30

And now Lara will be able to shoot again, till the weapons get emptied again, i.e. till the counter shows this: 2/0.
Etc.

If you want to use this setup, then all you need to do is:

- Copy/paste it in the Script, to each level where you want to use it.
- Check GlobalTrigger and TriggerGroup ID’s in the Script commands of the setup, because maybe you use the ID’s in another setup of your level, so you need to change the ID’s. (If you changed the ID of TriggerGroup#2, then you also need to change the TriggerGroup#2 in F118, that is typed in TriggerGroup#1.)
- I used Local Short Alfa1, Local Byte Alfa3 and Current Value variables in the setup. If you use Current Value in another setup at the same time, then that won’t work, you need to change one of the setups somehow, to remove Current Value.
If you use Local Short Alfa1 or Local Byte Alfa3 in another setup at the same time, then you need to choose other variables for the present setup. (Check the rules about choosing variables eg. in Hidden Triggers tutorial on Skribblerz/TRF.) If you chose other variables for this setup, then you need to change the variables in the triggers in the TriggerGroups of the setup.
- Type this in ExtraNG#0 string: #0050/#0800 (these are variable ID’s). Or check variable ID’s in NG Center/Reference, if you chose other variables, so you need to type other variable ID’s now.
Or, you can choose other string instead of ExtraNG#0, but in that case you need to check the triggers in the setup that refer to that string.


Notes:
- If the weapon is empty because you haven’t reloaded (or re-extracted) yet, then CTRL for shooting is disabled for any other functions of the game as well. It can be fixed with some complicated setup, with variables, but I don’t think it’s worth the while. Just reload, and CTRL is useful again.
- Be careful with Equipment command. I mean, if your Uzis starts the game with odd number of bullets, then this setup will fail.
- If you create a “reloading” animation, then you can try to modify the setup, so Lara will perform the reloading animation when she extracts the empty weapons or when the player hits Key R.


Code:
GlobalTrigger= 1, IGNORE, GT_LARA_HOLDS_ITEM, HOLD_UZI, IGNORE, 1, 5
TriggerGroup= 1, $2000, 244, $3EFF, > ;F244: copy the actual amount of Uzi ammo into Current Value variable
$2000, 244, $3E50, > ;F244: copy the actual amount of Uzi ammo into Local Short Alfa1 (LSA1) variable
$8000, 80, $2B, > ;C43: if LSA1=0
$2000, 64, $0, > ;F64: print ExtraNG#0 forever
$8000+TGROUP_ELSE, 80, $129, > ;C41: if LSA>=1
$2000, 118, $2, > ;F118: perform TG#2
$8000, 17, $5, > ;C5: if Lara’s shooting status is true
$2000, 232, $142 ; F232: set Value 1 in Local Byte Alfa3 (LBA3) variable

TriggerGroup= 2, $2000, 253, $1E50, > ;F253: divide LSA1 by 30
$2000, 251, $1E50, > ;F251: multiply LSA1 by 30
$8000+TGROUP_NOT, 80, $39, > ;C57: if Current Value NOT=LSA1
$2000, 286, $50, > ;F286: subtract LSA1 from Current Value
$2000, 253, $1E50, >;F253: divide LSA1 by 30
$2000, 64, $0, > ;F64: print ExtraNG#0 forever
$8000+TGROUP_ELSE, 80, $39, > ;C57: if Current Value=LSA1
$8000, 66, $12B, > ;C43: if LBA3=1
$2000, 286, $50, > ;F286: subtract LSA1 from Current Value
$2000, 253, $1E50, > ;F253: divide LSA1 by 30
$2000, 51, $9, > ;F51: disable Key Action (CTRL) forever
$2000, 64, $0, > ;F64: print ExtraNG#0 forever
$8000+TGROUP_ELSE, 80, $39, > ;C57: if Current Value=LSA1
$8000, 66, $2B, > ;C43: if LBA3=0
$2000, 232, $1EFF, > ;F232: set Value 30 in Current Value
$2000, 253, $1E50, >;F253: divide LSA1 by 30
$2000, 233, $150, > ;F233: subtract Value 1 from LSA1
$2000, 64, $0 ;F64 print ExtraNG#0 forever

GlobalTrigger= 2, IGNORE, GT_CONDITION_GROUP, IGNORE, 3, 4, IGNORE
TriggerGroup= 3, $8000, 80, $129, > ;C41: if LSA1 >=1
$8000, 255, $2B, > ;C43: if Current Value=0
$8000, 19, $10C ;C12: if Key R is pressed

TriggerGroup= 4, $2000, 52, $9, > ;F52: enable Key Action (CTRL) again
$2000, 232, $42, > ;F232: set Value 0 in LBA3
$2000, 70, $1F09 ;F70: play Sound Slot#9 (LARA_RELOAD)

TriggerGroup= 5, $2000, 204, $0, > ;F204: remove ExtraNG#0
$2000, 52, $9, > ;F52: enable Key Action (CTRL) again
$2000, 232, $42 ;F232: set Value 0 in LBA3
The explanation of the setup

GlobalTrigger#1 will control the main procedure:


GlobalTrigger#1 will execute TriggerGroup#1 if Lara holds the Uzis, and execute TriggerGroup#5 if she doesn’t.
So, if Lara extracts the Uzis, then TriggerGroup#1 starts executing this at each tick frame, while the weapons are in her hands:

- Two F244 triggers put the actual ammo amount into two variables: Current Value and Local Short Alfa1 (LSA1). (Current Value is constant, you can’t choose another variable, but LSA1 is chosen randomly.)
- Then a C43 condition examines if Lara has any Uzi ammo at all, saying, if LSA1=0 then Lara has no Uzi ammo either in the backpack or the weapons.
- If C43 is true (so if there is no Uzi ammo at all) then an F64 prints ExtraNG#0 on the screen. The string has these contents: #0050/#0800. As you see in NG Center, #0050 is the code of LSA1, #0800 is the code of Current Value. They must be 0 now, so this will be printed on the screen now: 0/0.
- Then a C41 examines if LSA >=1. If it is that means there are some Uzi ammo in the backpack and/or the weapons.
- If C41 is true (so if there are some Uzi ammo) then

= an F118 will execute TriggerGroup#2,
= and a C5 examines if Lara is just shooting or not.

- If she’s shooting then an F232 set Value 1 Local Byte Alfa3 (LBA3, chosen randomly). (We will use the 0 or 1 value of LBA3 later. See below.)

TriggerGroup#2 has four main parts:


a, The red part will be executed everyway (i.e. if the Uzis are extracted, and if Lara has any Uzi ammo anywhere). An F253 will divide LSA1 by 30, and then an F251 will multiply it by 30. (It is 30 for the 30 bullets sized clip pairs.)
Theoretically it seems meaningless, but it is not. Because TRNG can’t handle numbers after the decimal point.
So, for example, if LSA1 (the ammo amount) is 120, then 120/30=4.0, then 4.030=120.
But, if the amount is 110, then 110/30=3.0 (not 3.66!), then 3.030=90.

So, in the first case, LSA1 value remains 120, in the second case LSA1 value turns 110 to 90. – This difference between the two results will be important, as you see just below.

b, After the red part, the values of Current Value and LSA1 are not equal with each other everyway. For example:

- If LSA1 was 120, then it is still 120 after the red part. Current Value is still 120.
- If LSA1 was 110, then it is 90 after the red part. Current Value is still 110.

The green part will be executed if Current Value and LSA1 are not equal any more (see C57 condition).
Now an F286 will subtract LSA1 from Current Value. So if LSA1 is 90 and Current Value is 110, then the new value of Current Value will be 110-90=20.
Then an F253 will divide LSA1 by 30. So, if it is 90, then it will turn into 3 now.
Then an F64 prints ExtraNG#0 on the screen. As I said above, it will show LSA1/Current Value, which is 3/20 now: 3 full clip pairs “in the backpack”, 20 bullets in the weapons.

c, If LBA3=1, that means Lara’s shooting with the Uzis. If Lara’s shooting, plus, if LSA1=Current Value after the red part, that is possible only if the ammo just runs out of the weapons. – Explanation:
- Lara’s shooting, ammo (Current Value) 92. LSA1 is 90.
- Then Lara’s still shooting, ammo (Current Value) 90. LSA1 is 90.

The blue part will be executed if she’s shooting (see C43), plus if LSA1=Current Value (see C57).
Now an F286 will subtract LSA1 from Current Value. So if LSA1 is 90 and Current Value is 90, then the new value of Current Value will be 90-90=0.
Then an F253 will divide LSA1 by 30. So, if it is 90, then it will turn into 3 now.
Then an F51 will disable Key CTRL (preventing from shooting).
Then an F64 prints ExtraNG#0 on the screen. As I said above, it will show LSA1/Current Value, which is 3/0 now: 3 full clip pairs “in the backpack”, 0 bullets in the weapons.

d, If LBA3=0, that means Lara’s not shooting with the Uzis. If Lara’s not shooting, plus, if LSA1=Current Value after the red part, that is possible only:

- if Lara has just extracted an empty weapon, or
- if Lara has just reloaded with Key R.

The brown part will be executed if she’s not shooting (see C41), plus if LSA1=Current Value (see C57).
As I said above, both the operations (extraction, reload) should reload the ammo. So eg. if Current Value=90, LSA1=90, then you won’t see 3/0 now, due to the triggers that will be executed now:
An F232 set Value 30 in Current Value.
Then an F253 will divide LSA1 by 30. So, if it is 90, then it will turn into 3 now.
Then an F233 will subtract Value 1 from LSA1. So if its 3, then it will turn into 2 now.
Then an F64 prints ExtraNG#0 on the screen. As I said above, it will show LSA1/Current Value, which is 2/30 now: 2 full clip pairs “in the backpack”, 30 bullets in the weapons.

GlobalTrigger#2 will control the reload of the weapons:

GlobalTrigger#2 will execute TriggerGroup#4 if the conditions in TriggerGroup#3 are true.

TriggerGroup#3 is true, if LSA1>=1 (so if there is at least 1 clip pairs “in the backpack”, see C41), plus, if Current Value=0 (so if there is no ammo in the weapons, C43), plus if the player hits Key R (see C12).
TriggerGroup#4 will enable CTRL again (see F52), and it will set Value 0 in LBA3 (see F232 – Value 0 is important for the brown part of TriggerGroup#2, that turns the X/0 counter to X-1/30 now), and it will play the reloading sound (see F70).

Note:
As you can see in TriggerGroup#3, Key R condition is used together with “LSA1>=1” variable condition. As I said above, that variable can be used only in this setup. So LSA is always 0 if you use other setups. That is why it is unimportant if other setups also use Key R or not, the two setups won’t disturb each other with that.

TriggerGroup#5 will be executed if Lara holsters the Uzis:

- F204 will remove the counter (ExtraNG#0) from the screen.
- F52 will enable CTRL again.
- F232 will set Value 0 in LBA3 (Value 0 is important for the brown part of TriggerGroup#2, that turns the X/0 counter to X-1/30, if Lara extracts the Uzis the next time).

Customizing the setup

1. If your Uzi clip pairs doesn’t have 30 bullets, but more or less ones (see Customize= CUST_AMMO Script command), then you need to change Value 30 in each trigger that use that value, for the new clip size. (But don’t forget: those triggers can’t handle values above 127. However, you can solve that with other triggers, for example using F287 instead of F253 for dividing. But it is complicated, because F287 uses Current Value that we use for other purpose in this setup.)

2. If you want another weapon instead of the Uzis (to load new clips to the pistols or to load another six bullets into the revolver):

- Check the bullet amount in the triggers of the clips, as I said just above.
- In GlobalTrigger#1, GT_LARA_HOLDS_ITEM needs another HOLD constant, for the given weapon.
- In TriggerGroup#1, you need to change “Uzi ammo” parameter in both the F244 triggers, for the proper ammo type.

If you want both Uzis and another (or more) weapons, then keep the Uzi setup, copy-paste it, then check the GlobalTrigger/TriggerGroup ID’s in the new weapon setup, as I said above. Plus:
In the last TriggerGroup (it is TriggerGroup#5 in the Uzi setup) you need to type one or more exported condition triggers (C35) for the other weapons, before all the executable triggers, in each weapon setup, with TGROUP_NOT flag.
For example, type it in Uzi TriggerGroup, if you also have a setup for pistols:
C35 with TGROUP_NOT: “if Lara doesn’t hold pistols”.
Or, type it in pistols TriggerGroup, if you also have a setup for Uzis and revolvers:
C35 with TGROUP_NOT: “if Lara doesn’t hold Uzis”,
C35 with TGROUP_NOT: “if Lara doesn’t hold revolvers”.

Notes:

- At the same time, Lara can have only one type of weapons in the hands. That is why if you use the setup for more weapons, then feel free to use the same variables in their setups.
- I don’t think you should use this setup with shotgun, grenade gun or crossbow, because in their cases Lara reloads automatically after each shot, by default. (Moreover, in their cases, you should need one more condition, which is possible only with variables: “if X type ammo is loaded”. So, this time, each weapon should have a setup for each of its ammo type.)


Made using TRNG 1.2.2.7.

Last edited by Titak; 25-02-15 at 14:05.
AkyV is online now  
Closed Thread

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 17:42.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.