Problem +1 rep for help
#1

Quote:

if(strcmp(cmd, "/maddogdm", true) == 0)
{
if(indeathmatch[playerid] == 1)
{
SendClientMessage(playerid, COLOR_RED, "Type /kill to leave the DM FIRST.");
return 1;
}
else
{
new Float:maddogspawn[9][3] =
{
// Positions, (X, Y, Z and Facing Angle)
{1266.3718,-780.3331,1084.0078},
{1253.6959,-786.6283,1084.0149},
{1268.9158,-786.1834,1084.0149},
{1266.7693,-809.4655,1084.0078},
{1234.0151,-811.4605,1084.0078},
{1275.4358,-826.8328,1085.6328},
{1280.6829,-815.3812,1089.9375},
{1283.4325,-785.7381,1089.9375},
{1278.5106,-772.6031,1091.9063}
};
new rand = random(sizeof(maddogspawn));
SetPlayerPos(playerid,maddogspawn[rand][0],maddogspawn[rand][1],maddogspawn[rand][2],maddogspawn[rand][3],maddogspawn[rand][4],maddogspawn[rand][5],maddogspawn[rand][6],maddogspawn[rand][7],maddogspawn[rand][8]);

Thats part of my script that doesnt work.

The full part
Quote:

if(strcmp(cmd, "/maddogdm", true) == 0)
{
if(indeathmatch[playerid] == 1)
{
SendClientMessage(playerid, COLOR_RED, "Type /kill to leave the DM FIRST.");
return 1;
}
else
{
new Float:maddogspawn[9][3] =
{
// Positions, (X, Y, Z and Facing Angle)
{1266.3718,-780.3331,1084.0078},
{1253.6959,-786.6283,1084.0149},
{1268.9158,-786.1834,1084.0149},
{1266.7693,-809.4655,1084.0078},
{1234.0151,-811.4605,1084.0078},
{1275.4358,-826.8328,1085.6328},
{1280.6829,-815.3812,1089.9375},
{1283.4325,-785.7381,1089.9375},
{1278.5106,-772.6031,1091.9063}
};
new rand = random(sizeof(maddogspawn));
SetPlayerPos(playerid,maddogspawn[rand][0],maddogspawn[rand][1],maddogspawn[rand][2],maddogspawn[rand][3],maddogspawn[rand][4],maddogspawn[rand][5],maddogspawn[rand][6],maddogspawn[rand][7],maddogspawn[rand][8]);
SetPlayerInterior(playerid, 5);
SendClientMessage(playerid, COLOR_RED, "------------Mad Dogs DM------------");
SendClientMessage(playerid, COLOR_GREEN, "Welcome to Maddogdm");
SendClientMessage(playerid, COLOR_RED, "----------------------------");
format(string,sizeof(string),"%s (Id:%d) Has Teleported to MadDogDM! (/maddogdm)",PlayerName,playerid);
SendClientMessageToAll(COLOR_GREEN, "string");
SetPlayerPos(playerid, 1299.14,-794.77,1084.00);
indeathmatch[playerid] = 1;
return 1;
}
}

Thats where it comes from. It all works perfectly but the random spawn.
When i try and compile i get this one error.

Quote:

(200) : error 032: array index out of bounds (variable "maddogspawn")

How do i fix this?

Thanks, if you can help me
Reply
#2

This:
pawn Код:
maddogspawn[rand][0],maddogspawn[rand][1],maddogspawn[rand][2],maddogspawn[rand][3],maddogspawn[rand][4],maddogspawn[rand][5],maddogspawn[rand][6],maddogspawn[rand][7],maddogspawn[rand][8]
i think it needs to be this:
pawn Код:
maddogspawn[rand][0],maddogspawn[rand][1],maddogspawn[rand][2]);
you only have [9][3], so that means, you cannot go further at [3], and you went to 9, for the [9] you already used rand.

It will be like this i think:
pawn Код:
SetPlayerPos(playerid,maddogspawn[rand][0],maddogspawn[rand][1],maddogspawn[rand][2]);
Reply
#3

Will that use all the random positions ? Or just 3 of them? I want it so it will use them all.
Reply
#4

Well, i think it will use them all, i don't know if your [rand] code is correct..
Just try it, and if it doesn't work, we will search for the problem

EDIT: i think i found something, not sure if that causes problems..
I checked the wiki, and your random spawns should be like this:
change:
pawn Код:
new Float:maddogspawn[9][3] =
to
pawn Код:
new Float:maddogspawn[][3] =
I used the wiki page: https://sampwiki.blast.hk/wiki/Random to be sure, check the first part

and again, not sure if the code you have now would cause any problems, could be that it's just ok, so test it with the code you have now first, if it doesn't work, try changing the part i said.
Reply
#5

It works! Thanks very much! ^^ +1 Rep
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)