Command error
#1

hi guys, i am getting an error for my dropmoney cmd
Код:
(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 Код:
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;
}
Reply
#2

You have to set an array size.

PHP код:
new MoneyPickup[500]; // Line 177
new MoneyPickupID;
new 
PickupAmount[500]; // Line 179 
Reply
#3

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
You have to set an array size.

PHP код:
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?
Reply
#4

Write it like this:

PHP код:
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
Reply
#5

https://sampwiki.blast.hk/wiki/Starting_IDs

pickupid 0 is valid, reset to -1
Reply
#6

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Write it like this:

PHP код:
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 Код:
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)