Ship Spawning
-
fThrust is the speed at which the ship goes. -1 is the default value in the game and means full speed.
fRange is how far from the destination the ship has to go.
Did you define a pilot and a state graph?
-
You changed testOP to a pointer, but didn’t change it in the call.
pub::AI::SubmitState(iSpaceObjID, testOP); ```Although depending on just how DirectiveGotoOp has been defined, you might still need to cast it (it should have been derived, so there should be no need).
-
The older headers don’t have the inheritance. You’d need to add it to the definition of all Op classes.
-
I have set all the personality settings, but I either only get a standing ship (setting state_graph to -1) or an instant server crash.
int iStateGraph = pub::StateGraph::get_state_graph("FIGHTER", pub::StateGraph::TYPE_STANDARD); IStateGraph const *sg = pub::StateGraph::get_state_graph_internal(iStateGraph); pub::AI::SetPersonalityParams pp; pp.state_graph=(int) sg; pp.personality=p; pp.state_id=true; pub::AI::SubmitState(iSpaceObjID, (pub::AI::BaseOp*)&pp);
It doesn’t matter whether I set state_id to true or false or use iStateGraph for the state_graph variable.
Any hints?
-
Ok, I solved it by setting the stategraph afterwards using the BehaviorManager. But as long as you don’t know much about Freelancers internal objects you wont get that far ^^ Maybe there is an easier way?
-
I have no clue. For me, only setting it afterwards works.
Has anyone an idea how to set the enemies of the spawned ship differently from the rep group? E.g. if you want to make an escort they should attack everything which is not friendly to the escorted player.
-
There seem to be some errors regarding the ownerlist stuff:
First of all it has to be
template <class t=""> class IMPORT OwnerList { public: OwnerList(); virtual ~OwnerList(); class OwnerList & operator=(class OwnerList const &); void free(); };</class>
and then the structs are:
struct CargoDesc // Just quickly reversed, no clue about the types { int vft; int iUnk1; int iUnk2; int iUnk3; int iUnk4; }; struct ShipInfo { uint iFlag; // 4 uint iSystem; uint iShipArchetype; Vector vPos; Vector vUnk1; // all 0 Vector vUnk2; // all 0 Matrix mOrientation; uint iUnk1; // 0 uint iLoadout; OwnerList <pub::spaceobj::cargodesc>cargoDesc; uint unk1; // 0 uint unk2; // 0 float fUnk1; uint unk3; // 0 uint iLook1; uint iLook2; uint unk4; // 0 uint unk5; // 0 uint iComm; float fUnk2; float fUnk3; float fUnk4; float fUnk5; float fUnk6; float fUnk7; float fUnk8; uint iUnk2; uint iRep; // increases for each NPC spawned, starts at 0 or 1 uint iPilotVoice; uint unk6; // 0 int iHealth; // -1 = max health uint unk7; // 0 uint unk8; // 0 uint iLevel; };</pub::spaceobj::cargodesc>
After that there is no need to set si.cargoDesc. It will be automaticly initialised like in content.dll.
I still have no clue how to iterate through the list or whether it has anything to do with NPCs dropping all their stuff.
-
There is still an error in the reversed personality struct:
struct IMPORT DamageReactionStruct { DamageReactionStruct(); DamageReactionStruct& operator=(const DamageReactionStruct&); float evade_break_damage_trigger_percent; // 1 float evade_dodge_more_damage_trigger_percent; // 0.2 float drop_mines_damage_trigger_percent; // 1 float drop_mines_damage_trigger_time; // 1 float engine_kill_face_damage_trigger_percent; // 1 float engine_kill_face_damage_trigger_time; // 2 float roll_damage_trigger_percent; // 1 float roll_damage_trigger_time; // 1 float afterburner_damage_trigger_percent; // 1 float afterburner_damage_trigger_time; // 1.5 float brake_reverse_damage_trigger_percent; // 1 float fire_missiles_damage_trigger_percent; // 1 float fire_missiles_damage_trigger_time; // 0.5 float fire_guns_damage_trigger_percent; // 1 float fire_guns_damage_trigger_time; // 1 int iUnk1; int iUnk2; };
As you can see there are 2 more values at the end. I have checked the constructor and there are indeed 8 bytes more reserved as the original struct had. (Trust me this was not easy to find ^^)
I also noticed that my personality struct always hast the default values after submitting the personality params. I have to set it afterwars aswell as the stategraph. This way everything works perfectly. As soon as an NPC dies I destroy its equipment so that nothing stays it space but its cargo.
-
Yeah it worked. We’ve been spawning NPCs etc since some years now. I even tested some scripting sequences, but didn’t have the time to really develop that further. But it is planned.
-
Hey again.
I made a lot of progress with this stuff using Cannon’s code as a base and some help provided by Friendlyfire. It’s mostly stable but there’s a final issue I’m unable to fix.
If I destroy an npc through pub::SpaceObj::Destroy(*iShipIter, (pub::SpaceObj::DestroyType)0); then it effectively destroy it properly without generating any loot.
However when the spawned npc is killed via normal conditions (killed by a player) it literally spawns EVERYTHING the NPC had on him, including the guns, the engine (really), bots, ammo, etc…
Basically I didn’t find any way to hook to the npc death to prevent it from spawning any loot in space and I’m starting to lose hope
I know Schmackbolzen posted about it literally four or five posts above so I’m most likely looking in the wrong direction.
-
As far as I remember the problem was, that the main controller of the NPCs is missing (since you don’t create it). It seems to be responsible for all patrol commands etc. of the assigned NPCs and apparently also manages all the equipment on death. So the thing I did was to erase it manually. You have to create a list of all your NPCs and check when anything dies whether it is in the list. There are no new hooks necessary for that, you can use the existing ones. Going through the cargo of a ship should be somewhere in the hook SVN code (I hope, since I haven’t done any hooking stuff for a long time). I used a reverse engineered method, though.
-
You can reach the CEquipTraverser* at offset 0xE4 of a CShip* pointer. From there iterating on the cargo/equipment is easy.