Unlimited Bombs Help
#1

1st can i make it comfortable for player? i mean in this script i can drop unlimited bombs i wanna to set it only 5 times so can any one help me brah?
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_FIRE)
    {
        if (IsPlayerInAnyVehicle(playerid) && GetVehicleModel(GetPlayerVehicleID(playerid)) != 476)
        {
            return SendClientMessage(playerid, 0xFF0000AA, "");
        }
        else
        {
            new Float:VBPos[3];
            new Float:X, Float:Y, Float:Z;
            GetVehiclePos(GetPlayerVehicleID(playerid),VBPos[0],VBPos[1],VBPos[2]);
            MapAndreas_FindZ_For2DCoord(VBPos[0], VBPos[1], VBPos[2]);
            CreateExplosion(VBPos[0], VBPos[1], VBPos[2], 7, 20.0);
            GetPlayerPos(playerid, X, Y, Z);
            format(Stringz, sizeof(Stringz), "You've droped a bomb at the Destination Of "cred"%0.0f, %0.0f, %0.0f ", X, Y, Z);
            SendClientMessage(playerid, orange, Stringz);
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~>~~w~Bomb ~r~Droped~<~", 3000, 3);
        }
    }


and 2nd is whenever i press FIGHT KEY so i'm getting this message while on FOOT STATUS

pawn Код:
format(Stringz, sizeof(Stringz), "You've droped a bomb at the Destination Of "cred"%0.0f, %0.0f, %0.0f ", X, Y, Z);
            SendClientMessage(playerid, orange, Stringz);
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~>~~w~Bomb ~r~Droped~<~", 3000, 3);
        }
Reply
#2

Well.. 1st solution is to create variable like
pawn Код:
new bombs[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE)
    {
        if (IsPlayerInAnyVehicle(playerid) && GetVehicleModel(GetPlayerVehicleID(playerid)) != 476)
        {
            return SendClientMessage(playerid, 0xFF0000AA, "");
        }
        else
        {
            if(bombs[playerid] != 5)
            {
                new Float:VBPos[3];
                new Float:X, Float:Y, Float:Z;
                GetVehiclePos(GetPlayerVehicleID(playerid),VBPos[0],VBPos[1],VBPos[2]);
                MapAndreas_FindZ_For2DCoord(VBPos[0], VBPos[1], VBPos[2]);
                bombs[playerid]++;
                CreateExplosion(VBPos[0], VBPos[1], VBPos[2], 7, 20.0);
                GetPlayerPos(playerid, X, Y, Z);
                format(Stringz, sizeof(Stringz), "You've droped a bomb at the Destination Of "cred"%0.0f, %0.0f, %0.0f ", X, Y, Z);
                SendClientMessage(playerid, orange, Stringz);
                GameTextForPlayer(playerid, "~n~~n~~n~~n~~>~~w~Bomb ~r~Droped~<~", 3000, 3);
            }
            else return SendClientMessage(playerid, 0xFF0000AA, "the message you want to appear.");

        }
    }
and 2nd one.. you did:
pawn Код:
if(newkeys == KEY_FIRE)
which its wrong..
Fix:
pawn Код:
if(newkeys & KEY_FIRE)
Reply
#3

tell him why not to do that, it will help him to prevent this..

We dont use
pawn Код:
if(newkeys & KEY_FIRE)
because if we do "==", the script only checks he he press only left click. If we do with "&", the script checks whetehr he pressed LMB along with RMB, or C + LMB, or etc.
Reply
#4

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
tell him why not to do that, it will help him to prevent this..

We dont use
pawn Код:
if(newkeys & KEY_FIRE)
because if we do "==", the script only checks he he press only left click. If we do with "&", the script checks whetehr he pressed LMB along with RMB, or C + LMB, or etc.
Absolutely wrong. You have to detect the player key, so you must do like newkeys & KEY_ANY. & is a bitwise operator means 'AND', and it is not a logical operator '&&' which also means 'AND'. Also '==' is comparison operators/relational operators, comparing if the player had pressed newkey with KEY_FIRE is wrong. I won't be going in more depth as it will be out of topic. If you want more detail you can PM me.

EDIT: Keys are in bit patterns so that's why we use bitwise operator instead of logical operator.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)