Custom commands - Autotargeting
Talon
25 Aug 2017, 21:37Trying to do a little coding on my own, have an idea for a bit of gunplay in a game, and i'm giving every for the attribute "enemy" as a script that will run when they are shot.. so player says "Shoot Villain" and it all works fine. I would like the code to work with just saying "Shoot" and checking to see if anything nearby is a valid target. if one isn't specified..
So I added a foreach
Use the recently fired to prevent the player getting a shot at everyone in the room
the Command is pretty basic
Shoot #object#;Shoot
and the script
if (HasScript(object,"enemy")) {
do (object, "enemy")
}
else if (not GetBoolean(player, "recentlyfired")) {
foreach (N, ScopeVisible()) {
if (HasScript(N,"enemy")) {
do (N, "enemy")
SetObjectFlagOn (player, "recentlyfired")
}
}
}

K.V.
25 Aug 2017, 22:19Hello!
Here's how I did that:
Command Pattern: shoot #object#;fire at #object#;shoot at #object#
SCRIPT:
if (Got(revolver)) {
if (revolver.shots > 0) {
if (not HasAttribute(object, "shoot_msg")) {
deadman = "+ object +"
if (HasAttribute(object, "Antag")) {
if (not object.name = "Murphy") {
msg ("You shoot " + object.name + ".")
RemoveObject (object)
revolver.shots = revolver.shots - 1
}
else {
shootMurphy
// msg ("You shoot Murphy. GAME OVER (until I add the rest of the shootout)")
// finish
}
}
else {
msg ("You'd rather not shoot the " + object.name + ".")
}
}
else {
invoke (object.shoot_msg)
}
}
else {
msg ("No more buwwets.")
}
}
else {
msg ("You have no gun.")
}
Then, I just set up a SHOOT command:
Command Pattern: shoot;fire
SCRIPT:
if (Got(revolver)) {
foreach (o, ScopeReachable()) {
if (HasAttribute(o, "Antag")) {
//msg ("Testing Message:")
//msg (o)
HandleSingleCommand ("shoot " + GetDisplayName(o))
}
}
}
else {
msg ("You have no gun.")
}