Part 4 updated!
[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
[highlight=e2]@name Advanced Landmine
@inputs Button
@outputs Detonate
@persist Plate:vector True
#Whenever you update the Epression it won't explode
if (first()) {Plate=entity()os()}
#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()os()
#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}
[/highlight]
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:
[highlight=e2]if (first()) {Plate=entity()os()}[/highlight]
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:
[highlight=e2]runOnTick(1)[/highlight]
Makes it run every 10 millisecond.
Line 3:
[highlight=e2]if (entity():isWeldedTo():isPlayerHolding()) {True=0}[/highlight]
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:
[highlight=e2]Plate=entity()os()[/highlight]
Updates the position of the expression
Line 5:
[highlight=e2]if (True==0&$Plate==vec(0,0,0)) {True=1}[/highlight]
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:
[highlight=e2]if ($Plate&Button&True) {Detonate=1}[/highlight]
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:
[highlight=e2]else {Detonate=0}[/highlight]
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
[highlight=e2]@name Chatmine
@inputs Button
@outputs Detonate
@persist Plate:vector True ChatActivate
#Whenever you update the Epression it won't explode
if (first()) {Plate=entity()os()}
#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()os()
#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}[/highlight]
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):
[highlight=e2]Arg=owner():lastSaid()[/highlight]
Makes the variable Arg become the last thing you said and is saved as a string.
Line 2 (changed):
[highlight=e2]if (Arg=="/act") {Chat=1}[/highlight]
If the variable Arg is equal to that you said "/act" Chat is equal to 1.
Line 3 (changed):
[highlight=e2]elseif (Arg=="/deact") {Chat=0}[/highlight]
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.
Last edited by singilli; 07-04-2009 at 09:38 AM.
Part 4 updated!
bumpity bump
Instead of the button you could use a chatController... and why you don't apply the phx plate model to the explosive?
I know, I'm going into chat controllers later on. And what is the second thing you are talking about?
You should change the model of the e2 (wire_expression2_model [modelpath]) or the model of the explosive so that you don't need an extra prop.
And please don't use chat commands... or everyone will know if you activate the mine.
But anyway: Nice Landmine I like the idea to be able to pick it up![]()
Any spelling or grammar mistake is just to amuse you and may be kept by the finder ^_^
You could use a chat command to arm it though, and then perhaps E:aimEntity() and E:keyUse() to deactivate it.
Why want everyone to use chat commands? they are ******* ****.
I suggest to do it like Lying said but activate it with it too and use hints for status.
Any spelling or grammar mistake is just to amuse you and may be kept by the finder ^_^
Using chat commands however would allow them to activate them all simultaneously. Using my idea for both activation and deactivation would be very time consuming when laying a field of mines.
[highlight=e2]@name Chatmine
@inputs Button
@outputs Detonate
@persist Plate:vector True ChatActivate
#Whenever you update the Epression it won't explode
if (first()) {Plate=entity()os()}
#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()os()
#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}[/highlight]
Someone asked for code with chatcommands. Here it is. That is nothing special it doesn't include any super hard commands just your very basic Chatmine as I like to call it.
Added to top post
Last edited by singilli; 06-29-2009 at 01:44 PM.
Bookmarks