for (HouseID = 1; HouseID < MAX_HOUSES; HouseID++) { if (strcmp(AHouseData[HouseID][Owner], Name, false) == 0) { hLevel = AHouseData[HouseID][HouseLevel]; SetPlayerVirtualWorld(playerid, 5000 + HouseID); printf("SetPlayerVirtualWorld(%d, %d);", playerid, 5000 + HouseID); SetPlayerInterior(playerid, AHouseInteriors[hLevel][InteriorID]); printf("SetPlayerInterior(%d, %d);", playerid, AHouseInteriors[hLevel][InteriorID]); SetPlayerPos(playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); printf("SetPlayerPos(%d, %f, %f, %f);", playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); APlayerData[playerid][CurrentHouse] = HouseID; SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Use {FFFF00}/housemenu{FFFF00} to change options for your house"); return 1; } else { printf("Else called"); }
Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called Else called SetPlayerInterior(0, 10); SetPlayerPos(0, 2260.760009, -1210.449951, 1049.020019);
SetPlayerVirtualWorld(0, 5828); SetPlayerInterior(0, 0); SetPlayerPos(0, 0.000000, 0.000000, 0.000000);
You're looping to check if the playername matches any of the ownernames of the houses in the server.
so it's normal that it shows "else called" when the name of the player is not the same as the ownername of the house you're checking in the loop. If the names match, it will execute the "if", if they don't it will execute the "else". the loop shouldn't crash the players though, If I were you I would rewrite all that code. Also make sure you read important notes for the function "strcmp". https://sampwiki.blast.hk/wiki/Strcmp |
Where should I put the 'break' in the code? When I put it in the if statement that checks if a house has been found it just outputs 'unreachable code'. If I put it before the final bracket in the for statement it just calls else (obviously).
Edit: I tried adding break at the end of the if statement but still doesn't work. |
for (HouseID = 1; HouseID < MAX_HOUSES; HouseID++) { if (strcmp(AHouseData[HouseID][Owner], Name, false) == 0) { hLevel = AHouseData[HouseID][HouseLevel]; SetPlayerVirtualWorld(playerid, 5000 + HouseID); printf("SetPlayerVirtualWorld(%d, %d);", playerid, 5000 + HouseID); SetPlayerInterior(playerid, AHouseInteriors[hLevel][InteriorID]); printf("SetPlayerInterior(%d, %d);", playerid, AHouseInteriors[hLevel][InteriorID]); SetPlayerPos(playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); printf("SetPlayerPos(%d, %f, %f, %f);", playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); APlayerData[playerid][CurrentHouse] = HouseID; SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Use {FFFF00}/housemenu{FFFF00} to change options for your house"); break; } else { printf("Else called"); }
Код:
for (HouseID = 1; HouseID < MAX_HOUSES; HouseID++) { if (strcmp(AHouseData[HouseID][Owner], Name, false) == 0) { hLevel = AHouseData[HouseID][HouseLevel]; SetPlayerVirtualWorld(playerid, 5000 + HouseID); printf("SetPlayerVirtualWorld(%d, %d);", playerid, 5000 + HouseID); SetPlayerInterior(playerid, AHouseInteriors[hLevel][InteriorID]); printf("SetPlayerInterior(%d, %d);", playerid, AHouseInteriors[hLevel][InteriorID]); SetPlayerPos(playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); printf("SetPlayerPos(%d, %f, %f, %f);", playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); APlayerData[playerid][CurrentHouse] = HouseID; SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Use {FFFF00}/housemenu{FFFF00} to change options for your house"); break; } else { printf("Else called"); } |
for (HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
for (new HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
pawn Код:
pawn Код:
Also, why are you doing that OnPlayerRequestSpawn? If you're trying to spawn the player at his own house, use OnPlayerSpawn instead. Printf in a loop, that's why it's spamming else called. |
printf("Else called"); Index = random(sizeof(ASpawnLocationsTrucker)); x = ASpawnLocationsTrucker[Index][SpawnX]; y = ASpawnLocationsTrucker[Index][SpawnY]; z = ASpawnLocationsTrucker[Index][SpawnZ]; Angle = ASpawnLocationsTrucker[Index][SpawnAngle]; SetPlayerTruckerClassRank(playerid);
new Index, Float:x, Float:y, Float:z, Float:Angle, Name[24]; GetPlayerName(playerid, Name, sizeof(Name)); new hLevel; for (new HouseID = 1; HouseID < MAX_HOUSES; HouseID++) { if (strcmp(AHouseData[HouseID][Owner], Name, false) == 0) { hLevel = AHouseData[HouseID][HouseLevel]; SetPlayerVirtualWorld(playerid, 5000 + HouseID); printf("SetPlayerVirtualWorld(%d, %d);", playerid, 5000 + HouseID); SetPlayerInterior(playerid, AHouseInteriors[hLevel][InteriorID]); printf("SetPlayerInterior(%d, %d);", playerid, AHouseInteriors[hLevel][InteriorID]); SetPlayerPos(playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); printf("SetPlayerPos(%d, %f, %f, %f);", playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]); APlayerData[playerid][CurrentHouse] = HouseID; SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Use {FFFF00}/housemenu{FFFF00} to change options for your house"); break; } }
Else called SetPlayerVirtualWorld(0, 5828); SetPlayerInterior(0, 0); SetPlayerPos(0, 0.000000, 0.000000, 0.000000);
Else called SetPlayerVirtualWorld(0, 5055); SetPlayerInterior(0, 10); SetPlayerPos(0, 2260.760009, -1210.449951, 1049.020019);
printf("Else called");
Index = random(sizeof(ASpawnLocationsTrucker));
x = ASpawnLocationsTrucker[Index][SpawnX];
y = ASpawnLocationsTrucker[Index][SpawnY];
z = ASpawnLocationsTrucker[Index][SpawnZ];
Angle = ASpawnLocationsTrucker[Index][SpawnAngle];
SetPlayerTruckerClassRank(playerid);
SetPlayerPos(playerid, x, y, z);
SetPlayerFacingAngle(playerid, Angle);
You can use SetPlayerPos if user doesn't own a house.
pawn Код:
|
if (!isnull(AHouseData[HouseID][Owner]) && strcmp(AHouseData[HouseID][Owner], Name, false) == 0)