MileHighGuy wrote: ↑Fri Mar 12, 2021 2:02 am
GetCharacterTeam(object) will give the error (because object is not a character)
That was causing the "expecting number, found userdata" error. But the "Entity "0" not found" error is happening with GetObjectTeam. My first guess is that they've used the line GetObjectTeam(attacker), which won't work because attacker is a Character Index. Just because Character Index 0 is normally the human player, it looks like a plausible error message.
But assuming that they haven't done that, then GetObjectTeam(object) is a confusing error. Unless there's something unusual about the data for the object that OnObjectDamage gives you. You can definitely use GetObjectTeam(object) inside of OnObjectKill with no problems because it's in the stock missions. But it's weird because GetCharacterUnit gives you userdata that only exists when the character is alive. Whereas OnObjectKill or OnObjectHeadshot must give you userdata that still exists after the object is dead. That's why I was wondering if they use a pointer.
MileHighGuy wrote: ↑Fri Mar 12, 2021 2:02 am
you ought to add the safety checks like Sporadia did... but that is the basic idea to try
This might have been overkill from me. They don't check for destroyed objects in the stock missions.
Does print always crash when you try to print nil, or does it only crash when you try to concatenate nil (ie ..nil)? I feel like I've managed to print nil before and I've never thought to use tostring().
..object would always crash anyway because you can't concatenate userdata.
But I guess it's worth testing GetObjectTeam(object) on it's own, just in case that's not the cause of the error.
Edit:
MileHighGuy wrote: ↑Fri Mar 12, 2021 2:02 am
also maybe use this instead:
Code: Select all
OnObjectDamageTeam(function(object, attacker)
if GetCharacterTeam(attacker) ~= objectTeam then
--do stuff
print("Hey, you damaged the enemy object!")
end
end, objectTeam)
If this works then that's a really cool use for event filters. But it requires OnObjectDamageTeam to trigger without a filter, and fill in objectTeam for you. I don't think events are that clever. What I expect to happen is that it will think objectTeam is a variable from outside the event, and that you're trying to pass it a filter that's stored inside objectTeam. So you might even get a munge error. Or you'll get an event that only triggers for team nil / treats the contents of objectTeam like a filter. I don't even think you can use variables to change filters midgame; I'm pretty sure whatever value is in objectTeam when the game reaches the line OnObjectDamageTeam, it will permanently become the event's filter (ie it doesn't remember the filter was objectTeam, it just creates an event with filter nil or 1 etc, I remember having this problem).
But what you can do instead is write an OnObjectDamageTeam with the filter
1, and a separate OnObjectDamageTeam with the filter
2. And then you know that the first event triggers when the object is team 1, and in the second event it's 2.
Edit 2: I wrote about using a for loop to make both events in one go, but it doesn't work.