SA-MP Forums Archive
/locate command help. - 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: /locate command help. (/showthread.php?tid=536369)



/locate command help. - earlybird325 - 09.09.2014

Hi. I need help with fixing this command.

Includes this requires:
a_samp
dcmd
playerzone

pawn Код:
dcmd_locate(playerid, params[])
{
        new targetid;
        if(LoginCheck[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "* You Must Be Logged To Use Any Command!");
        if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /locate [Player Name/ID]");
        if(targetid == INVALID_PLAYER_ID || !IsPlayerConnected(targetid )) return SendClientMessage(playerid, COLOR_RED, "* Player Is Not Connected.");
        {
            new str1[128], str2[128], str3[128], str4[128], str5[128], str6[128];
            new targetname[MAX_PLAYER_NAME];
            GetPlayerName(targetid,targetname,24);
            format(str1, sizeof (str1), "~y~Location For:~w~ %s (%d)", targetname, targetid);
            format(str2, sizeof (str2), "~y~Location:~w~ %s.", GetPlayerZone(targetid));
            format(str3, sizeof (str3), "~y~In A ~w~%s.", VehicleNames[GetVehicleModel(GetPlayerVehicleID(targetid))-400]);
            format(str4, sizeof (str4), "~y~On Foot.");
            format(str5, sizeof (str5), "~y~Dead.");
            format(str6, sizeof (str6), "~y~San Andreas");
            TextDrawSetString(locationtext, str1);
            TextDrawSetString(locationtextR1, str2);
            new playerState = GetPlayerState(targetid);
            if(IsPlayerInAnyVehicle(targetid))
            {
            TextDrawSetString(locationtextR2, str3);
            }
            if(playerState == PLAYER_STATE_ONFOOT)
            {
            TextDrawSetString(locationtextR2, str4);
            }
            if(playerState == PLAYER_STATE_WASTED)
            {
            TextDrawSetString(locationtextR2, str5);
            }
            if(aduty[targetid] == 1)
            {
            TextDrawSetString(locationtextR2, str4);
            TextDrawSetString(locationtextR1, str6);
            }
            if(spectate[targetid] == 1)
            {
            TextDrawSetString(locationtextR2, str4);
            TextDrawSetString(locationtextR1, str6);
            }
            TextDrawHideForPlayer(playerid,locationtextR1);
            TextDrawHideForPlayer(playerid,locationtextR2);
            TextDrawHideForPlayer(playerid,locationtext);
            TextDrawHideForPlayer(playerid,locationtext2);
            TextDrawShowForPlayer(playerid,locationtext);
            TextDrawShowForPlayer(playerid,locationtext2);
            TextDrawShowForPlayer(playerid,locationtextR1);
            TextDrawShowForPlayer(playerid,locationtextR2);
    }
    return 1;
}
What the command does in my script is it returns an invalid command message upon entering a valid player id, but when I give an invalid player id, it returns the: * Player Is Not Connected. message. Please help me and thanks!


Re: /locate command help. - dusk - 09.09.2014

Are you talking about the "SERVER: unknown command" error?

If so, the code probably crashes somewhere.... Try downloading "crashdetect" plugin to confirm this issue.

I believe this may be the reason:
pawn Код:
VehicleNames[GetVehicleModel(GetPlayerVehicleID(targetid))-400]);
You don't check if the player is in a vehicle before it. So if playerd "targetid" isn't in a vehicle this is a "Array out of bounds" error, because -400 isn't a valid index.


Re: /locate command help. - Beckett - 09.09.2014

To get the vehicle name you don't need ID you need model.


Re: /locate command help. - earlybird325 - 10.09.2014

Quote:
Originally Posted by dusk
Посмотреть сообщение
Are you talking about the "SERVER: unknown command" error?

If so, the code probably crashes somewhere.... Try downloading "crashdetect" plugin to confirm this issue.

I believe this may be the reason:
pawn Код:
VehicleNames[GetVehicleModel(GetPlayerVehicleID(targetid))-400]);
You don't check if the player is in a vehicle before it. So if playerd "targetid" isn't in a vehicle this is a "Array out of bounds" error, because -400 isn't a valid index.
That is the exact error. Thanks for this, but do you know of a way to fix it?


Re: /locate command help. - dusk - 10.09.2014

Just check if a player is in a vehicle before that.

pawn Код:
if(IsPlayerInAnyVehicle(targetid))
   format(str3, sizeof (str3), "~y~In A ~w~%s.", VehicleNames[GetVehicleModel(GetPlayerVehicleID(targetid))-400]);
else strcat(str3,"~y~not in vehicle"); // no need to use format if there are no variables.