Need urgent help (about arrays)
#1

So, I was trying to make a fishing system.
pawn Код:
new
    g_Fishes[][][] = {
    {"Angelfish", 10, 88}, // {Fish name} {Min. weight [pounds]} {Max. weight [pounds]}
    {"Brill", 10, 78},
    {"Catfish", 40, 120},
    {"Dartfish", 30, 100},
    {"Electric Eel", 40, 118},
    {"Frogfish", 25, 105},
    {"Giant Sea Bass", 125, 302},
    {"Horn Shark", 50, 200}, // A shark!
    {"Icefish", 10, 40},
    {"Jackfish", 30, 80},
    {"Koi", 40, 120},
    {"Lemon Shark", 95, 255}, // I like lemons, also sharks
    {"Mackerel", 20, 75},
    {"Northern Pike", 20, 60},
    {"Oilfish", 60, 135},
    {"Porbeagle Shark", 135, 270}, // Another shark
    {"Quillfish", 10, 50},
    {"Requiem Shark", 60, 200}, // Another shark
    {"Salmon", 30, 120},
    {"Trout", 30, 75},
    {"Unicorn Fish", 10, 40}, // Search on wikipedia.....
    {"Viperfish", 10, 40},
    {"Whale Shark", 400, 1000}, // This fish is really rewarding because I love sharks, lol. (can reach 66k lbs but hey...)
    {"Yellowfin Tuna", 10, 60},
    {"Zebra Bullhead Shark", 50, 120} // Last fish and the last shark.
};
Code works fine at printing (debug)
pawn Код:
print("Fishes loaded:");
for (new i, j = sizeof(g_Fishes); i < j; ++ i) {
     printf("%s || Min Weight: %d || Max Weight: %d", g_Fishes[i][0], g_Fishes[i][1], g_Fishes[i][2]);
}
Does prints
pawn Код:
[21:30:21] Fishes loaded:
[21:30:21] Angelfish || Min Weight: 10 || Max Weight: 88
[21:30:21] Brill || Min Weight: 10 || Max Weight: 78
[21:30:21] Catfish || Min Weight: 40 || Max Weight: 120
[21:30:21] Dartfish || Min Weight: 30 || Max Weight: 100
[21:30:21] Electric Eel || Min Weight: 40 || Max Weight: 118
[21:30:21] Frogfish || Min Weight: 25 || Max Weight: 105
[21:30:21] Giant Sea Bass || Min Weight: 125 || Max Weight: 302
[21:30:21] Horn Shark || Min Weight: 50 || Max Weight: 200
[21:30:21] Icefish || Min Weight: 10 || Max Weight: 40
[21:30:21] Jackfish || Min Weight: 30 || Max Weight: 80
[21:30:21] Koi || Min Weight: 40 || Max Weight: 120
[21:30:21] Lemon Shark || Min Weight: 95 || Max Weight: 255
[21:30:21] Mackerel || Min Weight: 20 || Max Weight: 75
[21:30:21] Northern Pike || Min Weight: 20 || Max Weight: 60
[21:30:21] Oilfish || Min Weight: 60 || Max Weight: 135
[21:30:21] Porbeagle Shark || Min Weight: 135 || Max Weight: 270
[21:30:21] Quillfish || Min Weight: 10 || Max Weight: 50
[21:30:21] Requiem Shark || Min Weight: 60 || Max Weight: 200
[21:30:21] Salmon || Min Weight: 30 || Max Weight: 120
[21:30:21] Trout || Min Weight: 30 || Max Weight: 75
[21:30:21] Unicorn Fish || Min Weight: 10 || Max Weight: 40
[21:30:21] Viperfish || Min Weight: 10 || Max Weight: 40
[21:30:21] Whale Shark || Min Weight: 400 || Max Weight: 1000
[21:30:21] Yellowfin Tuna || Min Weight: 10 || Max Weight: 60
[21:30:21] Zebra Bullhead Shark || Min Weight: 50 || Max Weight: 120
But when it comes to
pawn Код:
stock randEx(min = cellmin, max = cellmax)
    return random(max - min + 1) + min;

// in a command
new rand = random(sizeof(g_Fishes));
new randWeight = randEx(g_Fishes[rand][1], g_Fishes[rand][2]);
It outputs
pawn Код:
error 035: argument type mismatch (argument 1)

// on line :
new randWeight = randEx(g_Fishes[rand][1], g_Fishes[rand][2]);
Help, please?
The problem I have is on randWeight. Which is the random value of MIN_WEIGHT of the fish and MAX_WEIGHT. Hence why the randomEx function is there
Reply
#2

you dont need randomEx
just use new rand = random(sizeof(g_Fishes));
and then after it use g_Fishes[rand][1] and g_Fishes[rand][2] in any way you want to like for printing it will be like this
pawn Код:
print("random fist");
new rand= random(sizeof(g_Fishes));
printf("%s || Min Weight: %d || Max Weight: %d", g_Fishes[rand][0], g_Fishes[rand][1], g_Fishes[rand][2]);
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
you dont need randomEx
just use new rand = random(sizeof(g_Fishes));
and then after it use g_Fishes[rand][1] and g_Fishes[rand][2] in any way you want to like for printing it will be like this
pawn Код:
print("random fist");
new rand= random(sizeof(g_Fishes));
printf("%s || Min Weight: %d || Max Weight: %d", g_Fishes[rand][0], g_Fishes[rand][1], g_Fishes[rand][2]);
Thanks, but that's whats not I'm looking for.
I'm looking for random weights which is a random between MINIMUM WEIGHT of a fish and a MAXIMUM WEIGHT of a fish so that's why I need RandomEx.
Any other answers?
Reply
#4

oh thatt for that do like this
pawn Код:
new rand = random(sizeof(g_Fishes));
new var = g_Fishes[rand][2]-g_Fishes[rand][1];
new randweight = random(var) + var;
//now use randweight as random weight it will be between minimum and maximum always :D
Reply
#5

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
oh thatt for that do like this
pawn Код:
new rand = random(sizeof(g_Fishes));
new var = g_Fishes[rand][2]-g_Fishes[rand][1];
new randweight = random(var) + var;
//now use randweight as random weight it will be between minimum and maximum always :D
Thank you for replying again, but another error:
pawn Код:
error 033: array must be indexed (variable "g_Fishes")
On line:
pawn Код:
new var = g_Fishes[rand][2]-g_Fishes[rand][1];
Reply
#6

try like this
not sure
but this should work
pawn Код:
enum fish
{
FishName[50],
MinWeight,
MaxWeight
};
new g_Fishes[][fish] = {
    {"Angelfish", 10, 88}, // {Fish name} {Min. weight [pounds]} {Max. weight [pounds]}
    {"Brill", 10, 78},
    {"Catfish", 40, 120},
    {"Dartfish", 30, 100},
    {"Electric Eel", 40, 118},
    {"Frogfish", 25, 105},
    {"Giant Sea Bass", 125, 302},
    {"Horn Shark", 50, 200}, // A shark!
    {"Icefish", 10, 40},
    {"Jackfish", 30, 80},
    {"Koi", 40, 120},
    {"Lemon Shark", 95, 255}, // I like lemons, also sharks
    {"Mackerel", 20, 75},
    {"Northern Pike", 20, 60},
    {"Oilfish", 60, 135},
    {"Porbeagle Shark", 135, 270}, // Another shark
    {"Quillfish", 10, 50},
    {"Requiem Shark", 60, 200}, // Another shark
    {"Salmon", 30, 120},
    {"Trout", 30, 75},
    {"Unicorn Fish", 10, 40}, // Search on wikipedia.....
    {"Viperfish", 10, 40},
    {"Whale Shark", 400, 1000}, // This fish is really rewarding because I love sharks, lol. (can reach 66k lbs but hey...)
    {"Yellowfin Tuna", 10, 60},
    {"Zebra Bullhead Shark", 50, 120} // Last fish and the last shark.
};
/*==========================================*/

new rand = random(sizeof(g_Fishes));
new var = g_Fishes[rand][MaxWeight]-g_Fishes[rand][MinWeight];
new randweight = random(var) + var;
Reply
#7

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
try like this
not sure
but this should work
pawn Код:
enum fish
{
FishName[50],
MinWeight,
MaxWeight
};
new g_Fishes[][fish] = {
    {"Angelfish", 10, 88}, // {Fish name} {Min. weight [pounds]} {Max. weight [pounds]}
    {"Brill", 10, 78},
    {"Catfish", 40, 120},
    {"Dartfish", 30, 100},
    {"Electric Eel", 40, 118},
    {"Frogfish", 25, 105},
    {"Giant Sea Bass", 125, 302},
    {"Horn Shark", 50, 200}, // A shark!
    {"Icefish", 10, 40},
    {"Jackfish", 30, 80},
    {"Koi", 40, 120},
    {"Lemon Shark", 95, 255}, // I like lemons, also sharks
    {"Mackerel", 20, 75},
    {"Northern Pike", 20, 60},
    {"Oilfish", 60, 135},
    {"Porbeagle Shark", 135, 270}, // Another shark
    {"Quillfish", 10, 50},
    {"Requiem Shark", 60, 200}, // Another shark
    {"Salmon", 30, 120},
    {"Trout", 30, 75},
    {"Unicorn Fish", 10, 40}, // Search on wikipedia.....
    {"Viperfish", 10, 40},
    {"Whale Shark", 400, 1000}, // This fish is really rewarding because I love sharks, lol. (can reach 66k lbs but hey...)
    {"Yellowfin Tuna", 10, 60},
    {"Zebra Bullhead Shark", 50, 120} // Last fish and the last shark.
};
/*==========================================*/

new rand = random(sizeof(g_Fishes));
new var = g_Fishes[rand][MaxWeight]-g_Fishes[rand][MinWeight];
new randweight = random(var) + var;
That's it! I was feeling like I was forgetting something, it was those enums!
Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)