Script /jail
#1

Hello everyone, I have another problem, I try to randomize the spawn when the command / jail
but it spawns in the same spawn.

Quote:

if(strcmp(cmd, "/jail", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jail [playerid/PartOfName] [minutes] [reason]");
return 1;
}
new playa;
new time;
playa = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
time = strvalEx(tmp);
if(PlayerInfo[playerid][pAdmin] >= 2)
{
if(IsPlayerConnected(playa))
{
if(playa != INVALID_PLAYER_ID)
{
GetPlayerName(playa, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jail [playerid/PartOfName] [minutes] [reason]");
return 1;
}
format(string, sizeof(string), "AdmCmd: %s has been jailed by an Admin, reason: %s", giveplayer, (result));
SendClientMessageToAll(COLOR_LIGHTRED, string);
ClearGuns(playa);
ResetPlayerWeapons(playa);
PlayerInfo[playa][pWantedLevel] = 0;
SetPlayerWantedLevel(playa, 0);
SetPlayerToTeamColor(playa);
PlayerInfo[playa][pJailed] = 1;
PlayerInfo[playa][pJailTime] = time*60;
SetPlayerInterior(playa, 6);
SetPlayerVirtualWorld(playerid, 0);
PlayerInfo[giveplayerid][pVirtualWorld] = 0;
new rand = 0 + random(1);
if(rand == 0) { SetPlayerPos(playa,264.5, 86.5,1000.7); }
else if(rand == 1) {SetPlayerPos(playa,264.2,82.3,1000.7); }
SetPlayerFacingAngle(playa, -90);
format(string, sizeof(string), "You are jailed for %d minutes. Bail: Unable", time);
SendClientMessage(playa, COLOR_LIGHTBLUE, string);
format(PlayerInfo[playa][pPrisonedBy], 128, "%s (Admin)", PlayerName(playerid));
format(PlayerInfo[playa][pPrisonReason], 32, "%s", (result));
PlayerInfo[playa][pAdminJailed] = 1;

}
}
}
else
{
SendClientMessage(playerid, COLOR_GRAD1, " You are not authorized to use that command !");
}
}
return 1;
}

Reply
#2

pawn Код:
if(strcmp(cmd, "/jail", true) == 0)
{
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jail [playerid/PartOfName] [minutes] [reason]");
    new playa = ReturnUser(tmp);
    tmp = strtok(cmdtext, idx);
    new time = strvalEx(tmp);
    tmp = strtok(cmdtext, idx, EOS);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jail [playerid/PartOfName] [minutes] [reason]");

    if(PlayerInfo[playerid][pAdmin] < 2) SendClientMessage(playerid, COLOR_GRAD1, " You are not authorized to use that command !");
    else if(playa == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_GRAD1, " Player is not online !");
    else{
        GetPlayerName(playa, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        format(string, sizeof(string), "AdmCmd: %s has been jailed by an Admin, reason: %s", giveplayer, tmp);
        SendClientMessageToAll(COLOR_LIGHTRED, string);
        ClearGuns(playa);
        ResetPlayerWeapons(playa);
        PlayerInfo[playa][pWantedLevel] = 0;
        SetPlayerWantedLevel(playa, 0);
        SetPlayerToTeamColor(playa);
        PlayerInfo[playa][pJailed] = 1;
        PlayerInfo[playa][pJailTime] = time*60;
        SetPlayerInterior(playa, 6);
        SetPlayerVirtualWorld(playa, 0);
        PlayerInfo[playa][pVirtualWorld] = 0;
        new rand = random(2);
        if(rand == 0) SetPlayerPos(playa,264.5, 86.5,1000.7);
        else SetPlayerPos(playa,264.2,82.3,1000.7);

        SetPlayerFacingAngle(playa, -90);
        format(string, sizeof(string), "You are jailed for %d minutes. Bail: Unable", time);
        SendClientMessage(playa, COLOR_LIGHTBLUE, string);
        format(PlayerInfo[playa][pPrisonedBy], 128, "%s (Admin)", PlayerName(playerid));
        format(PlayerInfo[playa][pPrisonReason], 32, "%s", tmp);
        PlayerInfo[playa][pAdminJailed] = 1;
    }
    return 1;
}
Reply
#3

When that happens just use some debugs to track the variables and see were is the problem.....
In this case just increase the the random values by 1 like this:

new rand = 0 + random(2);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)