Spawn location problem
#1

The problem is that even if I don't own a house, it'll say "Spawn set to house"..
pawn Код:
new Hcount;
                for(new i = 0; i < MAX_HOUSES; i++)
                {
                    if(strcmp(HouseInfo[i][hOwner], PlayerInfo[playerid][Name]) == 0)
                    {
                        Hcount++;
                        SendClientMessage(playerid, SERVER, "Spawn set to house.");
                        SetSpawnInfo(playerid, PlayerInfo[playerid][Job], PlayerInfo[playerid][Skin], HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], 0, 0, 0, 0, 0, 0, 0);
                        TogglePlayerSpectating(playerid, false);
                        break;
                    }
                    else continue;
                }
                if(Hcount < 1)
                {
                    SendClientMessage(playerid, RED, "You don't own a house. Searching for business..");
                    new Bcount;
                    for(new b = 0; b < MAX_BIZZ; b++)
                    {
                        if(strcmp(BusinessInfo[b][bOwner], PlayerInfo[playerid][Name]) == 0)
                        {
                            Bcount++;
                            SendClientMessage(playerid, SERVER, "Spawn set to business.");
                            SetSpawnInfo(playerid, PlayerInfo[playerid][Job], PlayerInfo[playerid][Skin], BusinessInfo[b][bEnterX], BusinessInfo[b][bEnterY], BusinessInfo[b][bEnterZ], 0, 0, 0, 0, 0, 0, 0);
                            TogglePlayerSpectating(playerid, false);
                            break;
                        }
                        else continue;
                    }
                    if(Bcount < 1)
                    {
                        SendClientMessage(playerid, RED, "You don't own a business. Spawn location set at random place.");
                        SetSpawnInfo(playerid, PlayerInfo[playerid][Job], 42, 1568.8165, -1691.8510, 5.8906, 0, 0, 0, 0, 0, 0, 0);
                        TogglePlayerSpectating(playerid, false);
                    }
                }
Reply
#2

replace Hcount++ with ++Hcount, should do the trick
Reply
#3

Quote:
Originally Posted by BlackM
Посмотреть сообщение
replace Hcount++ with ++Hcount, should do the trick
Why would that make difference
Reply
#4

If HouseInfo[i][hOwner] is NULL/empty, strcmp will return 0 (that they're equal) so check it with isnull.
pawn Код:
if (!isnull(HouseInfo[i][hOwner]) && !strcmp(HouseInfo[i][hOwner], PlayerInfo[playerid][Name], true, MAX_PLAYER_NAME))
Quote:
Originally Posted by BlackM
Посмотреть сообщение
replace Hcount++ with ++Hcount, should do the trick
It only makes difference when it is used inside a statement.
Reply
#5

Hcount++ increments Hcount however returns the original Hcount value not the incremented one. ++Hcount increments Hcount and returns the incremented value. Though after revising ur code again, this may not be the fix to your problem but it is essential for your script, so put it. Try and make sure that the Player Name you use isnt equivalent to any HouseInfo[i][hOwner] , if possible.
Reply
#6

[QUOTE=Konstantinos;3119503]If HouseInfo[i][hOwner] is NULL/empty, strcmp will return 0 (that they're equal) so check it with isnull.
pawn Код:
if (!isnull(HouseInfo[i][hOwner]) && !strcmp(HouseInfo[i][hOwner], PlayerInfo[playerid][Name], true, MAX_PLAYER_NAME))
I kinda suspected that, but still, strcmp should compare the strings, if HouseInfo[i][hOwner] does not equal the Player's Name then probably it should return -1 or 1 and not 0. But at equal probability u seem right too :P
Reply
#7

[QUOTE=Konstantinos;3119503]If HouseInfo[i][hOwner] is NULL/empty, strcmp will return 0 (that they're equal) so check it with isnull.
pawn Код:
if (!isnull(HouseInfo[i][hOwner]) && !strcmp(HouseInfo[i][hOwner], PlayerInfo[playerid][Name], true, MAX_PLAYER_NAME))
[/QUOTE=Konstantinos;3119503]
I kinda suspected that, but still, strcmp should compare the strings, if HouseInfo[i][hOwner] does not equal the Player's Name then probably it should return -1 or 1 and not 0. But at equal probability u seem right too :P
Reply
#8

https://sampwiki.blast.hk/wiki/Strcmp

Quote:
Important note: This function also returns 0 if either string is empty.

PS: There is an Edit () button to modify your post instead of posting a new one.
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Strcmp



PS: There is an Edit () button to modify your post instead of posting a new one.
I did so for some reason it posted my post trice
Reply
#10

Amazing, it works now, thanks once again Konstantinos and BlackM.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)