Not working
#1

Why this code don't work, when ever I buy gas can and i want to use it with /usegc it says: "You don't have any gas can to use"

pawn Код:
if(strcmp(cmdtext, "/usegc", true) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to use this command.");
        else if(engine == 1) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to turn off engine before using gas can.");
        else if(GCS[playerid] != 1 || GCM[playerid] != 1 || GCB[playerid] != 1) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You don't have any gas can to use");
        else
        {
            if(GCS[playerid] == 1)
            {
                GCS[playerid] --;
                return 1;
            }
            if(GCM[playerid] == 1)
            {
                GCM[playerid] --;
                return 1;
            }
            if(GCB[playerid] == 1)
            {
                GCB[playerid] --;
                return 1;
            }
            return 1;
        }
    }

    return 0;
}
Reply
#2

I don't know how gas and all that stuff work to those server and since you didn't give more information, I'm going to guess.

When you buy gas, you set GCS or GCM or GCB to 1? If so, then you need to check if all of those are not 1 (so no gas can).
pawn Код:
else if(GCS[playerid] != 1 && GCM[playerid] != 1 && GCB[playerid] != 1) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You don't have any gas can to use");
Reply
#3

This is how to get gas can, I'm saving it to veriable or w/e it is
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_GASCAN)
    {
        if(response)
        {
            if(listitem == 0) // Small size gas can
            {
                GCS[playerid] = 1;
                SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF}You bought small size gas can, use {FF6A22}/usegc {FFFFFF}to refill your vehicle");
            }
            if(listitem == 1) // Medium size gas can
            {
                GCM[playerid] = 1;
                SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF}You bought medium size gas can, use {FF6A22}/usegc {FFFFFF}to refill your vehicle");
            }
            if(listitem == 2) // Big size gas can
            {
                GCB[playerid] = 1;
                SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF}You bought big size gas can, use {FF6A22}/usegc {FFFFFF}to refill your vehicle");
            }
        }
        return 1;
    }

    return 0;
}
doesn't != 1 means If it's not 1 it will send msg...
but when I buy it on gas station it should change to 1 and this msg should gone..
Reply
#4

I guessed correctly then!

Yes, the symbol != means 'not equal to', therebefore it should be like the code I posted above (1st post). If all of them (small, medium, big cans) are not 1, then that means that all of them are empty.

The problem was that you used OR (||) instead of AND (&&).
Reply
#5

ohh silly me :P thank you again

if you don't mind I want to raise vehicle fuel if I will use can so if I have 10 fuel and if I have gascan I will add +5 fuel to car, is this correct code?

pawn Код:
if(GCS[playerid] == 1)
            {
                GCS[playerid] --;
                Carinfo[vehicleid][F] += 5; // Refilling vehicle with 5 liters of fuel
                return 1;
            }
can't test on my own I'm in hurry :/
Reply
#6

If you define vehicleid, then yes. Or:
pawn Код:
Carinfo[GetPlayerVehicleID(playerid)][F] += 5;
but make sure that the player who uses /usegc is driver because then passenger can get + fuel (abuse).

So change:
pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to use this command.");
to:
pawn Код:
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to use this command.");
---

I'd also suggest you 2 more things:

Not using strcmp, use ZCMD or y_commands instead (speed)
For things that get only 2 values (0,1), use booleans. Boolean in combination of char in arrays reduces the size.
Reply
#7

Damn it's working perfect, and thanks to fix possible abuses, I didn't think about this ^^

Umm about my command using, server that I'm trying to script for has every cmd in strcmp, so I'm trying to script in strcmp I know zcmd or ycmd + sccanf is a lot easier and faster ^^ thanks for advices and help
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)