How do i create this?
#1

Hello guys i have opened a server and i wanna know how to create a simple /rob [id] and if there close to the player the can attempt to could someone help me on this il rep you?
Reply
#2

This is psuedo CODE, I expect you to complete it.
pawn Код:
CMD:rob(playerid)
{
   new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z);
   foreach(new i:Player)
   {
    if(!IsPlayerInRangeOfPoint(i, 5, x, y, z)) continue;
    else
    {
        GivePlayerMoney(playerid, ( GetPlayerMoney(i) / 100 ) * 20 );
        // new st[128]; format(st, 128, "You have robbed %s of $ %d" .. )
        SendClientMessage(playerid, -1, st);
    }
}
}
Reply
#3

Do you use what command processor? Dcmd? Zcmd? or the normal, strcmp?

EDIT:
Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
This is psuedo CODE, I expect you to complete it.
pawn Код:
CMD:rob(playerid)
{
   new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z);
   foreach(new i:Player)
   {
    if(!IsPlayerInRangeOfPoint(i, 5, x, y, z)) continue;
    else
    {
        GivePlayerMoney(playerid, ( GetPlayerMoney(i) / 100 ) * 20 );
        // new st[128]; format(st, 128, "You have robbed %s of $ %d" .. )
        SendClientMessage(playerid, -1, st);
    }
}
}
You can even use Rajat's code but you must be using the right command processor or maybe it works normally? I'm not good with the new command processors. I'm still old school... XD
Reply
#4

I took it out of my script, and edited some stuff so you wont receive any errors in the compiler! Just add it with the rest of your commands.

NOTE - You need zcmd and sscanf

pawn Код:
CMD:rob( playerid, params [] )
{

    new
        id,
        str[128],
        str1[128],
        pName[MAX_PLAYER_NAME],
        pName1[MAX_PLAYER_NAME],
        Money;


    if( sscanf ( params, "u", id))
        return SendClientMessage(playerid, -1, "[USAGE] /rob [ID]");

    new
        Float:x,
        Float:y,
        Float:z;

    GetPlayerPos(id, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
        return SendClientMessage(playerid, -1, "ERROR:You must be near the player!");

    if( id == playerid )
        return SendClientMessage(playerid, -1, "ERROR:You cannot rob yourself!");

    if( id == INVALID_PLAYER_ID )
        return SendClientMessage(playerid, -1, "ERROR: Player is not connected");

    if( IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, -1, "ERROR:You cannot use this command whilst being inside a vehicle!");

    if( IsPlayerInAnyVehicle(id))
        return SendClientMessage(playerid, RED, "ERROR: You cannot rob someone who is inside a vehicle!");

    new
        luck = random(2);

    if ( luck == 0 )
    {
        format( str, 128, "[FAIL] %s[%d] has caught you trying to dig into his pockets!", GetName(id), id);
        SendClientMessage(playerid, -1, str );
        format( str, 128, "[ROB] %s[%d] has tried to rob you, but failed!", GetName(playerid), playerid);
        SendClientMessage(id, -1, str );
        SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1 );
    }

    else
    {

        GetPlayerName(id, pName, sizeof(pName));
        GetPlayerName(playerid, pName1, sizeof(pName1));

        Money = GetPlayerMoney(id);

        new
            RobbedMoney = random( Money );


        GivePlayerMoney(playerid, RobbedMoney);
        GivePlayerMoney(id, -RobbedMoney);



        format(str, sizeof(str), "[ROBBED] You have succesfully robbed $%d from %s[%d]", RobbedMoney, pName, id);
        SendClientMessage(playerid, -1, str);

        format(str1, sizeof(str1), "[ROBBED] %s[%d] has robbed $%d of you!", pName1, playerid, RobbedMoney);
        SendClientMessage(id, -1, str1);

        SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
    }

    return 1;
}
Reply
#5

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
This is psuedo CODE, I expect you to complete it.
pawn Код:
CMD:rob(playerid)
{
   new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z);
   foreach(new i:Player)
   {
    if(!IsPlayerInRangeOfPoint(i, 5, x, y, z)) continue;
    else
    {
        GivePlayerMoney(playerid, ( GetPlayerMoney(i) / 100 ) * 20 );
        // new st[128]; format(st, 128, "You have robbed %s of $ %d" .. )
        SendClientMessage(playerid, -1, st);
    }
}
}
You made a command which will make the player rob everyone who's near him, that's not what the guy asked. Although that command is useful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)