Why is this happening? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Why is this happening? (
/showthread.php?tid=252670)
Why is this happening? -
MP2 - 02.05.2011
I'm going to keep this simple, this is the code:
pawn Code:
// To show the dialog
new count[99], cnt;
for(new i=0; i<MAX_OBJ; i++)
{
if(objects[i][creator] == playerid && IsValidDynamicObject(objects[i][object_id])) count[objects[i][grp]]++;
}
for(new i=0; i<99; i++)
{
if(!count[i]) continue;
if(!cnt) format(string, sizeof(string), "GROUP %i: %i objects", i, count[i]);
else format(string, sizeof(string), "%s\nGROUP %i: %i objects", string, i, count[i]);
cnt++;
players[playerid][groupfindid][cnt-1] = i; // So I know which group is where in the dialog list
}
ShowPlayerDialog(playerid, DIALOG_OGROUPS, DIALOG_STYLE_LIST, "Your object groups", string, "Select", "Cancel");
pawn Code:
// To handle the dialog response
if(dialogid == DIALOG_OGROUPS && response)
{
format(string, sizeof(string), "%i", players[playerid][groupfindid][listitem]);
SendClientMessage(playerid, COLOR_GREEN, string);
return dcmd_oglist(playerid, string);
}
pawn Code:
// The /oglist command
dcmd_oglist(playerid, params[])
{
SendClientMessageToAll(COLOR_SUMO, params);
if(!pObjects[playerid]) return SendErrorMessage(playerid, "You have no objects.");
if(!strlen(params)) return ShowSyntax(playerid, "/OGLIST [GROUPID]", "List objects in a certain group.");
if(strlen(params) > 2) return SendErrorMessage(playerid, ERROR_INVALID_OBJECT_GROUP);
if(strval(params) < 0) return SendErrorMessage(playerid, ERROR_INVALID_OBJECT_GROUP);
new ocnt;
SendClientMessageEx(playerid, COLOR_GREEN, "[[ == Listing objects in group == ]]");
for(new i=0; i<MAX_OBJ; i++)
{
if(objects[i][creator] == playerid && IsValidDynamicObject(objects[i][object_id]) && objects[i][grp] == strval(params))
{
ocnt++;
if(ocnt == 99) return SendClientMessage(playerid, COLOR_RED, "Over 99 objects in this group, no more can be shown in chat.");
format(string, sizeof(string), "GROUP %i: MSEL %i (MODEL: %i)", strval(params), i, objects[i][modelid]);
SendClientMessage(playerid, COLOR_TEAL, string);
}
}
if(!ocnt) SendClientMessage(playerid, COLOR_RED, "No objects in that group.");
return 1;
}
The problem is, it's listing the objects in the group I select, then it's getting called a second time and lists the objects in group 0. I have commented out the code in the /oglist command and put a sendclientmessage to show the parameters, and it shows one clientmessage with the number of the group I selected. Why then, when I uncomment the code, is it calling it twice the second time with 0 as a parameter?
If I change
return dcmd_oglist(playerid, string);
to
return dcmd_oglist(playerid, "8");
it works fine..
Thanks.