Reading multiple parameters from an Armagetron command

What do you want to see in Armagetron soon? Any new feature ideas? Let's ponder these ground breaking ideas...
Post Reply
User avatar
smoothice
On Lightcycle Grid
Posts: 45
Joined: Sun Nov 09, 2008 7:54 pm

Reading multiple parameters from an Armagetron command

Post by smoothice »

So this is my Arma C++ question for the week....

So you know when you run an Armagetron command you can run like "KILL smoothice". What if I wanted to (in C++) get information from multiple parameters?: "KILL smoothice anotherplayer".

You can see this code:

Code: Select all

static void Kill_conf(std::istream &s)
{
    if ( se_NeedsServer( "KILL", s, false ) )
    {
        return;
    }

    ePlayerNetID * p = ReadPlayer( s );
It obviously retrieves the player from the command and reads it into the ePlayerNetID called p.

So basically I'm asking how I can make a command that deals with two players and not just one.
Image
User avatar
Lucifer
Project Developer
Posts: 8747
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

tricky, since player names can have spaces, right?

Anyway, you need to parse the arguments into a list, then, for this particular example, iterate through the list and run the command on each item in the list.

Not too hard, provided there aren't spaces in the player names.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
epsy
Adjust Outside Corner Grinder
Posts: 2003
Joined: Tue Nov 07, 2006 6:02 pm
Location: paris
Contact:

Post by epsy »

ReadPlayer only reads one word AFAIK
User avatar
Z-Man
God & Project Admin
Posts: 11715
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

Yep. Just call it as often as you need.
User avatar
smoothice
On Lightcycle Grid
Posts: 45
Joined: Sun Nov 09, 2008 7:54 pm

Post by smoothice »

Z-Man wrote:Yep. Just call it as often as you need.
So it would be like this?

Code: Select all

static void Kill_conf(std::istream &s) 
{ 
    if ( se_NeedsServer( "KILL", s, false ) ) 
    { 
        return; 
    } 

    ePlayerNetID * p = ReadPlayer( s );
    ePlayerNetID * p2 = ReadPlayer( s );

p would be the first player and p2 the second?
Image
User avatar
Z-Man
God & Project Admin
Posts: 11715
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

Yeah, that should work.
User avatar
smoothice
On Lightcycle Grid
Posts: 45
Joined: Sun Nov 09, 2008 7:54 pm

Post by smoothice »

Hi again.... the previous discussion with running ReadPlayer twice works. However, I've moved the code in my branch to gGame and ReadPlayer does not work there. So instead, epsy told me to use these lines:

Code: Select all

	ePlayerNetID * p = ePlayerNetID::FindPlayerByName( theInput, 0 );
	ePlayerNetID * p2 = ePlayerNetID::FindPlayerByName( theInput, 0 );
However running it twice returns the first argument for both p and p2. How would I go about getting the functionality of ReadPlayer into this (being able to run it twice to get argument 1 and argument 2)?
Image
User avatar
Z-Man
God & Project Admin
Posts: 11715
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

In that case, you first need to split the argument in its parts:

Code: Select all

std::istringstream stream( theInput );
tString theInput1, theInput2;
stream >> theInput1;
stream >> theInput2;
Post Reply