Re: Get a guns projectile / Get a projectiles gun
Ah right!
When digging trough some mods I noticed sharpness is accessed everywhere, I see now!
So the lua object attributes are not accessible outside the script, but we got functions to push and fetch new attributes to the underlying c++ objects, neat!
The projectile querying is actually what I find to be used in other mods as well!
But yes, it is inefficient to loop over all entries and compare distances.
In my current case it's only missile launcher type of weapons, so it does not happen frequently, like a rapid fire weapon would.
But possibly the impact would be notable on such type of guns?
Spawning a projectile in the guns script would work, but introduce all the complexity of spawning, aligning, rotating, accelerating and ... I assume more ... into that script.
Certainly less error prone and surely more efficient still.
I don't quite like to bypass the builtin projectile spawning mechanics and then provide proxy projectiles for the AI to use the weapon correctly, but if that is how its done.
And thanks for the link to your scripts!
It's a bit troublesome to find mods that use the most recent functionality.^
EDIT:
You need to cast whatever GetObjectValue returns back into the appropriate type b4 it is usable.
Code:
self._properties:SetNumberValue("targetID", self._target.RootID)
self._properties:SetNumberValue("ownerID", self._owner.RootID)
self._properties:SetObjectValue("targetOBJ", self._target)
self._properties:SetObjectValue("ownerOBJ", self._owner)
print(self._properties:GetNumberValue("targetID")) --returns ID
print(self._properties:GetNumberValue("ownerID")) --returns ID
print(self._properties:GetObjectValue("targetOBJ")) --returns Soldier, AHuman
print(self._properties:GetObjectValue("ownerOBJ")) --returns Soldier, AHuman
print(self._properties:GetObjectValue("targetOBJ").RootID) --returns nil
print(self._properties:GetObjectValue("ownerOBJ").RootID) --returns nil
print(ToMovableObject(self._properties:GetObjectValue("targetOBJ")).RootID) --cast to MO! Else returns nil
print(ToMovableObject(self._properties:GetObjectValue("ownerOBJ")).RootID) --cast to MO! Else returns nil