Timer issue.
#1

Yeah, so I've been working on using timers and I'll admit, I'm totally useless when it comes to the more advanced timer use. So all I'd like to do is when I use /jail, it'll store their amount of minutes into a variable which can be used to be shown on a command and will decrease every minute. Here's my code;

Код:
if(strcmp(cmd, "/jail", true) == 0)
  {
    if(IsPlayerConnected(playerid))
    {
     tmp = strtok(cmdtext, idx);
     if(!strlen(tmp))
     {
      SendClientMessage(playerid, COLOR_RED, "USAGE: /jail [ID] [Minutes] [Reason]");
      return 1;
     }
     new playa;
     new money;
     playa = strval(tmp);
     tmp = strtok(cmdtext, idx);
 			if(PlayerData[playerid][Admin] < 3) return SendClientMessage(playerid, RED, "SERVER MESSAGE: You are not admin level 3.");
			{
       if(IsPlayerConnected(playa))
       {
         if(playa != INVALID_PLAYER_ID)
         {
      	 new otherplayer = strval(tmp);
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;
   			 GetPlayerName(playa, giveplayer, sizeof(giveplayer));
         GetPlayerName(playerid, sendername, sizeof(sendername));
         if(PlayerData[playerid][onduty] == 0) return SendClientMessage(playerid, RED, "Your not on Administration duty!");
 		 	   if(PlayerData[playerid][Admin] < PlayerData[otherplayer][Admin]) return SendClientMessage(playerid, RED, "You can't use this command on higher level Admins than yourself!");
         format(string, sizeof(string), "*Administrator %s jailed %s for %d minutes – [Reason: %s]", sendername,giveplayer,PlayerData[playa][PrisonTime],result);
         SendClientMessageToAll(COLOR_RED1, string);
         ResetPlayerWeapons(playa);
         PlayerData[playa][Prison] = 1;
         GameTextForPlayer(playa, "~r~Admin Jailed", 3000, 3);
         SetPlayerInterior(playa, 6);
         SetPlayerPos(playa, 264.6288,77.5742,1001.0391);
         format(string, sizeof(string), "You are jailed for %d minutes – Reason: %s", PlayerData[playa][PrisonTime],result);
         SendClientMessage(playa, COLOR_RED1, string);
					PlayerData[playa][PrisonTime] = money*60000;
					SetTimerEx("JailTimerPassing",60000,1,"-",playa);
				}
      }
     }
   }
   return 1;
  }
I apologize for the terrible indentation but I can't help it. Anyhow, I'd appreciate any help here as I don't have a clue what I'm doing here.
Reply
#2

SetTimerEx("JailTimerPassing",60000,1,"-",playa);

Not sure what made you put "-", but if "playa" is the playerid (integer) you need "i".
Reply
#3

Alright thanks, I'll try that. As I said, I didn't really know what that was so I took a guess with that really as I'm useless with timers.
Reply
#4

I would very much suggest dcmd and sscanf.
Reply
#5

Quote:
Originally Posted by Weirdosport
SetTimerEx("JailTimerPassing",60000,1,"-",playa);

Not sure what made you put "-", but if "playa" is the playerid (integer) you need "i".
We tryed this it did not work.
Reply
#6

Sorry for bumping, but it works now the only problem it, it unjails me automaticly every one minute :S.

Код:
public JailTimerPassing(playerid)
{
	new string[256];
	new playrname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playrname, sizeof(playrname));
	SetPlayerWorldBounds(playerid,20000.0000,-20000.0000,20000.0000,-20000.0000);
	PlayerData[playerid][Prison] = 0;
	PlayerData[playerid][PrisonTime] = 0;
	SetPlayerArmour(playerid, 0);
	SetPlayerInterior(playerid,0);
	format(string, sizeof(string), "%s was unjailed automatically (Times Up).", playrname);
	SendClientMessageToAll(RED, string);
	SetPlayerPos(playerid,1480.9805,-1770.7013,18.7958);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)