local variable "Random" shadows a variable at a preceding level
#1

Код:
public OnPlayerSpawn(playerid)
{
new Random = random(sizeof(RandomSpawnsCiv));
	SetPlayerPos(playerid, RandomSpawnsCiv[Random][0], RandomSpawnsCiv[Random][1], RandomSpawnsCiv[Random][2]);
    SetPlayerFacingAngle(playerid, RandomSpawnsCiv[Random][3]);
    if(gTeam[playerid] == TEAM_CIV)
    {
        GivePlayerWeapon(playerid,23,100);
        GivePlayerWeapon(playerid,32,50);
    }

    if(gTeam[playerid] == TEAM_COP)
    {
        GivePlayerWeapon(playerid,3,1);
        GivePlayerWeapon(playerid,22,50);
        GivePlayerWeapon(playerid,30,75);
    }

    SetPlayerInterior(playerid,0);
    SetPlayerMapIcon(playerid, 12, -2050.9399,461.4982,35.1719, 52, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -1366.1598,-102.6746,6.0000, 52, 0, MAPICON_LOCAL);

    SetPlayerMapIcon(playerid, 57, -2766.2039,788.3242,52.7813, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2440.0798,742.6775,35.0156, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2507.7576,-49.3189,25.6880, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2417.7581,969.4247,45.2969, 17, 0, MAPICON_LOCAL);

    TextDrawShowForPlayer(playerid, DollarTxd);
    TextDrawShowForPlayer(playerid,Servt);
   	TextDrawShowForPlayer(playerid, LocationTD[playerid]);

    if(PlayerInfo[playerid][pJailed] == 1)
    {
    pJailTimerID[playerid] = SetTimerEx("pJailTimer", 1000, true, "i", playerid);
    pJailCount[playerid] = 20 + random(41);
    SendClientMessage(playerid,0xFF0000FF,"Welcome,go back in the jail and pay for your crimes.");
    new Random = random(sizeof(RandomJailSpawns));
    SetPlayerPos(playerid, RandomJailSpawns[Random][0], RandomJailSpawns[Random][1], RandomJailSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomJailSpawns[Random][3]);
    ResetPlayerWeapons(playerid);
    SetPlayerInterior(playerid, 10);
    SetPlayerWantedLevel(playerid,0);
    }
    return 1;
}
Please Help Me To Fix This local variable "Random" shadows a variable at a preceding level
Reply
#2

Try this.
Код:
public OnPlayerSpawn(playerid)
{
	new Rand = random(sizeof(RandomSpawnsCiv));
	SetPlayerPos(playerid, RandomSpawnsCiv[Rand][0], RandomSpawnsCiv[Rand][1], RandomSpawnsCiv[Rand][2]);
    SetPlayerFacingAngle(playerid, RandomSpawnsCiv[Rand][3]);
    if(gTeam[playerid] == TEAM_CIV)
    {
        GivePlayerWeapon(playerid,23,100);
        GivePlayerWeapon(playerid,32,50);
    }

    if(gTeam[playerid] == TEAM_COP)
    {
        GivePlayerWeapon(playerid,3,1);
        GivePlayerWeapon(playerid,22,50);
        GivePlayerWeapon(playerid,30,75);
    }

    SetPlayerInterior(playerid,0);
    SetPlayerMapIcon(playerid, 12, -2050.9399,461.4982,35.1719, 52, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -1366.1598,-102.6746,6.0000, 52, 0, MAPICON_LOCAL);

    SetPlayerMapIcon(playerid, 57, -2766.2039,788.3242,52.7813, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2440.0798,742.6775,35.0156, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2507.7576,-49.3189,25.6880, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2417.7581,969.4247,45.2969, 17, 0, MAPICON_LOCAL);

    TextDrawShowForPlayer(playerid, DollarTxd);
    TextDrawShowForPlayer(playerid,Servt);
   	TextDrawShowForPlayer(playerid, LocationTD[playerid]);

    if(PlayerInfo[playerid][pJailed] == 1)
    {
    pJailTimerID[playerid] = SetTimerEx("pJailTimer", 1000, true, "i", playerid);
    pJailCount[playerid] = 20 + random(41);
    SendClientMessage(playerid,0xFF0000FF,"Welcome,go back in the jail and pay for your crimes.");
    new Random = random(sizeof(RandomJailSpawns));
    SetPlayerPos(playerid, RandomJailSpawns[Random][0], RandomJailSpawns[Random][1], RandomJailSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomJailSpawns[Random][3]);
    ResetPlayerWeapons(playerid);
    SetPlayerInterior(playerid, 10);
    SetPlayerWantedLevel(playerid,0);
    }
    return 1;
}
Reply
#3

Thanks
Reply
#4

What? That was NOT a good way to fix that! In fact you just made it worse! Instead of fixing the one variable you made another one, BAD!

Код:
public OnPlayerSpawn(playerid)
{
	new Random;
    if(PlayerInfo[playerid][pJailed] == 1)
    {
    pJailTimerID[playerid] = SetTimerEx("pJailTimer", 1000, true, "i", playerid);
    pJailCount[playerid] = 20 + random(41);
    SendClientMessage(playerid,0xFF0000FF,"Welcome,go back in the jail and pay for your crimes.");
    Random = random(sizeof(RandomJailSpawns));
    SetPlayerPos(playerid, RandomJailSpawns[Random][0], RandomJailSpawns[Random][1], RandomJailSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomJailSpawns[Random][3]);
    SetPlayerInterior(playerid, 10);
    return 1;
    }

    Random = random(sizeof(RandomSpawnsCiv));
	SetPlayerPos(playerid, RandomSpawnsCiv[Random][0], RandomSpawnsCiv[Random][1], RandomSpawnsCiv[Random][2]);
    SetPlayerFacingAngle(playerid, RandomSpawnsCiv[Random][3]);
    if(gTeam[playerid] == TEAM_CIV)
    {
        GivePlayerWeapon(playerid,23,100);
        GivePlayerWeapon(playerid,32,50);
    }

    if(gTeam[playerid] == TEAM_COP)
    {
        GivePlayerWeapon(playerid,3,1);
        GivePlayerWeapon(playerid,22,50);
        GivePlayerWeapon(playerid,30,75);
    }

    SetPlayerInterior(playerid,0);
    SetPlayerMapIcon(playerid, 12, -2050.9399,461.4982,35.1719, 52, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -1366.1598,-102.6746,6.0000, 52, 0, MAPICON_LOCAL);

    SetPlayerMapIcon(playerid, 57, -2766.2039,788.3242,52.7813, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2440.0798,742.6775,35.0156, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2507.7576,-49.3189,25.6880, 17, 0, MAPICON_LOCAL);
    SetPlayerMapIcon(playerid, 57, -2417.7581,969.4247,45.2969, 17, 0, MAPICON_LOCAL);

    TextDrawShowForPlayer(playerid, DollarTxd);
    TextDrawShowForPlayer(playerid,Servt);
   	TextDrawShowForPlayer(playerid, LocationTD[playerid]);
    return 1;
}
I move the jail part to be first because it should be, removed unnecessary stuff, and returned in jail part if player is in jail.

Fix the indentation yourself, I'm on my phone...
Reply


Forum Jump:


Users browsing this thread: