How to grab variable in src then display in script engine?

bWolfie

I'm the man
Messages
850
Points
0
Location
Alberta, Midgard
Github
bWolfie
Emulator
Hello,

I will try to explain what I am looking for.
Example: You use the @who command and it displays '53 players found'.

How would one capture that '53' and convert it so it could be used in a script?

Say, once the 53 is counted, it would be saved as a mapreg variable $who_count

Thanks for any help.

 
That sentence is sent directly to clif, which sends to the client so you can't catch it without source modification. If what you want is just to count all connected users there's an easy way for that:

Code:
getusers(1)
 
That sentence is sent directly to clif, which sends to the client so you can't catch it without source modification. If what you want is just to count all connected users there's an easy way for that:

getusers(1)
We are using custom @who4 command, which displays online players without autotraders.

            switch (display_type) {
                .......
                default: {
                    if (display_type == 4 && pl_sd->state.autotrade == 1)  // who4: ignore autotrade vendors
                        continue;
 
                    struct party_data *p = party->search(pl_sd->status.party_id);
                ......


So I'm interested in being able to generate this number to use in a script.

 
One could make a script command ("buildin") for this, but iterating through every single player every time this command is called would be very slow, especially if there's like 2k players online. One solution could be to have a separate property of map besides map->users that would count just like map->users but would be updated every time a player's vending state changes... but this would not be general-purpose so I don't think it should be in the core engine, this should rather be a plugin

 
I guess I will use query_sql for now.

Code:
query_sql("SELECT COUNT(account_id) FROM `autotrade_merchants`", .@merchants);
.@total = getusers(1) - .@merchants;
 
Last edited by a moderator:
One could make a script command ("buildin") for this, but iterating through every single player every time this command is called would be very slow, especially if there's like 2k players online. One solution could be to have a separate property of map besides map->users that would count just like map->users but would be updated every time a player's vending state changes... but this would not be general-purpose so I don't think it should be in the core engine, this should rather be a plugin
Not true for @who,@who command uses "count" variable and adds them when a player is found, and then display it with

StrBuf->Printf(&buf, msg_fd(fd,30), count); // %d players found.
Since it's not command that player should have (ideally), and there's some permission to hide from who searches, we do it by count variable here.Edit: you should use the command to show value, or store it in some variable and use another script command to utilise it.

Else, you can also use temporary global variable

Code:
mapreg->setreg(script->add_str("$@who4count"), count);
 
Thanks Dastgir, that is perfect, just what I needed! I made a copy @who command which just counts so it can be used by the script engine.

 
Back
Top