setting player cash
#1

I require assistance again

I have this
PHP код:
CMD:fixveh(playeridparams[])
{
    new 
vehicleid;
    
vehicleid GetClosestVehiclePolice(playerid);
    for (new 
checkvehiclecheckvehicle MAX_PLAYERScheckvehicle++)
    if(
IsPlayerInVehicle(checkvehiclevehicleid))
    {
    if(
gTeam[playerid] == ASSISTANCE// Learn how to use if statements
             
{
               
ShowPlayerDialog(checkvehicleFIX_DDIALOG_STYLE_MSGBOX"Repair""Would you like your vehicle repaired?""Yes""No");
               
SendClientMessage(playerid, -1,"Repair request sent!");
            }
    
    else
        {
        
SendClientMessage(playeridCOLOR_WHITE"There isn't a player in this car");
        }
    }
    return 
1;

When someone requires there car fixed someone from the assistance team can do /fixveh near their car and it shows a dialog confirming the fix..
PHP код:
case FIX_D:
        {
            if (!
response) return SendClientMessage(playerid0xFF0000FF"You cancelled.");
            if(
response)
            {
                
RepairVehicle(GetPlayerVehicleID(playerid));
                
SendClientMessage(playeridCOLOR_WHITE"Your Vehicle has been repaired.");
                
GivePlayerMoney(playerid, -500);
                
PlayerPlaySound(playerid11330.00.00.0);
            }
        } 
This works aboslutely fine, however how would i award the player that sent the command(/fixveh) money?
Thanks in advance
Reply
#2

Just use https://sampwiki.blast.hk/wiki/Function:GivePlayerMoney.
Reply
#3

How? It gives the player id -500 but i need to give the guy that reuels the car 500
Reply
#4

pawn Код:
GivePlayerMoney(playerid, 500);
Very simple.

EDIT: Oh, I think I get where you're coming from, you don't have anywhere to put this to give the player typing the command money. I'll try and draft up something.
Reply
#5

Thank you
Reply
#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
#7

Thanks for this, Looks similar to something i tried(but might actually work) I'll test it after work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)