[ame="http://www.youtube.com/watch?v=zysvYraOZfw"]YouTube - Enginn's tutorial #2 - Advanced landmine (E2)[/ame]
Now includes ChatMine at bottom as requested.
Whenever you pick up the prop the e2 was spawned on it will not explode, when it comes to a stop it will arm that part of the explosive again.
Advanced Landmine:
Part 1 - Building the contraption
1. First spawn a PHX 1x1 plate, freeze it.
2. Place a wired "Button" onto the plate toggled with Value on: 1 and Value off: 0, it is under Wire - I/O.
3. Place an "Explosive" and make sure the trigger value is at 1 other options are up to you, it is under Wire - Physics.
Part 2 - The expression 2
e2 Code:
@name Advanced Landmine
@inputs Button
@outputs Detonate
@persist Plate:vector True
#Whenever you update the Epression it won't explode
if (first()) {Plate=entity():pos()}
#Makes it run every game tick or 10 milliseconds, this way it won't be affected by lag
runOnTick(1)
#If player holds the entity the Expression is welded to the explosive can't explode
if (entity():isWeldedTo():isPlayerHolding()) {True=0}
#Gets the position of the expression as a vector
Plate=entity():pos()
#If True equal 0 and the plate has stopped moving True is set to 1 again and that part of the explosive gets armed
if (True==0&$Plate==vec(0,0,0)) {True=1}
#If the delta of the plate is not 0/if it has moved, the button is 1 and True is 1 Detonate is 1 else Detonate is 0
if ($Plate&Button&True) {Detonate=1}
#Self explanatory
else {Detonate=0}
Copy and paste the code and place the expression
Part 3 - Wiring it all up
1. Wire the "Button" input of the expression to the "Button".
2. Wire the Explosives "Detonate" to the "Detonate" output of the expression.
Part 4 - Better understanding of the expression used
Line 1:
e2 Code:
if (first()) {Plate=entity():pos()}
If it's the first run of the expression it will get the vector position of the Plate so it doesn't blow it when you update it.
Line 2:
Makes it run every 10 millisecond.
Line 3:
e2 Code:
if (entity():isWeldedTo():isPlayerHolding()) {True=0}
If you hold the entity the expression is welded to with the physgun, it will make the variable True equal to 0. If True is 0 the explosive can't explode.
Line 4:
Updates the position of the expression
Line 5:
e2 Code:
if (True==0&$Plate==vec(0,0,0)) {True=1}
If the variable True is equal to 0 and the Delta of the vector of the plate is 0/the Plate variable is not moving. It makes the True variable 1 and thus arming that part of the bomb.
Line 6:
e2 Code:
if ($Plate&Button&True) {Detonate=1}
If the Delta of the expression is changing/the expresion is moving and the Button is equal to 1 and True is equal to 1 Detonate = 1.
Line 7:
If one of the variables at line 6 is not equal to 1, Detonate is equal to 0.
-------------------------------------------------------------------------------------------------------
ChatMine:
Part 1 - Building the contraption
1. First spawn a PHX 1x1 plate, freeze it.
2. Place an "Explosive" and make sure the trigger value is at 1 other options are up to you, it is under Wire - Physics.
Part 2 - The expression 2
e2 Code:
@name Chatmine
@inputs Button
@outputs Detonate
@persist Plate:vector True ChatActivate
#Whenever you update the Epression it won't explode
if (first()) {Plate=entity():pos()}
#Makes it run every game tick or 10 milliseconds, this way it won't be affected by lag
runOnTick(1)
#Saves the last thing the owner said as the variable Arg
Arg=owner():lastSaid()
#If you say /act it will activate the mine
if (Arg=="/act") {Chat=1}
#Else if you say /deact it will deactivate the mine
elseif (Arg=="/deact") {Chat=0}
#If player holds the entity the Expression is welded to the explosive can't explode
if (entity():isWeldedTo():isPlayerHolding()) {True=0}
#Gets the position of the expression as a vector
Plate=entity():pos()
#If True equal 0 and the plate has stopped moving True is set to 1 again and the explosive gets armed
if (True==0&$Plate==vec(0,0,0)) {True=1}
#If the delta of the plate is not 0/if it has moved, the button is 1 and True is 1 Detonate is 1 else Detonate is 0
if ($Plate&Chat&True) {Detonate=1}
#Self explanatory
else {Detonate=0}
Copy and paste the code and place the expression
Part 3 - Wiring it up
1. Wire the Explosives "Detonate" to the "Detonate" output of the expression.
Part 4 - Better understanding of the expression used
Line 1 (changed):
Makes the variable Arg become the last thing you said and is saved as a string.
Line 2 (changed):
e2 Code:
if (Arg=="/act") {Chat=1}
If the variable Arg is equal to that you said "/act" Chat is equal to 1.
Line 3 (changed):
e2 Code:
elseif (Arg=="/deact") {Chat=0}
Else if the variable Arg is equal to "/deact" Chat is equal to 0.
Do note that I just threw this code in and it's very inefficient, ask for help if you want to know how to make it more efficient.
Bookmarks