Jump to content
Official BF Editor Forums


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

1 Follower

About ScoutStrike

  • Rank

Contact Methods

  • Website URL
  • ICQ

Profile Information

  • Location

Recent Profile Visitors

4,123 profile views
  1. import host import bf2 def init(): host.registerHandler("ChatMessage", onChatMessage) def onChatMessage(index, text, channel, flags): if index == -1: index = 255 player = bf2.playerManager.getPlayerByIndex(index) # search for bad language in 'text' Use something like this. Make sure to call the init() method from the scoringCommon.py init(), or your file won't be loaded. import <file> <file>.init() From http://wiki.igd-studios.co.uk/index.php/Event_Reference That site is a great pile of info on the BF2 Python. Good luck!
  2. You still looking for info on this? Also, how accurate does it have to be? If rough coordinates on the terrain are enough, you might be able to do it like this: - Look at heightmap.py in my mod to get started. This reads heightmapprimary.raw and interpolates between grid points. Modify that to load the terrain into some usable format. - Get the angle and position of the camera. - Then implement some fancy ray tracing to see where the camera ray intersects the terrain. Seems like a lot of work, but not impossible. A big drawback is that objects aren't considered... so if you're looking at a wall it won't register.
  3. Hey, I just noticed this, good job! BF2tech.org has always been my main reference when doing Python work... I was very sad to see it go offline. I did manage to get a few cached pages downloaded after the disaster, but this is much better! Thanks again.
  4. Hello, this post is to inform you guys of the release of a new version of the WOoKie Sniper Mod: 1.3. Please visit our forums to read the official info thread: http://wookie-clan.com/Forum/viewtopic.php?f=91&t=1330 We plan to host a server for the foreseeable future, hope to see you there! We will also organize regular mod nights, since there probably won't be enough players to keep the server populated at all times. Greetings and have fun, Scouty
  5. Bit of an old topic (and surely resolved by now). But I haven't seen a complete solution yet. I think wrapping the whole thing is the neatest way: ### INIT __statuses = { 1 : "Playing", 2 : "EndGame", 3 : "PreGame", 4 : "Paused", 5 : "RestartServer", 6 : "NotConnected", } __functions = { # game status "GameStatusChanged" : [], # server "ServerReady" : [], "BeginRound" : [], "EndRound" : [], # player "PlayerConnect" : [], "PlayerSpawn" : [], "PlayerChangeTeams" : [], "PlayerChangeWeapon" : [], "PlayerChangedSquad" : [], "PlayerScore" : [], "PlayerHealPoint" : [], "PlayerRepairPoint" : [], "PlayerGiveAmmoPoint" : [], "PlayerTeamDamagePoint" : [], "PlayerKilled" : [], "PlayerRevived" : [], "PlayerDeath" : [], "PlayerBanned" : [], "PlayerKicked" : [], "PlayerDisconnect" : [], # vehicle "EnterVehicle" : [], "ExitVehicle" : [], "VehicleDestroyed" : [], # kit "PickupKit" : [], "DropKit" : [], # team "Reset" : [], "ChangedCommander" : [], "ChangedSquadLeader" : [], # game "ControlPointChangedOwner" : [], "TimeLimitReached" : [], "TicketLimitReached" : [], # command "ConsoleSendCommand" : [], "RemoteCommand" : [], "ClientCommand" : [], # misc "PlayerUnlocksResponse" : [], "PlayerAwardsResponse" : [], "ChatMessage" : [], "PlayerStatsResponse" : [], } def init(): host.registerGameStatusHandler(__onGameStatusChanged) for key in __functions.iterkeys(): if key != "GameStatusChanged": host.registerHandler(key, globals()["__on%s" % key], 1) ### EVENTS # game status def __onGameStatusChanged(*args): __trigger("GameStatusChanged", *args) # server def __onServerReady(*args): __trigger("ServerReady", *args) def __onBeginRound(*args): __trigger("BeginRound", *args) def __onEndRound(*args): __trigger("EndRound", *args) # player def __onPlayerConnect(*args): __trigger("PlayerConnect", *args) def __onPlayerSpawn(*args): __trigger("PlayerSpawn", *args) def __onPlayerChangeTeams(*args): __trigger("PlayerChangeTeams", *args) def __onPlayerChangeWeapon(*args): __trigger("PlayerChangeWeapon", *args) def __onPlayerChangedSquad(*args): __trigger("PlayerChangedSquad", *args) def __onPlayerScore(*args): __trigger("PlayerScore", *args) def __onPlayerHealPoint(*args): __trigger("PlayerHealPoint", *args) def __onPlayerRepairPoint(*args): __trigger("PlayerRepairPoint", *args) def __onPlayerGiveAmmoPoint(*args): __trigger("PlayerGiveAmmoPoint", *args) def __onPlayerTeamDamagePoint(*args): __trigger("PlayerTeamDamagePoint", *args) def __onPlayerKilled(*args): __trigger("PlayerKilled", *args) def __onPlayerRevived(*args): __trigger("PlayerRevived", *args) def __onPlayerDeath(*args): __trigger("PlayerDeath", *args) def __onPlayerBanned(*args): __trigger("PlayerBanned", *args) def __onPlayerKicked(*args): __trigger("PlayerKicked", *args) def __onPlayerDisconnect(*args): __trigger("PlayerDisconnect", *args) # vehicle def __onEnterVehicle(*args): __trigger("EnterVehicle", *args) def __onExitVehicle(*args): __trigger("ExitVehicle", *args) def __onVehicleDestroyed(*args): __trigger("VehicleDestroyed", *args) # kit def __onPickupKit(*args): __trigger("PickupKit", *args) def __onDropKit(*args): __trigger("DropKit", *args) # team def __onReset(*args): __trigger("Reset", *args) def __onChangedCommander(*args): __trigger("ChangedCommander", *args) def __onChangedSquadLeader(*args): __trigger("ChangedSquadLeader", *args) # game def __onControlPointChangedOwner(*args): __trigger("ControlPointChangedOwner", *args) def __onTimeLimitReached(*args): __trigger("TimeLimitReached", *args) def __onTicketLimitReached(*args): __trigger("TicketLimitReached", *args) # command def __onConsoleSendCommand(*args): __trigger("ConsoleSendCommand", *args) def __onRemoteCommand(*args): __trigger("RemoteCommand", *args) def __onClientCommand(*args): __trigger("ClientCommand", *args) # misc def __onPlayerUnlocksResponse(*args): __trigger("PlayerUnlocksResponse", *args) def __onPlayerAwardsResponse(*args): __trigger("PlayerAwardsResponse", *args) def __onChatMessage(*args): __trigger("ChatMessage", *args) def __onPlayerStatsResponse(*args): __trigger("PlayerStatsResponse", *args) ### PRIVATE METHODS def __trigger(event, *args): # print event info if event == "GameStatusChanged": print "event: %s (%s)" % (event, __statuses.get(args[0])) else: print "event: %s" % event # call registered functions for function in __functions.get(event): try: print " function: %s.%s" % (function.func_globals['__name__'], function.__name__) function(*args) except: common.exception() ### PUBLIC METHODS def register(event, function): # register callback functions = __functions.get(event) if function not in functions: functions.append(function) def unregister(event, function): # unregister callback functions = __functions.get(event) if function in functions: functions.remove(function) def unregisterall(): for value in __functions.itervalues(): value[:] = [] All other python scripts register their events here instead: def init(): event.register("GameStatusChanged", onGameStatusChanged) Then you just need to make sure something calls unregisterall() between modes, or the script themselves know when to call unregister(). So far I haven't noticed any performance issues associated with registering ALL events in advance, and only calling functions when needed.
  6. Plus, BF2 has a built-in python package (based on 2.3.4), that cannot be changed. So if something isn't included there (like .zip support, I tried), there's no way to put it back in. Sad, I know.
  7. ScoutStrike


    If you want to give them just ammo... I'd make a copy of the supply_crate object, remove the health storage, and reward players by spawning that near them. It's a huge workaround for what I think you're trying to do (access player ammo directly). Edit - But you could spawn it, give it a very high resupply rate, and a small storage, so it'll be almost instant.
  8. Is there a way to only show your own trail effects? I tried setting ObjectTemplate.showInThirdPerson 0, but that removes the effect entirely (maybe because it's tied to the bullet, not the gun?). Tracer templates don't seem to have a whole lot of options. My cheap copy of the e_riflegrenade: ObjectTemplate.create EffectBundle e_tracer ObjectTemplate.cullRadiusScale 100 ObjectTemplate.createdInEditor 1 rem *** Generated with Bf2Editor.exe [created: 2005/3/22 17:49] ObjectTemplate.activeSafe EffectBundle e_tracer ObjectTemplate.modifiedByUser dsu ObjectTemplate.saveInSeparateFile 1 ObjectTemplate.createdInEditor 1 ObjectTemplate.floaterMod 0 ObjectTemplate.hasMobilePhysics 0 rem ------------------------------------- ObjectTemplate.addTemplate S_e_tracer_Start ObjectTemplate.addTemplate em_tracer_stripe rem ------------------------------------- ObjectTemplate.setStartOnEffects 0 ObjectTemplate.setStopOnEffects 0 ObjectTemplate.timeToLive CRD_NONE/-1/0/0 ObjectTemplate.randomAgeFactor CRD_NONE/1/0/0 ObjectTemplate.startAtCreation 0 ObjectTemplate.speedFromPhysics 0 ObjectTemplate.activeSafe Sound S_e_tracer_Start ObjectTemplate.modifiedByUser dsu ObjectTemplate.create TrailSystem em_tracer_stripe ObjectTemplate.cullRadiusScale 100 ObjectTemplate.modifiedByUser dsu ObjectTemplate.createdInEditor 1 ObjectTemplate.showInFirstPerson 1 ObjectTemplate.showInThirdPerson 1 ObjectTemplate.emitPrio High ObjectTemplate.lodDistance 9999 ObjectTemplate.qualityLevel Low ObjectTemplate.emitterType Standard ObjectTemplate.isLocalSystem 0 ObjectTemplate.emitRadius 0/0/0 ObjectTemplate.emitRangeX CRD_NONE/0/0/0 ObjectTemplate.emitRangeY CRD_NONE/0/0/0 ObjectTemplate.emitRangeZ CRD_NONE/0/0/0 ObjectTemplate.randomRadialDirection 360 ObjectTemplate.radialDirection 0 ObjectTemplate.emitFrequency 15 ObjectTemplate.preWarmTime 0 ObjectTemplate.emitTime 0 ObjectTemplate.emitDelay 0 ObjectTemplate.isLooping 0 ObjectTemplate.emitSpeed 1 ObjectTemplate.emitDirection 0/0/-1 ObjectTemplate.timeToLive 5 ObjectTemplate.randomTimeToLive 0 ObjectTemplate.windAffectionFactor 0 ObjectTemplate.forceToWaterSurface 0 ObjectTemplate.waterSurfaceOffset 0.03 ObjectTemplate.rotationGraph 0/0/0/0 ObjectTemplate.alignRotationToSpeed 1 ObjectTemplate.transparencyGraph 0/0.4/-1/0.6 ObjectTemplate.gravity 0 ObjectTemplate.gravityGraph 0/0/0/1 ObjectTemplate.airResistanceGraph 0/0/0/1 ObjectTemplate.emitSpeedGraph 0/0/0/1 ObjectTemplate.randomSpeed 0 ObjectTemplate.randomDirectionAngle 0/0/0 ObjectTemplate.airResistance 0 ObjectTemplate.collisionEnable 0 ObjectTemplate.collisionSpeedAlongNormal 0.7 ObjectTemplate.collisionSpeedAlongPlane 0.8 ObjectTemplate.randomSize 0 ObjectTemplate.particleMaxSize 0.6 ObjectTemplate.sizeGraph 0/0.39/0.51/0.1 ObjectTemplate.randomIntensity 0 ObjectTemplate.lightMapIntensityOffset 0.5 ObjectTemplate.color1 1/1/1 ObjectTemplate.color2 0.901961/0.901961/0.901961 ObjectTemplate.colorBlendGraph 0/0/1/0 ObjectTemplate.alphaCull 0.2 ObjectTemplate.textureName objects\effects\textures\animated\anim_smoketrail2 ObjectTemplate.animationEnable 1 ObjectTemplate.animationSpeed 5 ObjectTemplate.setAnimationFrameWidthRelative 0.25 ObjectTemplate.setAnimationFrameHeightRelative 0.25 ObjectTemplate.animationFrameCount 16 ObjectTemplate.animationFrameCountX 4 ObjectTemplate.fadeInFactor 0 ObjectTemplate.fadeOutFactor 0 ObjectTemplate.textureTileFactor 1 ObjectTemplate.textureOffsetVelocity 0 ObjectTemplate.numPlanes 3 ObjectTemplate.minTrailVelocity 0
  9. Python only crashes the server in rare cases (after the initial startup that is). What are you trying to do?
  10. Are you sure you're not triggering an infinite loop by sending a chat message inside the ChatMessage event?
  11. Err, it might be a small thing, but I don't think you're supposed to import bf2.PlayerManager yourself. BF2 makes a singleton reference itself in bf2\__init__.py: # set up singletons import bf2.PlayerManager playerManager = bf2.PlayerManager.PlayerManager() Use instead: player = bf2.playerManager.getPlayerByIndex(playerID) In any case, I suggest you get some debugging output going. debug.py ### INIT import sys import host import bf2 ### INIT def modinit(): # enable debugging sys.stdout = logfile("stdout") sys.stderr = logfile("stderr") ### METHODS def exception(): sys.excepthook(*sys.exc_info()) ### CLASSES class logfile: def __init__(self, name): self.file = open("%s/python/%s.txt" % (host.sgl_getModDirectory(), name), 'w') self.buffer = "" def flush(self): self.file.flush() def close(self): self.file.close() def write(self, string): if string is not None and len(string) > 0: self.buffer += string if self.buffer.endswith("\n"): self.file.write("[%.3f] %s" % (host.timer_getWallTime(), self.buffer)) self.file.flush() self.buffer = "" Import and init this first, so any following errors get handled. Then enclose all your events and timer functions with try/except blocks: def onTrigger(self): try: print "timer: Once" except: debug.exception() Then you'll get nice exception information in the text file logs if something goes wrong. Remember the explicit try/catch, BF2 eats all errors by default.
  12. ScoutStrike

    Player Limit

    Damn don't get me started on those nubcakes. I finally have 63 of them in one team that sit still so you can shoot them!
  13. Are you sure that channel works? I'm not really sure about any of them, except the main server chat: host.sgl_sendTextMessage(0, 12, 1, text, 0) Also, has the round started? If not, and you want events to trigger, you need to add the optional parameter: host.registerHandler('ChatMessage', myChatMessage, 1)
  14. ScoutStrike

    Player Limit

    It shouldn't be too difficult, you have access to all the events and methods you need. Below is a quick draft of how I'd do it: import host import bf2 ### INIT def init(): host.registerHandler("PlayerConnect", onPlayerConnect, 1) host.registerHandler("PlayerChangeTeams", onPlayerChangeTeams, 1) host.registerHandler("PlayerDeath", onPlayerDeath, 1) ### EVENTS def onPlayerConnect(player): checkTeams(player) def onPlayerChangeTeams(player, isHuman): checkTeams(player) def onPlayerDeath(player, soldier): checkTeams(player) ### METHODS def checkTeams(player): if player.getTeam() == 1: if bf2.playerManager.getNumberOfPlayersInTeam(1) > 10: player.setTeam(2) message("putting player %s in team 2" % player.getName()) def message(text): host.sgl_sendTextMessage(0, 12, 1, text, 0) You need to import this script, and call the init() method to activate it (do that in scoringCommon.py).
  15. Ah, this event works fine, but there's a slight issue with the index you receive. On local servers or in singleplayer, your own ID is wrong. Add this: if playerID == -1: playerID = 255
  • Create New...