SA-MP Forums Archive
/oprison doesn't work - 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: /oprison doesn't work (/showthread.php?tid=603042)



/oprison doesn't work - iKevin - 17.03.2016

Код:
IRP:oprison(playerid, var[])
{
    new user[32], string[128], file[32], time;
   	if(!Logged(playerid)) return NoLogin(playerid);
	if(Player[playerid][pAdmin] < 3) return NoAuth(playerid);
	if(sscanf(var, "s[32]is[128]", user, time, var)) return SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /oprison [playername] [time] [reason]");
	if(RPIDFN(user) != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD2, "Player is connected to the server, use /prison instead.");
	format(file, sizeof(file), "Accounts/%s.ini", user);
	if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_GRAD2, "Player name not found.");
	if(Player[playerid][pAdmin] < dini_Int(file, "Admin")) return SendClientMessage(playerid, COLOR_GRAD2, "Player has a higher admin level than you.");
	format(string, sizeof(string), "AdmCmd: %s has been offline-prisoned by %s, reason: %s", user, GetName(playerid), var);
	SendClientMessageToAll(COLOR_LIGHTRED, string);
	format(string, sizeof(string), "AdmCmd: %s has been offline-prisoned by %s, reason: %s", user, GetName(playerid) , var);
	// Prisoning
	dini_IntSet(file, "pJail", 1);
	// Prisonreason
	dini_Set(file, "pJailReason", var);
	dini_Set(file, "pJailBy", GetName(playerid));
	dini_IntSet(file, "pJailTime", time);
	return 1;
}
What's actually wrong here? Player should be prisoned, but he isn't.


Re: /oprison doesn't work - introzen - 17.03.2016

I assume you have a prisonTimer that checks for pJail in the .ini, seeing as you do not change the players position directly with the command. Show us the prisonTimer if so.

Also, there's no reason to format the string twice with the same text.


Re: /oprison doesn't work - ATGOggy - 17.03.2016

Add this: dini_Close(file);


Re: /oprison doesn't work - iKevin - 17.03.2016

Код:
forward PrisonTimer();
public PrisonTimer()
{
	foreach(Player, playerid)
	{
		new string[128];
	    if(Player[playerid][pPrisonTime] <=0)
	    {
	        if(Player[playerid][pPrison] == 1) // NG Prison
			{
			    Player[playerid][pPrison] = 0;
				Player[playerid][pPrisonTime] = 0;
				SetPlayerInterior(playerid, 0);
				SetPlayerFacingAngle(playerid, 87.1763);
				SetPlayerColor(playerid, TRANSPARENT_WHITE);
				SetPlayerPos(playerid, 1546.1428,-1675.4786,13.5617);
				SetCameraBehindPlayer(playerid);
				SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have served your prison time, try to be a better citizen.");
				format(string, sizeof(string), "Prison: %s has been released as they served their prison time.", GetName(playerid));
				foreach(Player, i)
				{
				    if(IsACop(i) && IsFBI(i) && IsDOC(i))
				    {
				        SendClientMessage(i, COLOR_BLUE, string);
				    }
				}
			}
	        else if(Player[playerid][pPrison] == 2) // Admin Prison
			{
			    Player[playerid][pPrison] = 0;
				Player[playerid][pPrisonTime] = 0;
				format(Player[playerid][pPrisonReason], 64, "");
				format(Player[playerid][pPrisonBy], 32, "");
				SetPlayerInterior(playerid, 0);
				SetPlayerVirtualWorld(playerid, 0);
				SetPlayerFacingAngle(playerid, 87.1763);
				SetPlayerColor(playerid, TRANSPARENT_WHITE);
				SetPlayerPos(playerid, 1546.1428,-1675.4786,13.5617);
				SetCameraBehindPlayer(playerid);
				SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have served your prison time, try to be a better player.");
			}
	    }
	    else
	    {
            if(!IsAFK[playerid])
            {
        	   	Player[playerid][pPrisonTime] --;
	          	format(string,sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~r~Prison Time Left: ~w~%d ~r~seconds", Player[playerid][pPrisonTime]);
	     		GameTextForPlayer(playerid, string,1500, 3);
	     	}
		}
	}
	return 1;
}
There's prisonTimer functions. Yes, directly from ini.

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Add this: dini_Close(file);
Where?


Re: /oprison doesn't work - ATGOggy - 17.03.2016

PHP код:
IRP:oprison(playerid, var[])
{
    new 
user[32], string[128], file[32], time;
       if(!
Logged(playerid)) return NoLogin(playerid);
    if(
Player[playerid][pAdmin] < 3) return NoAuth(playerid);
    if(
sscanf(var, "s[32]is[128]"usertime, var)) return SendClientMessage(playeridCOLOR_WHITE"** [Usage]: /oprison [playername] [time] [reason]");
    if(
RPIDFN(user) != INVALID_PLAYER_ID) return SendClientMessage(playeridCOLOR_GRAD2"Player is connected to the server, use /prison instead.");
    
format(filesizeof(file), "Accounts/%s.ini"user);
    if(!
dini_Exists(file)) return SendClientMessage(playeridCOLOR_GRAD2"Player name not found.");
    if(
Player[playerid][pAdmin] < dini_Int(file"Admin")) return SendClientMessage(playeridCOLOR_GRAD2"Player has a higher admin level than you.");
    
format(stringsizeof(string), "AdmCmd: %s has been offline-prisoned by %s, reason: %s"userGetName(playerid), var);
    
SendClientMessageToAll(COLOR_LIGHTREDstring);
    
format(stringsizeof(string), "AdmCmd: %s has been offline-prisoned by %s, reason: %s"userGetName(playerid) , var);
    
// Prisoning
    
dini_IntSet(file"pJail"1);
    
// Prisonreason
    
dini_Set(file"pJailReason", var);
    
dini_Set(file"pJailBy"GetName(playerid));
    
dini_IntSet(file"pJailTime"time);
        
dini_Close(file);
    return 
1;

You need to close an INI file after editing it to save your changes.


Re: /oprison doesn't work - introzen - 17.03.2016

How often do you update Array values for Array Player? You do not in the command set Player[playerid][pPrison] = 1 etc, so I assume you update the array frequently?


Re: /oprison doesn't work - iKevin - 17.03.2016

Quote:
Originally Posted by introzen
Посмотреть сообщение
How often do you update Array values for Array Player? You do not in the command set Player[playerid][pPrison] = 1 etc, so I assume you update the array frequently?
Don't get ya. Just tell me what to do.


Re: /oprison doesn't work - introzen - 17.03.2016

Quote:
Originally Posted by KevinExec
Посмотреть сообщение
Don't get ya. Just tell me what to do.
If this is a command for sending an offline-player to jail, you will need to enter the information and then save the file by dini_close, just as ATGOggy stated in his reply.

Код:
IRP:oprison(playerid, var[])
{
    new user[32], string[128], file[32], time;
       if(!Logged(playerid)) return NoLogin(playerid);
    if(Player[playerid][pAdmin] < 3) return NoAuth(playerid);
    if(sscanf(var, "s[32]is[128]", user, time, var)) return SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /oprison [playername] [time] [reason]");
    if(RPIDFN(user) != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD2, "Player is connected to the server, use /prison instead.");
    format(file, sizeof(file), "Accounts/%s.ini", user);
    if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_GRAD2, "Player name not found.");
    if(Player[playerid][pAdmin] < dini_Int(file, "Admin")) return SendClientMessage(playerid, COLOR_GRAD2, "Player has a higher admin level than you.");
    format(string, sizeof(string), "AdmCmd: %s has been offline-prisoned by %s, reason: %s", user, GetName(playerid), var);
    SendClientMessageToAll(COLOR_LIGHTRED, string);
    format(string, sizeof(string), "AdmCmd: %s has been offline-prisoned by %s, reason: %s", user, GetName(playerid) , var);
    // Prisoning
    dini_IntSet(file, "pJail", 1);
    // Prisonreason
    dini_Set(file, "pJailReason", var);
    dini_Set(file, "pJailBy", GetName(playerid));
    dini_IntSet(file, "pJailTime", time);
    dini_Close(file);
    return 1;
}
Also, you will need to update Player[][pPrison], Player[][pPrisonTime] and Player[][pPrisonReason] correctly when the player logs on.

Although, the biggest problem here is that the PrisonTimer does not update the player position, neither does your /oprison. You'll therefore have to check if player is jailed on player connect or player login and use
Код:
SetPlayerPos(playerid, x, y, z);



Re: /oprison doesn't work - iKevin - 17.03.2016

Can you give me the all updated codes?


Re: /oprison doesn't work - introzen - 17.03.2016

Show me your /login, please.