Talk:Object Reference

From BF2 Technical Information Wiki
Revision as of 13:18, 7 February 2011 by Woody (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Getting the object a player is pointing at

I want to get the object a player is pointing at. Any ideas? --Mic23 08:28, 8 Sep 2005 (MDT)


You should be able to code it, its just a question of how much effort you want to put into it. As far as I know there is no easy way of finding what a player is looking at.

I do have an idea of how to do it though. It would require getting a player's camera object, and seeing where it is pointed. Then you would need to do some math functions to determine the player's FOV box, and what objects fall into it. Cameras and FOV for players is fairly common and many 3D video game books cover implementions, just not in Python.

As far as my understanding goes, you can find what is in a player's view by extending a pyramid from the player's camera, and check the position of objects to see if their coordinates fall into this pyramid. Hope I didn't confuse you too much! Good luck!

--King of Camelot 17:17, 8 Sep 2005 (MDT)

I actually did some work on exactly this, and came to the same conclusion King of Camelot did. With (serious) work, you can guess what the play might be looking at, but your guesses will frequently be wrong, with your only hope really being if you limit yourself to objects that are quite close (a few meters) to the player. --Woody 19:29, 8 Sep 2005 (MDT)

Thanks Guys for your quick answers. I was at the point to give up hope of any easy solution too ; ) Maybe there is an undiscovered method or so. Fortunately I just have to get the object that the player is pointing at with the crosshair. So I should be able to get by with a straight line instead of a pyramid.

However, do you know a method of getting objects from this straight line? My approach would be to get the positions of every single object in advance and then question this "dataset" for the appropriate objects.

Is there a better way? Thanks again for your help guys.

--Mic23 03:41, 9 Sep 2005 (MDT)

Is there a way to get the static objects like buildings?

--Mic23 06:06, 9 Sep 2005 (MDT)

I don't know of an easy way to do the straight line method, but you seem to be on the right track with your "dataset". The main reason I mentioned the pyramid over the straight line is because of the way BF2 handles object positions. When you get an object's position, the coordinates it returns are referring to a position in the middle of an object. Using the straight line method, I could be looking at the cockpit on a helicopter, but if the object's center point isn't right where I am looking the straight line method.

The most accurate to find what a player is looking at would involve using the collision meshes of objects, which would become a monster coding project for you and would probably prove too resource hungary to run. Unfortunately there is no easy way to find what a player is looking at, but I would love to be proved wrong! Keep at it, where theres a will theres a way, and you may just discover an easy way of doing it.

--King of Camelot 21:30, 9 Sep 2005 (MDT)

Section Structure

Could we possibly split up each major module into seperate pages? This particular page is getting very heavy on content and is becoming a bit difficult to traverse.

We also need information on the standard_admin and game modules. I may go ahead and add information on using those in a bit. --Dackz 10:12, 18 Aug 2005 (MDT)

Yes, it is getting large; I'll give some thought to how it might be reorganized. Personally, it's working for me as-is: I use the table of contents at the top of the page, and/or my browser search function, to find what I need. I understand what you mean, though. Anyone else's experience? One downside to reorganizing into multiple pages: it would break all the links in the wiki that refer to this page. Hmmm. . . --Woody 10:43, 18 Aug 2005 (MDT)

I agree that the table of contents is your bestest friend ever. I particularly enjoy being able to get all the info on one page, and think that I'd be more hindered than helped by the splitting of the content. --dst 15:34, 18 Aug 2005 (MDT)

String Concatenation

Im not entirly sure whats going on, take for instance the code...


if vehicleType == VEHICLE_TYPE_SOLDIER:
  pass
else:
  timeString = wallString()
  playerTeam = str(player.getTeam())
  logfile.write("ENTER PlayerName=" + player.getName() + " PlayerTeam=" + playerTeam + " VehicleName=" + rootVehicle.templateName + " Time=" + timeString + "\n")
  player.fa.enterAt = date()
  player.fa.enterTemplate = rootVehicle.templateName

...now instead of...

"VehicleName=" + rootVehicle.templateName + " Time="

...try...

"VehicleName=" + vehicleType + " Time="

...this causes the line that fragalizer should print out, to not show up. Any ideas?

Answer

Answer: Python is a weakly-typed language, meaning that you can pass data of any type you want around willy-nilly, but those data objects still, nevertheless, do have types. In your example, "VehicleName=" is a string, but vehicleType is a number, and you can't "add" strings and numbers in Python--they're different types (contrast with Perl, which will happily make loads of assumptions about what you "really" wanted). When your line of code is executed, Python raises an unhandled exception, which the embedded Python interpreter appears to handle by just giving up--which is why you don't get any output.

Instead, try

 "VehicleName=" + str(vehicleType) + " Time="

and you should get what you want. --Woody

Response

String concatenation and type coercion example/guide

Python is dynamically and strongly typed

-- Doulostheos 14:14, 9 Jul 2005 (MDT)

sendMessage oddities

When ever i call bf2.gameLogic.sendServerMessage(playerid, message) i get the error: tuple index out of range.

I am very new to Python, but it looks to me like a tuple is expected somewhere? I tried calling as:

bf2.gameLogic.sendServerMessage(issuer.index, ('HELLO', 1, 1, 1, 1))

and

bf2.gameLogic.sendServerMessage(issuer.index, 'HELLO')

but i still receive the same error. Anyone had any luck with this one yet? - Danni

I did some experimenting with it--it looks to me like the code for sendServerMessage (found in bf2.GameLogic) has a bug in it. sendServerMessage is just a wrapper around the host.sgl_sendTextMessage method. . . a method that has one more parameter than the sendServerMessage wrapper includes in its call to it! If you call host.sgl_sendTextMessage directly, instead, and include the correct number of parameters, that should work. Ctz found the way to do this is:

 host.sgl_sendTextMessage(playerID, 12, 1, message, 0)

No, I have no clue what the "12", "1", and "0" are yet--but the last parameter, "0" is what is missing in the definition of sendServerMessage. --Woody

I have a list of channels (the second parameter, after playerID). examples of channels are Global, LocalTeam, LocalMedic etc. I haven't got this to work yet, only parameter 12 works (channel ServerMessage). It's bugged or only fires on a special combination of parameters. I'll post the channel list tonight. --=Mad=

I also found that (playerid, 12, 1, message, 0) worked, but i also found that if you change the third parameter from 1 to 2 it comes up as the player chat instead of a server message. Oh and don't try 4, it crashes. --Danni

unableToChangeTeam

hi, I try to set value of unableToChangeTeam(Control Point property) with cp_setParam('unableToChangeTeam', 1) but it don't work... you know why? thk


Not everything can be set with cp_setParam, unabletoChangeTeam is one of them. The list is also uncomplete there are a number of controlpoint properties not yet listed here (about ~10 of them). What properties can be set and which not has not yet been investigated thoroughly. --=Mad= 13:08, 18 Jul 2005 (MDT)

Object.Token

Anyone know of the relevance of tokens? I know they are have to do with the embedded Python interperter, but so far they seem to have no use. Its no like EA to add anything extra, so tokens have to have some use. --King of Camelot 19:08, 8 Aug 2005 (MDT)

I was looking at tokens a while back; they are objects of type "PyCObject", which is a little unusual: PyCObjects are native C-language objects that aren't directly usable within Python, but are sometimes passed to embedded Python code just so Python can pass them back to another C function later. My guess (only a guess) is that they are pointers to the original game world objects in the BF2 engine. --Woody 20:20, 8 Aug 2005 (MDT)

Ok, so we have an idea of what they are....now what can we do with them, if anything? --King of Camelot 01:43, 9 Aug 2005 (MDT)

Well, by their nature, PyCObjects aren't usable within Python (they are "opaque"), so the only possibility would be if there is a game engine function (for example, a method of the host module) that took "tokens" as a parameter--then you could use them as arguments to pass to that function. I haven't seen any such functions, though (yet). It may be that it's something DICE put in because they thought it would come in handy, but that they haven't actually found a use for yet. So, as a practical matter, I don't think there's anything you can use them for at this point (I'd love to be proven wrong. . .). --Woody 10:07, 9 Aug 2005 (MDT)

Changes in 1.03

I think we should list any changes that we notice in the 1.03 patch here, as long as they are relevant to the page. Heres what I've noticed so far:

host.sgl_sendTextMessage(playerId, 12, 1, message, 0) has become host.sgl_sendTextMessage(playerId, 10, 1, message)

  • It appears they took off the last 0, and changed the channel to 10. I haven't tested it, but maybe this means it works correctly now?

host.sgl_sendHudEvent(player.index, event, data) is new

  • This looks interesting, atleast they aren't ignoring the Python in patchs.


Great idea to add this information! It probably deserves it's own page. For that matter, it would be good to document the changes from 1.0 to 1.01--for example, I noticed that 1.0 had some scripting for whole game mode (Supply Lines) that they stripped out of 1.01. --Woody 19:21, 5 Oct 2005 (MDT)

Just did a quick test, and can't get host.sgl_sendTextMessage(playerId, 12, 1, message, 0) or host.sgl_sendTextMessage(playerId, 10, 1, message) working. --Quade 07:33, 7 Oct 2005 (MDT)


bf2.Timer

You must import bf2.Timer to create timer objects.

In __init__.py in the bf2 directory, line 4 makes the need to import bf2.Timer after importing bf2 unnecessary:

4 from bf2.Timer import Timer

It never hurts to import it, of course, but this particular line might be better of either disappearing or being changed to "You must import bf2 to create timer objects." unless I'm completely nuts. :) --dst 14:12, 13 Oct 2005 (MDT)

Remove or hide an object?

Is there any way to remove or hide such as a vehicle an object via python?

Or if that's not possible, what about making a vehicle invulnerable?

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox