Jump to content
  • 0
bWolfie

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

Question

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.

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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)

Share this post


Link to post
Share on other sites
  • 0

 

 

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.

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

I guess I will use query_sql for now.

query_sql("SELECT COUNT(account_id) FROM `autotrade_merchants`", .@merchants);
.@total = getusers(1) - .@merchants;
Edited by True Zeal

Share this post


Link to post
Share on other sites
  • 0

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

mapreg->setreg(script->add_str("$@who4count"), count);

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.