Cmd help
#1

Can someone help me to edit this command and make it work with a key?

I mean, if a player presses Y, he will rob the victim.

pawn Код:
CMD:rb(playerid,params[])
{
    new string[128];
    new copm[150];
    new DestName[24];
    new Destinationid;
    new name[24];
    GetPlayerName(playerid, name, 24);
    GetPlayerName(Destinationid, DestName, 24);
    if(GetPVarInt(playerid,"RbTime")>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"Please wait 30 seconds before robbing a player again.");
    if(PlayerInfo[playerid][pJailed] == 1) return SendClientMessage(playerid, red, "You cannot use this command in jail.");
    if(sscanf(params, "u", Destinationid))
    {
        SendClientMessage(playerid,red,"USAGE: /rb (Player Name/ID)");
        return 1;
    }
    if(!IsPlayerConnected(Destinationid))
    {
        format(string,sizeof(string),"Wrong playerid.");
        SendClientMessage(playerid,red,string);
        return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,Destinationid) > 4)
    {
        format(string,sizeof(string),"%s (%d) is too far away.You cannot reach him to rob him.",DestName,Destinationid);
        SendClientMessage(playerid,red,string);
        return 1;
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,red,"You cannot rob someone while in a vehicle.Exit the vehicle first.");
        return 1;
    }
    if(GetPlayerState(Destinationid) == PLAYER_STATE_DRIVER || GetPlayerState(Destinationid) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,red,"You cannot rob someone while they are in a vehicle. Get them to exit the vehicle first.");
        return 1;
    }
    if(playerid == Destinationid)
    {
        SendClientMessage(playerid,red,"You cannot rob yourself,how can you even manage that?");
        return 1;
    }
    if(GetPlayerMoney(Destinationid) <= 0)
    {
        SendClientMessage(playerid,red,"That player has no money in their pockets.What would be the point in robbing them?");
        SetPVarInt(playerid,"RbTime",GetTickCount()+30000);
        return 1;
    }
    new crand = random(100);
    if(crand <= 30)
    {
        SendClientMessage(playerid,red,"Rob attempt failed. The player slipped out of your grasp.");
        SetPVarInt(playerid,"RbTime",GetTickCount()+30000);
        return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,Destinationid) <= 4 && crand > 30)
    {
        new current_zone = player_zone[playerid];
        new mrand =random(GetPlayerMoney(Destinationid));
        SendClientMessage(playerid,red,"[[_Player Robbed_]]");
        format(string,sizeof(string),"You have robbed %d$ from %s (%d)!",mrand,DestName,Destinationid);
        SendClientMessage(playerid,red,string);
        GivePlayerMoney(playerid,mrand);

        SetPVarInt(playerid,"RbTime",GetTickCount()+30000);

        SendClientMessage(Destinationid,orange,"[[_Robbed_]]");
        format(string,sizeof(string),"%s (%d) has robbed you %d$!",name,playerid,mrand);
        SendClientMessage(Destinationid,orange,string);
        GivePlayerMoney(Destinationid,-mrand);

        format(copm,sizeof(copm),"Robbery: %s (%d) has robbed %d$ from %s (%d) - Location: %s.",name,playerid,mrand,DestName,Destinationid,zones[current_zone][zone_name]);
        new RobMsg[128];
        format(RobMsg, sizeof(RobMsg), "010Robbery: %s (%d) has robbed %d$ from %s (%d) - Location: %s.", name,playerid,mrand,DestName,Destinationid,zones[current_zone][zone_name]);
        IRC_GroupSay(gGroupID, IRC_CHANNEL, RobMsg);
        for(new i=0;i<MAX_PLAYERS;i++)
            {
                if(!IsPlayerConnected(i))continue;
                if(gTeam[i] == TEAM_COP)
                {
                    SendClientMessage(i, COLOR_BLUE, copm);
                }
       }
        return 1;
    }
    return 1;
}
Reply
#2

Wrap that above code into a stock function.

Then just call that function OnPlayerKeyStateChange

An example below

PHP код:
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) // PUT THIS CODE ON THE TOP OF THE SCRIPT, AT THE DEFINES PART

public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if (
PRESSED(65536)) //65536 Key code for Y
    
{
        
//CALL YOUR FUNCTION HERE
    
}
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)