[bfprog] tk_punish.py and mines
Forrest Thiessen
thiessen at cyberscapearena.com
Sun Jul 17 11:43:21 PDT 2005
ScratchMonkey wrote:
> Has anyone played with changing the TK rules? What's necessary to
> convert a mine punishment to a suicide penalty? I see in the script
> that you get the player and weapon identifier. What's the format of
> the weapon? What do you code to match a mine?
>
> Is there a way to query how long a mine has been deployed? A tossed
> mine kill should still count as a TK, but that can only be done if we
> know how long it's been down.
That's an interesting idea. . . with the "3D map" skull and crossbones
symbol imposed on your field of view right where "friendly" mines are so
hard to miss, I thought it was pretty dumb to drive over one--and dumber
still to punish the guy who laid it.
The PlayerKilled event gives the callback handler a "weaponObject" as a
parameter; you can get the templateName property of this object to get
it's "template" name (something like "usrif_m16a2"), and you can use the
getWeaponType function from bf2.stats.constants to turn the template
name into a weapon category; something like this:
from bf2.stats.constants import *
weaponType = getWeaponType(weaponObject.templateName)
The weaponType you get that way will be 16 generic weapon types defined
at the beginning of the bf2.stats.constants file; if you compare it to
the constant WEAPON_TYPE_ATMINE, you will have a way of telling if a
player was killed by a mine--any type of mine--there's only one right
now, but may be more in mods or expansions in the future).
You ought to be able to insert this code whereever the TK check is done
(I think inside the onPlayerKilled function inside the tk_punish.py
file), and only do the TK processing if the weapon was not a mine. I
haven't looked to see where the suicide penalty is handled, but you
could probably copy some of the code from there into the TK punishment
code, so that if the weapon was a mine they get the suicide treatment:
from bf2.stats.constants import *
weaponType = getWeaponType(weaponObject.templateName)
if weaponType = WEAPON_TYPE_ATMINE:
(Suicide punishment goes here)
else:
(Regular TK punishment goes here)
To your other question, it wouldn't be easy to tell how long a mine is
deployed--there is no "time deployed" attribute, and as far as I can see
deploying a mine fires off no events, so you can't "see" it happening.
HOWEVER, deploying a mine, it seems to me, creates a new object of some
type in the game world; you might be able to create a timer event that
fires off a handler to periodically run
bf2.objectManager.getObjectsOfType('at_mine')
to find all the land mines; you could compare the list with a persistent
list to see if any new ones have popped up since the last time the timer
handler ran, and timestamp the new ones--probably by adding a new
attribute to the land mine objects. Then when someone gets killed by a
mine, you check the timestamp attribute of the weaponObject returned by
the PlayerKilled event to see how long the mine was in place--and then
you can treat recent mines differently than older mines. Yeah, that's
the ticket. . .
I may try playing with this tonight. . .
--Forrest (aka "Woody")
More information about the BFProg
mailing list