SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/01/2019, 08:08 AM   #1
simpleman
Little Clucker
 
Join Date: Nov 2018
Posts: 6
Reputation: 0
Exclamation Command error

hi guys, i am getting an error for my dropmoney cmd
Code:
(177) : error 009: invalid array size (negative, zero or out of bounds)
(179) : error 009: invalid array size (negative, zero or out of bounds)
pawn Code:
new MoneyPickup[]; // Line 177
new MoneyPickupID;
new PickupAmount[]; // Line 179

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i = 0; i < 500; i++)
    {
        if(MoneyPickupID == MoneyPickup[i])
        {
            new string[256];
            GivePlayerMoney(playerid, PickupAmount[i]);
            format(string, sizeof(string), "System: You picked up the money bag and received $%d", PickupAmount[i]);
            SCM(playerid, green, string);
            DestroyPickup(MoneyPickup[i]);
        }
    }
    return 1;
}

CMD:dropmoney(playerid, params[])
{
    new string[256], money, Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(sscanf(params, "i", money)) return SCM(playerid, yellow, "Syntax: /dropmoney [amount]");
    MoneyPickup[MoneyPickupID] = CreatePickup(1550, 19, X+2, Y, Z, 0);
    PickupAmount[MoneyPickupID] = money;
    MoneyPickupID++;
    format(string, sizeof(string), "System: You have dropped $%d", money);
    SCM(playerid, success, string);
    return 1;
}
simpleman is offline   Reply With Quote
Old 11/01/2019, 08:17 AM   #2
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,071
Reputation: 149
Default Re: Command error

You have to set an array size.

PHP Code:
new MoneyPickup[500]; // Line 177
new MoneyPickupID;
new 
PickupAmount[500]; // Line 179 
__________________
Kaliber is offline   Reply With Quote
Old 11/01/2019, 09:27 AM   #3
simpleman
Little Clucker
 
Join Date: Nov 2018
Posts: 6
Reputation: 0
Default Re: Command error

Quote:
Originally Posted by Kaliber View Post
You have to set an array size.

PHP Code:
new MoneyPickup[500]; // Line 177
new MoneyPickupID;
new 
PickupAmount[500]; // Line 179 
thanks, but when the player picks up the money bag, he doesn't receive anything nor does he get a msg saying its been picked up...

and also the player can type in negative numbers, which i dont want...

any fixes?
simpleman is offline   Reply With Quote
Old 11/01/2019, 09:36 AM   #4
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,071
Reputation: 149
Default Re: Command error

Write it like this:

PHP Code:
new MoneyPickup[500] = {-1, ...};

public 
OnPlayerPickUpPickup(playeridpickupid)
{
    for(new 
isizeof(MoneyPickup); i++)
    {
        if(
pickupid == MoneyPickup[i])
        {
            new 
string[256];
            
GivePlayerMoney(playeridPickupAmount[i]);
            
format(stringsizeof(string), "System: You picked up the money bag and received $%d"PickupAmount[i]);
            
SCM(playeridgreenstring);
            
DestroyPickup(MoneyPickup[i]);
            
MoneyPickup[i] = -1;
            break;
        }
    }
    return 
1;
}

CMD:dropmoney(playeridparams[])
{
    new 
string[256], moneyFloat:XFloat:YFloat:Z,Float:A;
    
GetPlayerPos(playeridXYZ), GetPlayerFacingAngle(playeridA);
    if(
sscanf(params"i"money)) return SCM(playeridyellow"Syntax: /dropmoney [amount]");
    if(
money <= 0) return SCM(playeridyellow"Please use only positive Money!");
    
+= 2.0 floatsin(-Adegrees);
    
+= 2.0 floatcos(-Adegrees);
    
MoneyPickup[MoneyPickupID] = CreatePickup(155019XYZGetPlayerVirtualWorld(playerid));
    
PickupAmount[MoneyPickupID] = money;
    
MoneyPickupID++;
    
format(stringsizeof(string), "System: You have dropped $%d"money);
    
SCM(playeridsuccessstring);
    return 
1;

This create the money-Bag in Front of the player

//Edited: Thanks Calisthenics
__________________
Kaliber is offline   Reply With Quote
Old 11/01/2019, 09:54 AM   #5
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 559
Reputation: 90
Default Re: Command error

https://wiki.sa-mp.com/wiki/Starting_IDs

pickupid 0 is valid, reset to -1
Calisthenics is offline   Reply With Quote
Old 11/01/2019, 11:18 AM   #6
simpleman
Little Clucker
 
Join Date: Nov 2018
Posts: 6
Reputation: 0
Default Re: Command error

Quote:
Originally Posted by Kaliber View Post
Write it like this:

PHP Code:
new MoneyPickup[500] = {-1, ...};

public 
OnPlayerPickUpPickup(playeridpickupid)
{
    for(new 
isizeof(MoneyPickup); i++)
    {
        if(
pickupid == MoneyPickup[i])
        {
            new 
string[256];
            
GivePlayerMoney(playeridPickupAmount[i]);
            
format(stringsizeof(string), "System: You picked up the money bag and received $%d"PickupAmount[i]);
            
SCM(playeridgreenstring);
            
DestroyPickup(MoneyPickup[i]);
            
MoneyPickup[i] = -1;
            break;
        }
    }
    return 
1;
}

CMD:dropmoney(playeridparams[])
{
    new 
string[256], moneyFloat:XFloat:YFloat:Z,Float:A;
    
GetPlayerPos(playeridXYZ), GetPlayerFacingAngle(playeridA);
    if(
sscanf(params"i"money)) return SCM(playeridyellow"Syntax: /dropmoney [amount]");
    if(
money <= 0) return SCM(playeridyellow"Please use only positive Money!");
    
+= 2.0 floatsin(-Adegrees);
    
+= 2.0 floatcos(-Adegrees);
    
MoneyPickup[MoneyPickupID] = CreatePickup(155019XYZGetPlayerVirtualWorld(playerid));
    
PickupAmount[MoneyPickupID] = money;
    
MoneyPickupID++;
    
format(stringsizeof(string), "System: You have dropped $%d"money);
    
SCM(playeridsuccessstring);
    return 
1;

This create the money-Bag in Front of the player

//Edited: Thanks Calisthenics

Thank you so much but I am having one more problem...

If the player has more than $1000

He can drop any amount he wants...


pawn Code:
CMD:dropmoney(playerid, params[])
{
    new string[256], money, Float:X, Float:Y, Float:Z, Float:A;
    GetPlayerPos(playerid, X, Y, Z), GetPlayerFacingAngle(playerid, A);
    if(sscanf(params, "i", money)) return SCM(playerid, yellow, "|- Syntax: /dropmoney [amount] -|");
    if(!IsPlayerSpawned(playerid)) return SCM(playerid, red, "|- System: You must be spawned in to use this command -|");
    if(GetPlayerMoney(playerid) < 1000) return SCM(playerid, red, "|- System: You do not have enough money to drop -|");
    if(money <= 0) return SCM(playerid, gray, "|- System: You can only enter in a positive number -|");
    if(money < 1000 || money > 1000000) return SCM(playerid, gray, "|- System: You can only drop between $1000 and $1,000,000 -|");
    X += 2.0 * floatsin(-A, degrees);
    Y += 2.0 * floatcos(-A, degrees);
    MoneyPickup[MoneyPickupID] = CreatePickup(1550, 19, X+2, Y, Z, GetPlayerVirtualWorld(playerid));
    PickupAmount[MoneyPickupID] = money;
    MoneyPickupID++;
    GivePlayerMoney(playerid, -money);
    format(string, sizeof(string), "|- System: You have dropped $%d -|", money);
    SCM(playerid, success, string);
    return 1;
}

how do I make it so the player can only drop how much they have.
simpleman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SERVER:Unknown command. error even the command works well GameOvr Scripting Help 20 07/09/2018 02:05 PM
Command error Dejan12345 Scripting Help 12 03/08/2016 05:06 PM
HELP Error Command weez Server Support 2 17/08/2014 07:11 PM
An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now) Tom_Dedi Help Archive 3 07/11/2010 01:01 PM
[LA-RP]Command Error. delow-music Help Archive 11 29/04/2009 03:47 PM


All times are GMT. The time now is 12:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.