flysouth Posted July 27, 2016 Share Posted July 27, 2016 When driving a vehicle if I crash into a rock or tree I would like to know what I collided with. It would also be good if I could affect the object I hit. Trees and rocks are TSStatic.In vehicle.cs I used onCollision and onImpact, in these functions have tried using %col.getClassName(), %col.getType(), %col.GetName(), %col.GetTargetName(0), %col.GetInternalName() etc. but nothing works.The script document indicates that most of these should be valid for a TSStatic but some of them give an error when calling them.So how do I get this information? Quote Link to comment Share on other sites More sharing options...
flysouth Posted July 28, 2016 Author Share Posted July 28, 2016 Anybody know how to do this... or is it the standard answer... you need to change the C++ code? Quote Link to comment Share on other sites More sharing options...
Bloodknight Posted July 29, 2016 Share Posted July 29, 2016 The answer is always to change the C++ code if you cannot learn how to be flexible.You need to check on the callbacks, some objects have onCollision callbacks some do not, as I recall TSStatics are pretty much geometry only, they aren't real objects, if you want to know hat your running over then you need to change the objects to a scripted object type, but bear in mind this will obviously have some overhead.Coding alternatives are to create a new lightweight class based on tsstatic and add a few choice options or alter the tsstatic class if you want all objects to be smart objects in some way.Also, I feel I should add, that for a decade or so now I have been the community leader as far as grumpy sarcastic is concerned, and feel you are cruising a little close to my turf, also I should warn you that this is a poor way of getting answers, trust me, I'm an expert. Quote Link to comment Share on other sites More sharing options...
Azaezel Posted July 29, 2016 Share Posted July 29, 2016 couple notes to mull on:1) .dump() will dump out every variable and method attached to a given objectid (including datablocks) into the console for a (bruteforce, but quick) look at what yo've got to work with en-toto.2) any variable can be tacked on to any class at any point in time and be referenced by the server or client depending on where you're shoving the data. (gets a bit trickier with replication of data so it's there on both server and all connected clients)full .dump() from that particular shot: Class: TSStatic Static Fields: bool allowPlayerStep = "0" bool alphaFadeEnable = "0" float alphaFadeEnd = "150" bool alphaFadeInverse = "0" float alphaFadeStart = "100" bool canSave = "1" bool canSaveDynamicFields = "1" TSMeshType collisionType = "Collision Mesh" string cubeReflectorDesc = "" TSMeshType decalType = "Collision Mesh" int forceDetail = "-1" bool hidden = "0" bool isRenderEnabled = "1" bool isSelectionEnabled = "true" bool locked = "0" bool meshCulling = "0" int mountNode = "-1" pid mountPID = "" MatrixPosition mountPos = "0 0 0" MatrixRotation mountRot = "1 0 0 0" bool originSort = "0" SimObject parentGroup = "MissionGroup" pid persistentId = "" bool playAmbient = "1" MatrixPosition position = "12.8895 -2.18239 238.765" float renderNormals = "0" MatrixRotation Rotation = "1 0 0 0" Point3F scale = "1 1 1" filename shapeName = "art/shapes/rocks/rock1.dts" Dynamic Fields: Methods: bool acceptsAsChild( SimObject obj ) void add( SimObject objects... ) void assignFieldsFrom( SimObject fromObject ) void assignPersistentId() void bringToFront( SimObject obj ) string call( string method, string args... ) void callOnChildren( string method, string args... ) void callOnChildrenNoRecurse( string method, string args... ) void changeMaterial( string mapTo="", Material oldMat=NULL, Material newMat=NULL ) void clear() void clearScopeToClient( NetConnection client ) string clone() string deepClone() void delete() void deleteAllObjects() void dump( bool detailed=false ) void dumpClassHierarchy() void dumpGroupHierarchy() string dumpMethods() string findObjectByInternalName( string internalName, bool searchChildren=false ) bool getCanSave() string getClassName() string getClassNamespace() int getClientObject() int getCount() int getDeclarationLine() string getDynamicField( int index ) int getDynamicFieldCount() string getEulerRotation() string getField( int index ) int getFieldCount() string getFieldType( string fieldName ) string getFieldValue( string fieldName, int index=-1 ) string getFilename() string getForwardVector() int getFullCount() int getGhostID() string getGroup() int getId() string getInternalName() string getInverseTransform() string getModelFile() int getMountedObject( int slot ) int getMountedObjectCount() int getMountedObjectNode( int slot ) int getMountNodeObject( int node ) string getName() string getObject( int index ) string getObjectBox() int getObjectIndex( SimObject obj ) int getObjectMount() string getPosition() string getRandom() string getRightVector() string getScale() int getServerObject() string getSuperClassNamespace() int getTargetCount() string getTargetName( int index=0 ) string getTransform() int getType() string getUpVector() string getWorldBox() string getWorldBoxCenter() bool isChildOfGroup( SimGroup group ) bool isClientObject() bool isEditorOnly() bool isExpanded() bool isField( string fieldName ) bool isGlobalBounds() bool isInNamespaceHierarchy( string name ) bool isMember( SimObject obj ) bool isMemberOfClass( string className ) bool isMethod( string methodName ) bool isMounted() bool isNameChangeAllowed() bool isSelected() bool isServerObject() void listObjects() bool mountObject( SceneObject objB, int slot, TransformF txfm=MatrixF::Identity ) onDefineFieldTypes() void pushToBack( SimObject obj ) void remove( SimObject objects... ) void reorderChild( SimObject child1, SimObject child2 ) bool save( string fileName, bool selectedOnly=false, string preAppendString="" ) int schedule( float time, string method, string args... ) void scopeToClient( NetConnection client ) void setCanSave( bool value=true ) void setClassNamespace( string name ) void setEditorOnly( bool value=true ) void setFieldType( string fieldName, string type ) bool setFieldValue( string fieldName, string value, int index=-1 ) void setFilename( string fileName ) void setHidden( bool value=true ) void setInternalName( string newInternalName ) void setIsExpanded( bool state=true ) void setIsSelected( bool state=true ) void setLocked( bool value=true ) void setName( string newName ) void setNameChangeAllowed( bool value=true ) void setPosition( Point3F pos ) void setScale( Point3F scale ) void setScopeAlways() void setSuperClassNamespace( string name ) void setTransform( TransformF txfm ) void sort( string callbackFunction ) void unmount() bool unmountObject( SceneObject target ) Callbacks: onObjectAdded( SimObject object ) onObjectRemoved( SimObject object ) probably the simplest way of returning 'this was a rock' would be to shove all your rocks in a directory and look up the shapeName for instance, if you don't want to specifically tag each object with a type variable, for instance. Quote Link to comment Share on other sites More sharing options...
rlranft Posted July 29, 2016 Share Posted July 29, 2016 In vehicle.cs I used onCollision and onImpact, in these functions have tried using %col.getClassName(), %col.getType(), %col.GetName(), %col.GetTargetName(0), %col.GetInternalName() etc. but nothing works.If you don't name every rock and tree in your level how do you know the getName() methods don't work? Same for getInternalName() - if it's not set it is an empty string.Of course, getClassName() may or may not work - could just try %obj.class and see what's in that, along with %obj.name. Some objects don't have the getters defined and simply use an exposed field. You can always look in the source (Engine/source/T3D/tsStatic.h and Engine/source/T3D/tsStatic.cpp) to see what is implemented (looking at that dump getClassName() should work, and getName() should work if the object has a name). Quote Link to comment Share on other sites More sharing options...
flysouth Posted July 29, 2016 Author Share Posted July 29, 2016 @BloodknightAlso, I feel I should add, that for a decade or so now I have been the community leader as far as grumpy sarcastic is concerned, and feel you are cruising a little close to my turf, also I should warn you that this is a poor way of getting answers, trust me, I'm an expert.That is most likely true. It is just that almost everything that I want to do with T3D has amounted to ..you need to change the c++ code for that. So I have just become a little frustrated. :cry: The rock does have a name and when the vehicle hits it the onImpact is called. In my onimpact function I have the following statements to see which works: function VehicleData::onImpact(%this, %obj, %col, %vec, %speed) { echo("This = ",%this.getName()); echo("Obj = ",%obj.getName()); echo("Col = ",%col.getName()); echo("Col Type = ",%col.getType()); echo("Vec = ",%vec); echo("Speed = ",%speed); echo("Class =" ,%col.class); echo("ClassName =" ,%col.getClassName()); echo("TargetName =",%col.GetTargetName(0)); } and the result is:This = CheetahCarObj = Cheeta1scripts/server/vehicle.cs (151): Unable to find object: '0' attempting to call function 'getName'Col = scripts/server/vehicle.cs (152): Unable to find object: '0' attempting to call function 'getType'Col Type = Vec = -13.4593 -32.5138 2.24118Speed = 35.2608Class =scripts/server/vehicle.cs (156): Unable to find object: '0' attempting to call function 'getClassName'ClassName =scripts/server/vehicle.cs (157): Unable to find object: '0' attempting to call function 'getTargetName'TargetName =The problem is that when you hit a rock %col is just 0 so this information is not available. So some things that should work in theory, dont. Quote Link to comment Share on other sites More sharing options...
rlranft Posted July 30, 2016 Share Posted July 30, 2016 Excellent - now we're getting somewhere! Or, maybe nowhere, because it looks like the code that generates the callback isn't actually passing our object reference to script. Congratulations! Sounds like a bug, buddy! Perhaps wander over to the GitHub repo and log an issue? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.