Add Entity:AddSpawnFlag and Entity:RemoveSpawnFlag
Adds NPC:GiveSpawnFlag and NPC:RemoveSpawnFlag In my opinion, it's easier to use than the bit. library, for those who don't understand it.
I feel like this should be an addition for all entities, not just npcs
There's already an extension file for entity (includes/extensions/entity.lua) so just add it there, no need for a new file. Also, extensions are included manually within includes/init.lua, so this npc.lua file is never going to be included unless you add it to init.lua
Yeah, fixed it
@robotboy655 I don't see the request review, so if you would kindly take a look at this.
Please do not include unrelated changes to your Pull Requests.
If you want to suggest further additions, open a second/new Pull Request.
You could inline newSpawnFlags into the SetKeyValue call if you care about micro-optimization, as it's not used anywhere else and therefore saves a variable.
Also, I don't think an explicit check if flags already exist is needed, that way you can add multiple flags in a single call, or just one at a time, leaving it up to the individual.
If you want to complete the set though, add SetSpawnFlags and ClearSpawnFlags, the latter being a C++ function along those other 2.
Example:
function meta:SetSpawnFlags( Flags )
return self:SetKeyValue( "spawnflags", Flags )
end
function meta:ClearSpawnFlags()
return self:SetSpawnFlags( 0 )
end
function meta:AddSpawnFlags( Flags )
return self:SetSpawnFlags( bit.bor( self:GetSpawnFlags(), Flags ) )
end
function meta:RemoveSpawnFlags( Flags )
return self:SetSpawnFlags( bit.band( self:GetSpawnFlags(), bit.bnot( Flags ) ) )
end
Just a suggestion, and I'm not sure what robotboy655 thinks of such trivial functions.
If you're going to nitpick then also mention that all instances of flag should be flags, including the function name, as you can add and remove multiple with each function.
@robotboy655 Updated this once again, pls merge :( I have also tested it and it works
I don't think your recent changes are a good idea.
I don't think your recent changes are a good idea.
How come?
I don't think your recent changes are a good idea.
How come?
- It is inconsistent with the other Flag entity methods. None of them utilize varargs.
- I'm pretty sure varargs are slower. I haven't confirmed that though, I'm not certain
I don't think your recent changes are a good idea.
How come?
* It is inconsistent with the other Flag entity methods. None of them utilize varargs. * I'm pretty sure varargs are slower. I haven't confirmed that though, I'm not certain
I restored the previous version if that's the case. @robotboy655 pls merge