Little problem.
#1

Hi all again.I do car market,and problem is player can buy,just first car here is a script:

pawn Код:
if(dialogid == 5227)
    {
    if(response)
    {
    if(PlayerData[playerid][pcar] != -1 && PlayerData[playerid][pcar2] != -1)
    {
    SendClientMessage(playerid,-1,"Only 2 cars");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(model == 534)//REMINGTON
    {
    if(GetPlayerMoneyA(playerid) < 9000)
    {
    SendClientMessage(playerid,  COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=2");
    return 1;
    }
    if(model == 533)//FELTZER
    {
    if(GetPlayerMoneyA(playerid) < 7000)
    {
    SendClientMessage(playerid, COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy FELTZER=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy FELTZER=2");
    return 1;
    }
This is just part,but in this when i press (response) it only work on remington,when i go to feltzer(and others market cars) nothing happines,where is problem?maybe to mach return or some thing ...
Reply
#2

I don't understand what are you talking abot.

Explain better please, I don't know what you mean.
Reply
#3

When player enter to car who is in market player get's dialog with id 5227,and how you see i check model,money,but this work,just for first checking car model now is REMINGTON.

Код:
if(model == 534)//REMINGTON
    {
    if(GetPlayerMoneyA(playerid) < 9000)
    {
    SendClientMessage(playerid,  COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=2");
    return 1;
    }
This code is work,but when i add more:

Код:
if(model == 534)//REMINGTON
    {
    if(GetPlayerMoneyA(playerid) < 9000)
    {
    SendClientMessage(playerid,  COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=2");
    return 1;
    }
    if(model == 533)//FELTZER
    {
    if(GetPlayerMoneyA(playerid) < 7000)
    {
    SendClientMessage(playerid, COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy FELTZER=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy FELTZER=2");
    return 1;
    }
And how you see i do another if(model and now is don't work,player don't get message "You but FELTZER=2 or =1,but it for all cars model what i add,maybe it's need use else or anything thing
Reply
#4

Help any if can.
Reply
#5

Sorry for double post,but i very need help with this.And i wanna to say i think this is problem with return i think or else ,because i try remove returns and work for 1 vehicle,but others vehicle don't work...
Reply
#6

try this, I'm not sure will this work
PHP код:
if(dialogid == 5227)
    {
        if(
response)
        {
            if(
PlayerData[playerid][pcar] != -&& PlayerData[playerid][pcar2] != -1)
                {
                    
SendClientMessage(playerid,-1,"Only 2 cars");
                    
SetVehicleToRespawn(vehicleid);
                    return 
1;
                }
                if(
model == 534)//REMINGTON
                
{
                    if(
GetPlayerMoneyA(playerid) < 9000)
                    {
                        
SendClientMessage(playerid,  COLOR_RED"Enought money");
                        
SetVehicleToRespawn(vehicleid);
                        return 
1;
                    }
                    if(
PlayerData[playerid][pcar] == -1)
                    {
                        
SendClientMessage(playeridCOLOR_GREEN"You buy REMINGTON=1");
                    }
                else
                    {
                        
SendClientMessage(playeridCOLOR_GREEN"You buy REMINGTON=2");
                    }
                return 
1;
            }
            if(
model == 533)//FELTZER
                
{
                    if(
GetPlayerMoneyA(playerid) < 7000)
                    {
                        
SendClientMessage(playeridCOLOR_RED"Enought money");
                        
SetVehicleToRespawn(vehicleid);
                        return 
1;
                    }
                    if(
PlayerData[playerid][pcar] == -1)
                    {
                    
SendClientMessage(playeridCOLOR_GREEN"You buy FELTZER=1");
                    }
                    else
                   {
                        
SendClientMessage(playeridCOLOR_GREEN"You buy FELTZER=2");
                    }
                return 
1;
            } 
Reply
#7

One small thing that bothers me, what's the model variable actually for or how is it assigned?

Also, a small thing to make your code better would be using a switch statement there.
pawn Код:
switch(model)
{
    case 534:
    {
    }
    case 533:
    {
    }
    //...
}
Something to make your code better structured (for some eyes that is):
pawn Код:
// instead of this:
if(response)
{
    switch(model)
    {
        // ...
    }
}

// act like this:
if(!response)
    return true;

switch(model)
{
    // ...
}
There's some useless returning as well...
pawn Код:
if(PlayerData[playerid][pcar] == -1)
{
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=1");
}
else
{
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=2");
    return 1; // <-- useless return,
}
return 1; // <-- this one will do the job
Reply
#8

AndreT i don't understand you.I try to do with switch but i do wrong,maybe you can to that with that script who i give:

Код:
if(model == 534)//REMINGTON
    {
    if(GetPlayerMoneyA(playerid) < 9000)
    {
    SendClientMessage(playerid,  COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy REMINGTON=2");
    return 1;
    }
    if(model == 533)//FELTZER
    {
    if(GetPlayerMoneyA(playerid) < 7000)
    {
    SendClientMessage(playerid, COLOR_RED, "Enought money");
    SetVehicleToRespawn(vehicleid);
    return 1;
    }
    if(PlayerData[playerid][pcar] == -1)
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy FELTZER=1");
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREEN, "You buy FELTZER=2");
    return 1;
    }
Reply
#9

Quote:
Originally Posted by Pasa
Посмотреть сообщение
try this, I'm not sure will this work
PHP код:
if(dialogid == 5227)
    {
        if(
response)
        {
            if(
PlayerData[playerid][pcar] != -&& PlayerData[playerid][pcar2] != -1)
                {
                    
SendClientMessage(playerid,-1,"Only 2 cars");
                    
SetVehicleToRespawn(vehicleid);
                    return 
1;
                }
                if(
model == 534)//REMINGTON
                
{
                    if(
GetPlayerMoneyA(playerid) < 9000)
                    {
                        
SendClientMessage(playerid,  COLOR_RED"Enought money");
                        
SetVehicleToRespawn(vehicleid);
                        return 
1;
                    }
                    if(
PlayerData[playerid][pcar] == -1)
                    {
                        
SendClientMessage(playeridCOLOR_GREEN"You buy REMINGTON=1");
                    }
                else
                    {
                        
SendClientMessage(playeridCOLOR_GREEN"You buy REMINGTON=2");
                    }
                return 
1;
            }
            if(
model == 533)//FELTZER
                
{
                    if(
GetPlayerMoneyA(playerid) < 7000)
                    {
                        
SendClientMessage(playeridCOLOR_RED"Enought money");
                        
SetVehicleToRespawn(vehicleid);
                        return 
1;
                    }
                    if(
PlayerData[playerid][pcar] == -1)
                    {
                    
SendClientMessage(playeridCOLOR_GREEN"You buy FELTZER=1");
                    }
                    else
                   {
                        
SendClientMessage(playeridCOLOR_GREEN"You buy FELTZER=2");
                    }
                return 
1;
            } 
Don't work.
Reply
#10

Stop double posting, also I don't quite understand your question you said it works then what do you need?

Код:
and problem is player can buy,
If you claim it is working why is there a problem :O
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)