setting player cash
#6

There may be more efficient/better ways to do this, but this was the only way I could think of. Which is the use of player variables.

pawn Код:
new bool:helped[MAX_PLAYERS]; //Top of script
pawn Код:
CMD:fixveh(playerid, params[])
{

    new vehicleid;
    vehicleid = GetClosestVehiclePolice(playerid);
    for (new checkvehicle; checkvehicle < MAX_PLAYERS; checkvehicle++)
    if(IsPlayerInVehicle(checkvehicle, vehicleid))
    {
        if(gTeam[playerid] == ASSISTANCE) // Learn how to use if statements
        {
            ShowPlayerDialog(checkvehicle, FIX_D, DIALOG_STYLE_MSGBOX, "Repair", "Would you like your vehicle repaired?", "Yes", "No");
            SendClientMessage(playerid, -1,"Repair request sent!");
            SetPVarInt(playerid, "Helped", checkvehicle); //Put the player-being-helped's id into a player variable.
            helped[playerid] = true; //Set the helper's helped variable to true (for use in the dialog response)
        }
        else
        {
            SendClientMessage(playerid, -1, "There isn't a player in this car");
        }
    }
    return 1;
}
pawn Код:
case FIX_D:
        {
            if (!response) return SendClientMessage(playerid, 0xFF0000FF, "You cancelled.");
            if(response)
            {
                RepairVehicle(GetPlayerVehicleID(playerid));
                SendClientMessage(playerid, -1, "Your Vehicle has been repaired.");
                GivePlayerMoney(playerid, -500);
                PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
                foreach(new i : Player)
                {
                    if(GetPVarInt(i, "Helped") == playerid && helped[i] == true) //This checks if the helper has helped playerid, and if his helped variable is set to true.
                    {
                        GivePlayerMoney(i, 500); // Give helper his money
                        helped[i] = false; // and set his helped variable to false (since he hasn't helped anyone)
                    }
                }
            }
        }
Let me know if you have any trouble.
Reply


Messages In This Thread
setting player cash - by Stu1 - 03.11.2012, 00:22
Re: setting player cash - by DBan - 03.11.2012, 02:04
Re: setting player cash - by Stu1 - 03.11.2012, 02:27
Re: setting player cash - by DBan - 03.11.2012, 02:31
Re: setting player cash - by Stu1 - 03.11.2012, 02:35
Re: setting player cash - by DBan - 03.11.2012, 03:13
Re: setting player cash - by Stu1 - 03.11.2012, 08:44

Forum Jump:


Users browsing this thread: 1 Guest(s)