SA-MP Forums Archive
Need help with foreach. - 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)
+--- Thread: Need help with foreach. (/showthread.php?tid=420915)



Need help with foreach. - rangerxxll - 07.03.2013

Hi.

I've been experimenting with foreach, and so far I really enjoy working with it. But I'm trying to create a command, where it'll put everyone online into vehicle x. I'm checking if the players are in any vehicle, and IF they are I remove them before creating a new one for them. That's my goal.

But the thing is; the code seems to be working (Sort of.) but in-game it still says their name tag (And even shows their skin.) on their old vehicle, when they're driving the new one.

How can I fix this error? I'll show you my current code.

Any help is greatly appreciated as always. Thanks.

pawn Код:
CMD:vehall(playerid, params[])
{
    new vstring[128], id;
    if(PlayerInfo[playerid][pAdmin] >=2)
    {
        foreach ( new i : Player)
        {
            new Float:X, Float:Y, Float:Z, Float:A, col1, col2;
            if(sscanf(params, "iii", id, col1, col2)) return SendClientMessage(playerid, -1, "/veh [VehID][Col1][Col2]");
            if(IsPlayerInAnyVehicle(i))
            {
                RemovePlayerFromVehicle(i);
            }
            if(id < 400 || id > 611) return SendClientMessage(playerid, -1, "Vehicle IDs are only 400 - 611");
            GetPlayerFacingAngle(i, A);
            GetPlayerPos(i, X,Y,Z);
            id = CreateVehicle(id, X, Y, Z, A, col1, col2, 600);
            PutPlayerInVehicle(i, id, 0);
        }
        format(vstring,sizeof(vstring), "AdmCmd: %s %s has put everyone online into vehicle ID: %d.",GetAdminLvlName(playerid),GetName(playerid),id);
        SendClientMessageToAll(COLOR_ORANGE, vstring);
    }
    else SendClientMessage(playerid,COLOR_GREY, "You're not authorized to use this command.");
    return 1;
}



Re: Need help with foreach. - L.Hudson - 07.03.2013

Idk if that'll do much but try changing
pawn Код:
foreach ( new i : Player)
to
pawn Код:
foreach (Player, i)