Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Yankee on Jun 21, 2017, 10:27 AM

Title: Code For Give Score To Other Players
Post by: Yankee on Jun 21, 2017, 10:27 AM
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)
            }
        }
    }
Title: Re: Code For Give Score To Other Players
Post by: Mötley on Jun 21, 2017, 10:35 AM
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()
Title: Re: Code For Give Score To Other Players
Post by: SAzEe21 on Jun 21, 2017, 04:57 PM
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)
            }
        }
    }
Title: Re: Code For Give Score To Other Players
Post by: Mötley on Jun 21, 2017, 08:28 PM
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
    }
Title: Re: Code For Give Score To Other Players
Post by: Thijn on Jun 21, 2017, 08:33 PM
@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.
Title: Re: Code For Give Score To Other Players
Post by: Mötley on Jun 21, 2017, 08:50 PM
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
Title: Re: Code For Give Score To Other Players
Post by: Yankee on Jun 23, 2017, 11:00 PM
Thanks guys it worked properly :)