Code For Give Score To Other Players

Started by Yankee, Jun 21, 2017, 10:27 AM

Previous topic - Next topic

Yankee

Hi guys,
Question is simple,first i made a system for this but it's not working properly.Can someone help me to fix this code or give me working code ?

else if ( cmd == "givescore" )
    {
        if(!text) MessagePlayer( "[#ffffff]syntax - /givescore <playerName> <Amount>", player );
        else
        {
            local params = split( text, " " ), plr = FindPlayer( params[0] ), amount = params[1];
            if(!plr) MessagePlayer( "[#ffffff]Error - invalid player", player );
            else if(!ammount || !IsNum( ammount )) MessagePlayer( "[#ffffff]Error - The Ammount must be integer", player );
            else
            {
                plr.Score(ammount.tointeger());
                MessagePlayer( "[#DC26FF]"+player.Name+" given $"+ammount.tointeger()+" to you",plr);
                MessagePlayer( "[#DC26FF]You gave $"+ammount.tointeger()+" > "+plr.Name,player);
                SaveAccount(plr)
            }
        }
    }

Mötley

#1
You changed local amount to ammount everywhere else.
I think that might just be it

If anything I think plr.Score(amount.tointeger()); is invalid.
Should be plr.Score = amount.tointeger()

SAzEe21

else if ( cmd == "givescore" )
    {
        if(!text) MessagePlayer( "[#ffffff]syntax - /givescore <playerName> <Amount>", player );
        else
        {
            local params = split( text, " " ), plr = FindPlayer( params[0] ), ammount = params[1];
            if(!plr) MessagePlayer( "[#ffffff]Error - invalid player", player );
            else if(!ammount || !IsNum( ammount )) MessagePlayer( "[#ffffff]Error - The Ammount must be integer", player );
            else
            {
                plr.Score = ammount.tointeger();
                MessagePlayer( "[#DC26FF]"+player.Name+" given $"+ammount.tointeger()+" to you",plr);
                MessagePlayer( "[#DC26FF]You gave $"+ammount.tointeger()+" > "+plr.Name,player);
                SaveAccount(plr)
            }
        }
    }

Mötley

#3
Now that's wrong...
plr.Score = ammount.tointeger();
You have to do += or else if the original score were 5, You wanted to give 3 extra points. Now the score is three instead of 8.



I didn't want to give away code, But at the same time I really hated your method Yankee. So I re did it to see stuff better while reading. So well hear

else if ( cmd == "givescore" )
    {
        local params = split( text, " " ), plr = FindPlayer( params[0] ), amount = params[1];

        if(!text)
        {
        MessagePlayer( "[#ffffff]syntax - /givescore <playerName> <Amount>", player );
        return true; //End
        }

        if (!IsNum( amount ))
        {
        MessagePlayer( "[#ffffff]Error - The Amount must be integer", player );
        return true; //End
        }

        if(!amount)
        {
        MessagePlayer( "[#ffffff]syntax - /givescore <playerName> <Amount>", player );
        return true; //End
        }
       
        if(!plr)
        {
        MessagePlayer( "[#ffffff]Error - invalid player", player );
        return true; //End
        }
       
        // Nothing else was called durring the checks, Set Data.

        /* Increase the score */
        plr.Score += amount.tointeger();
       
        /* Inform da playa */
        MessagePlayer( "[#DC26FF]"+player.Name+" given $"+amount.tointeger()+" to you", plr);

        /* Inform the commander */
        MessagePlayer( "[#DC26FF]You gave $"+amount.tointeger()+" > "+plr.Name,player);
       
/* Add to the account */
        SaveAccount(plr);

        return true; //End this command call
    }

Thijn

@TurboGrafx
You gotta move those locals down so text is being validated first. If there's no text, there's no params, and you'll get an undefined index.

Mötley

I thought they were just one time decelerations. As Text already exist as well everything else plus new data 'local shortcuts', so once the locals are declared, Everything else is already there. I've always declared everything before hand. Then call everything afterwards..

Therefore I honestly don't see what your saying :/, Maybe I am just dumb ;D

Yankee