Hercules icon indicating copy to clipboard operation
Hercules copied to clipboard

Add bitcount() script command

Open maqc1 opened this issue 1 year ago • 0 comments

REOPENED FROM #3344

Pull Request Prelude

Changes Proposed

Add bitcount() script command to return the number of active bits in an integer. Also commonly called popcount. It is a basic operation that is usefull when dealing with bitmasks. Now, I know it can be done using functions, but isn't it nice to have a built-in command instead of relying on callfunc() for something that simple?

Script example:

NPC 1
if(bitcount(quest) < 2)
    mes "You need to talk to 2 different NPCs.";
else
    mes "Here is your reward!";

NPC 2
if(quest & 1)
    mes "You already talked to me.";
else
    quest |= 1;


NPC 3
if(quest & 2)
    mes "You already talked to me.";
else
    quest |= 2;

NPC 4
if(quest & 4)
    mes "You already talked to me.";
else
    quest |= 4;

maqc1 avatar Mar 29 '25 17:03 maqc1