SA-MP Forums Archive
I need help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I need help (/showthread.php?tid=332203)



I need help - Trawltrawl - 07.04.2012

Sorry guys for 2nd thread this day, but i faced a problem.
so, what im trying to do it
when someone types /ak47 it takes from him 100 and gives him an ak47
And if he doesn't have the amount of money is sends him 'you don't have enough amount of money'
So here's my code
pawn Код:
if (strcmp("/ak47", cmdtext, true, 10) == 0)
{
    if((GetPlayerMoney(playerid) >= 100)
    { // this is line 164
    SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
    GivePlayerWeapon(playerid, 30, 1000);
    GivePlayerMoney(playerid, -100);
    }
    else
    {
    if(GetPlayerMoney(playerid) < 100)
    {
    SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
    }
    return 1;
}
And I got an ERROR that says
C:\Users\User\Desktop\Scripting\gamemodes\wassim.p wn(164) : error 028: invalid subscript (not an array or too many subscripts): "GetPlayerMoney"

-
Thanks much appreciated!


Re: I need help - Aira - 07.04.2012

Try
PHP код:
if (strcmp("/ak47"cmdtexttrue10) == 0)
{
if( 
GetPlayerMoney(playerid)  <  100) return SendClientMessage(playeridCOLOR_RED"You don't have enough money to buy an AK-47!");
GivePlayerMoney(playerid, -100);
GivePlayerWeapon(playerid301000);
SendClientMessage(playeridCOLOR_GREEN"WEAPON SHOP : You have succesfully bought an AK-47!");
return 
1;




Re: I need help - ivanVU - 07.04.2012

Quote:

if (strcmp("/ak47", cmdtext, true, 10) == 0)
{
if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
GivePlayerWeapon(playerid, 30, 1000);
GivePlayerMoney(playerid, -100);
return 1;
}

This will work

Damn , this will work // this was edit :P


Re: I need help - Shabi RoxX - 07.04.2012

So here is problem , try this :
pawn Код:
if((GetPlayerMoney(playerid) >= 100) //wrong a extra ( bracket here


//this should be

if(GetPlayerMoney(playerid) >= 100)
pawn Код:
if (strcmp("/ak47", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) >= 100)//a extra ( bracket here
        {
        SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
        GivePlayerWeapon(playerid, 30, 1000);
        GivePlayerMoney(playerid, -100);
        }
        else
        {
        if(GetPlayerMoney(playerid) < 100)
        {
        SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
        }
    }



Re: I need help - Trawltrawl - 07.04.2012

ivanVU, it worked, but can you please explain?
Shabi, I thought that, too but it sended me million of other errors


Re: I need help - ivanVU - 07.04.2012

Sorry for offtopic , but can i learn you something shabi?

why would you do it like this

Код:
if (strcmp("/ak47", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) >= 100)//a extra ( bracket here
        { // this is line 164
        SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
        GivePlayerWeapon(playerid, 30, 1000);
        GivePlayerMoney(playerid, -100);
        }
        else
        {
        if(GetPlayerMoney(playerid) < 100)
        {
        SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
        }
    }
when you can do it like this

Код:
if (strcmp("/ak47", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
        SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
        GivePlayerWeapon(playerid, 30, 1000);
        GivePlayerMoney(playerid, -100);
        }
    }
i mean , this is so simple, and you just read the whole code..
3rd line : If playermoney is less than 100$ , return send that message to player.. else , code send's him message that he bought ak47 , gives him weapon and charge him..


OT: if((GetPlayerMoney(playerid) >= 100)

you don't need 2 bracket here, just one, and the second thing that i bold , it says if playermoney is higher or equal to 100 , so you do it like this

if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid,-1,"You don't have enought money");

just read the code, if player money is less than 100 , code will return him message "you don't have enought money.."


Re: I need help - Trawltrawl - 07.04.2012

But you didn't type else (cough im embarresed right now)
[EDIT]:
Your script did work, but when i typed /ak47, and i had 0 money it said
"You don't have enough money!"
"You just bought an ak400"
And i had an ak400 with -100 money, so basicly your script doesn't work :P


Re: I need help - ivanVU - 07.04.2012

you don't need else, becouse in check

Quote:

if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");

if player has more than 100$ , there is no check , i don't know how to explain that batter.

look , read the code , if player has less than 100$, code will send him message, if he has more than 100$ , code will continue , sorry for bad explain..


Re: I need help - Shabi RoxX - 07.04.2012

Quote:
Originally Posted by ivanVU
Посмотреть сообщение
Sorry for offtopic , but can i learn you something shabi?

why would you do it like this

Код:
if (strcmp("/ak47", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) >= 100)//a extra ( bracket here
        { // this is line 164
        SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
        GivePlayerWeapon(playerid, 30, 1000);
        GivePlayerMoney(playerid, -100);
        }
        else
        {
        if(GetPlayerMoney(playerid) < 100)
        {
        SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
        }
    }
when you can do it like this

Код:
if (strcmp("/ak47", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money");
        SendClientMessage(playerid, 0xFF0000AA,"You bought an Ak47");
        GivePlayerWeapon(playerid, 30, 1000);
        GivePlayerMoney(playerid, -100);
        }
    }
i mean , this is so simple, and you just read the whole code..
3rd line : If playermoney is less than 100$ , return send that message to player.. else , code send's him message that he bought ak47 , gives him weapon and charge him..


OT: if((GetPlayerMoney(playerid) >= 100)

you don't need 2 bracket here, just one, and the second thing that i bold , it says if playermoney is higher or equal to 100 , so you do it like this

if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid,-1,"You don't have enought money");

just read the code, if player money is less than 100 , code will return him message "you don't have enought money.."
Because I don't want to make it difficult for Trawltrawl to understand : I just explained him his mistakes in his code not creating a cmd for him, so thats why i should fix his code not make my own . GOT IT ?


Re: I need help - DaRealShazz - 18.05.2012

Quote:
Originally Posted by Trawltrawl
Посмотреть сообщение
But you didn't type else (cough im embarresed right now)
[EDIT]:
Your script did work, but when i typed /ak47, and i had 0 money it said
"You don't have enough money!"
"You just bought an ak400"
And i had an ak400 with -100 money, so basicly your script doesn't work :P
That is because he failed a little. Here is his code (modified correctly):
pawn Код:
if (strcmp("/ak47", cmdtext, true, 5) == 0)
    {
        if(GetPlayerMoney(playerid) < 100) SendClientMessage(playerid, 0xFF0000AA,"You don't have enough money to buy an AK47!");
        else
        {
        GivePlayerWeapon(playerid, 30, 1000);
        GivePlayerMoney(playerid, -100);
        SendClientMessage(playerid, 0xFF0000AA,"You've bought an AK47!");
        }
    }