Remove player from vehicle after 7 seconds help
#1

As the title states, I am trying to find out if there is a simple script that will allow me to remove a player from vehicle after 7 seconds, meanwhile the player is uncontrollable. I've tried a SetTimer script with no effect. To be clear the action would be like this: The player is driving, another player turns off their vehicle (and toggles them uncontrollable for 7 seconds, enough time for the vehicle to stop). Then the 'other' player runs up and waits for the first player to exit (be removed from) their vehicle. Make sense?

EDIT:
I read over it again and it doesn't quite make sense. So here is the script with some comments:

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#define FILTERSCRIPT
#define BCars 751

#include <a_samp>

new BC;

/*main()
{
    print("\n ---------------------------------");
    print("  ¦        Gamemode Made By         ¦");
    print("  ¦             Karl..              ¦");
    print("  ¦                                 ¦");
    print("  ¦      DO NOT REMOVE CREDITS      ¦");
    print("  -----------------------------------");
    print("  ¦                                 ¦");
    print("  ¦  Available FilterscriptCommands ¦");
    print("  ¦           /player [id]          ¦");
    print("  ¦             /server             ¦");
    print("  ¦    /jail [id] [time] [Reason]   ¦");
    print("  ¦              /kick              ¦");
    print("  ¦               /ban              ¦");
    print("  ¦     -------------------------   ¦");
    print("  ¦         TelePort Commands:      ¦");
    print("  ¦            /telecmds            ¦");
    print("  ¦            /telemake            ¦");
    print("  ¦            /telechang           ¦");
    print("  ¦           /telecomment          ¦");
    print("  ¦           /teledelete           ¦");
    print("  ¦              /tele              ¦");
    print("  ¦            /telestats           ¦");
    print("  ¦            /telereset           ¦");
    print("  ¦           Set Teleports:        ¦");
    print("  ¦            /tele spawn          ¦");
    print("  ¦       /tele an <ammunation>     ¦");
    print("  ¦       /tele spawnl <Lookout>    ¦");
    print("  ¦       /tele pns <PaynSpray>     ¦");
    print("  ----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Roam/Cheat/Fun/Stunt");
    AddPlayerClass(21,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(19,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(28,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(30,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(47,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(48,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(50,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(66,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(67,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(86,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(100,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(102,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(103,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(104,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(105,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(106,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(107,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(108,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(109,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(110,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(114,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(115,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(116,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(149,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(173,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(174,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(175,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(176,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(177,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(271,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    AddPlayerClass(297,1106.3195,-1413.4640,13.5941,450.2402,0,0,0,0,0,0);
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 3117.61, -1088.85, 4.35);
    SetPlayerFacingAngle(playerid, 90);
    SetPlayerCameraPos(playerid, 3114.61, -1091.85, 3.8);
    SetPlayerCameraLookAt(playerid, 3117.61, -1088.85, 4.5);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, 0xFFEE00, "Welcome to the server! Hacks are optional! Speak ENGLISH Please! Choose a Skin!");
    SendClientMessage(playerid, 0xFFEE00, "DO NOT TROLL! It will result in a ban. This is a place for fun and not grief.");
    return 1;
}

public OnPlayerSpawn(playerid)
{
    GivePlayerWeapon(playerid, 46, 9999);
    GivePlayerWeapon(playerid, 9, 9999);
    GivePlayerWeapon(playerid, 22, 9999);
    GivePlayerWeapon(playerid, 24, 9999);
    GivePlayerWeapon(playerid, 25, 9999);
    GivePlayerWeapon(playerid, 28, 9999);
    GivePlayerWeapon(playerid, 29, 9999);
    GivePlayerWeapon(playerid, 31, 9999);
    GivePlayerWeapon(playerid, 34, 9999);
   
    SendClientMessage(playerid, 0xFFEE00, "Use /TL to see a list of Teles!");
    SendClientMessage(playerid, 0xFFEE00, "Use /UC for other Useful Commands!");
    SetPlayerPos(playerid, 3112, -1086.34, 9);
    SetCameraBehindPlayer(playerid);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/TL", true))
    {
        SendClientMessage(playerid, 0xFFEE00, "====================================================================");
        SendClientMessage(playerid, 0xFFEE00, "AVAILABLE TELES:  RS, ADD, SC, AA, SFI, URL, GP, LVA, LVS, LSA, SFA,");
        SendClientMessage(playerid, 0xFFEE00, "Type /tele <keyword> to Teleport!");
        SendClientMessage(playerid, 0xFFEE00, "Quick teles: /url, /url2, /gsr (DM)");
        return 1;
    }
     
    if(!strcmp(cmdtext, "/tl", true))
    {
        SendClientMessage(playerid, 0xFFEE00, "====================================================================");
        SendClientMessage(playerid, 0xFFEE00, "AVAILABLE TELES:  RS, ADD, SC, AA, SFI, URL, GP, LVA, LVS, LSA, SFA");
        SendClientMessage(playerid, 0xFFEE00, "Type /tele <keyword> to Teleport!");
        SendClientMessage(playerid, 0xFFEE00, "Quick teles: /url, /url2, /gsr (DM)");
        return 1;
    }

    if(!strcmp(cmdtext, "/UC", true))
    {
        SendClientMessage(playerid, 0xFFEE00, "====================================================================");
        SendClientMessage(playerid, 0xFFEE00, "Use /V to spawn a car!");
        SendClientMessage(playerid, 0xFFEE00, "Use /TUNE to customize your car! (Remember to press 'F' to leave menu)");
        SendClientMessage(playerid, 0xFFEE00, "Use /NEON to add neon!");
        SendClientMessage(playerid, 0xFFEE00, "Use /KILL to kill yourself if you ever need to!");
        SendClientMessage(playerid, 0xFFEE00, "Hint: In some of my own maps, I hid a {FFFFFF}White Nova {00FFFF}as an Easter Egg. Can you find them?");
        return 1;
    }
   
    if(!strcmp(cmdtext, "/uc", true))
    {
        SendClientMessage(playerid, 0xFFEE00, "====================================================================");
        SendClientMessage(playerid, 0xFFEE00, "Use /V to spawn a car!");
        SendClientMessage(playerid, 0xFFEE00, "Use /TUNE to customize your car! (Remember to press 'F' to leave menu)");
        SendClientMessage(playerid, 0xFFEE00, "Use /NEON to add neon!");
        SendClientMessage(playerid, 0xFFEE00, "Use /KILL to kill yourself if you ever need to!");
        SendClientMessage(playerid, 0xFFEE00, "Hint: In some of my own maps, I hid a {FFFFFF}White Nova {00FFFF}as an Easter Egg. Can you find them?");
        return 1;
    }
    if(strcmp(cmdtext,"/kill",true) == 0)
    {
        SetPlayerHealth(playerid, 0);
        SendClientMessage(playerid, 0xFFEE00, "You killed yourself.");
        return 1;
    }*/

    if (strcmp("/BC", cmdtext, true)==0)
    {
        DestroyVehicle(BC);
        ShowPlayerDialog(playerid, 751, DIALOG_STYLE_LIST, "Available Bait-Cars", "Huntley\nTurismo\nSultan\nBuffalo\nPatriot\nJetmax (boat)", "Select", "Cancel");
        return 1;
    }
    if (strcmp("/DIS", cmdtext, true)==0)
    {
        SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Disabled.");
        if (IsPlayerInVehicle(playerid,BC))  //I haven't really tested this on anyone else...would it still work?
        {
            SetVehicleParamsEx(BC, 0, 1, 0, 1, 0, 0, 0);
            TogglePlayerControllable(playerid, 0);
            RemovePlayerFromVehicle_Delayed(playerid, 7 //seconds);  //These are imaginary commands, but is there anything
            FreezePlayerExitedVehicle(playerid, 3 //seconds);     // that can achieve the same effect?
            TogglePlayerControllable(playerid, 1);
        }
        return 1;
    }
    return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new Float:x,Float:y,Float:z,Float:a;
    if(dialogid==751 &&response)
    {
        switch(listitem)
        {
            case 0:
            {
                SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Initiated, find a spot to park it.");
                SendClientMessage(playerid, 0xFFFF00FF , "Type /DIS to disable the Bait-Car's engine after a theif takes it.");
                GetPlayerFacingAngle(playerid,a);
                GetPlayerPos(playerid,x,y,z);
                BC=CreateVehicle(579, x, y, z,a, -1, -1, -1);
                PutPlayerInVehicle(playerid, BC, 0);
            }
            case 1:
            {
                SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Initiated, find a spot to park it.");
                SendClientMessage(playerid, 0xFFFF00FF , "Type /DIS to disable the Bait-Car's engine after a theif takes it.");
                GetPlayerFacingAngle(playerid,a);
                GetPlayerPos(playerid,x,y,z);
                BC=CreateVehicle(451, x, y, z,a, -1, -1, -1);
                PutPlayerInVehicle(playerid, BC, 0);
            }
            case 2:
            {
                SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Initiated, find a spot to park it.");
                SendClientMessage(playerid, 0xFFFF00FF , "Type /DIS to disable the Bait-Car's engine after a theif takes it.");
                GetPlayerFacingAngle(playerid,a);
                GetPlayerPos(playerid,x,y,z);
                BC=CreateVehicle(560, x, y, z,a, -1, -1, -1);
                PutPlayerInVehicle(playerid, BC, 0);
            }
            case 3:
            {
                SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Initiated, find a spot to park it.");
                SendClientMessage(playerid, 0xFFFF00FF , "Type /DIS to disable the Bait-Car's engine after a theif takes it.");
                GetPlayerPos(playerid,x,y,z);
                GetPlayerFacingAngle(playerid,a);
                BC=CreateVehicle(402, x, y, z,a, -1, -1, -1);
                PutPlayerInVehicle(playerid, BC, 0);
            }
            case 4:
            {
                SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Initiated, find a spot to park it.");
                SendClientMessage(playerid, 0xFFFF00FF , "Type /DIS to disable the Bait-Car's engine after a theif takes it.");
                GetPlayerPos(playerid,x,y,z);
                GetPlayerFacingAngle(playerid,a);
                BC=CreateVehicle(470, x, y, z,a, -1, -1, -1);
                PutPlayerInVehicle(playerid, BC, 0);
            }
            case 5:
            {
                SendClientMessage(playerid, 0xFFFF00FF , "Bait-Car Initiated, find a spot to park it.");
                SendClientMessage(playerid, 0xFFFF00FF , "Type /DIS to disable the Bait-Car's engine after a theif takes it.");
                GetPlayerPos(playerid,x,y,z);
                GetPlayerFacingAngle(playerid,a);
                BC=CreateVehicle(493, x, y, z,a, -1, -1, -1);
                PutPlayerInVehicle(playerid, BC, 0);
            }
        }
        return 1;
    }
    return 0;
}
Reply
#2

pawn Код:
SetTimerEx("RemovePlayerFromVehicle_Delayed", 7 * 1000, false, "i", playerid);
pawn Код:
RemovePlayerFromVehicle_Delayed(playerid); public RemovePlayerFromVehicle_Delayed(playerid) {
    if(IsPlayerInAnyVehicle(playerid)) {
        RemovePlayerFromVehicle(playerid);
    }
}
Reply
#3

Okay, I get what you need.
If im not right correct me.
I've made you a command /ejectfomcar [playerid/PartOfName] with sscanf

You need to stock this:
pawn Код:
stock sscanf(string[], format[], {Float,_}:...)
{
 new name[MAX_PLAYER_NAME];
 #if defined isnull
  if (isnull(string))
 #else
  if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
 #endif
  {
   return format[0];
  }
 #pragma tabsize 4
 new
  formatPos = 0,
  stringPos = 0,
  paramPos = 2,
  paramCount = numargs(),
  delim = ' ';
 while (string[stringPos] && string[stringPos] <= ' ')
 {
  stringPos++;
 }
 while (paramPos < paramCount && string[stringPos])
 {
  switch (format[formatPos++])
  {
   case '\0':
   {
    return 0;
   }
   case 'i', 'd':
   {
    new
     neg = 1,
     num = 0,
     ch = string[stringPos];
    if (ch == '-')
    {
     neg = -1;
     ch = string[++stringPos];
    }
    do
    {
     stringPos++;
     if ('0' <= ch <= '9')
     {
      num = (num * 10) + (ch - '0');
     }
     else
     {
      return -1;
     }
    }
    while ((ch = string[stringPos]) > ' ' && ch != delim);
    setarg(paramPos, 0, num * neg);
   }
   case 'h', 'x':
   {
    new
     num = 0,
     ch = string[stringPos];
    do
    {
     stringPos++;
     switch (ch)
     {
      case 'x', 'X':
      {
       num = 0;
       continue;
      }
      case '0' .. '9':
      {
       num = (num << 4) | (ch - '0');
      }
      case 'a' .. 'f':
      {
       num = (num << 4) | (ch - ('a' - 10));
      }
      case 'A' .. 'F':
      {
       num = (num << 4) | (ch - ('A' - 10));
      }
      default:
      {
       return -1;
      }
     }
    }
    while ((ch = string[stringPos]) > ' ' && ch != delim);
    setarg(paramPos, 0, num);
   }
   case 'c':
   {
    setarg(paramPos, 0, string[stringPos++]);
   }
   case 'f':
   {
    setarg(paramPos, 0, _:floatstr(string[stringPos]));
   }
   case 'p':
   {
    delim = format[formatPos++];
    continue;
   }
   case '\'':
   {
    new
     end = formatPos - 1,
     ch;
    while ((ch = format[++end]) && ch != '\'') {}
    if (!ch)
    {
     return -1;
    }
    format[end] = '\0';
    if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
    {
     if (format[end + 1])
     {
      return -1;
     }
     return 0;
    }
    format[end] = '\'';
    stringPos = ch + (end - formatPos);
    formatPos = end + 1;
   }
   case 'u':
   {
    new
     end = stringPos - 1,
     id = 0,
     bool:num = true,
     ch;
    while ((ch = string[++end]) && ch != delim)
    {
     if (num)
     {
      if ('0' <= ch <= '9')
      {
       id = (id * 10) + (ch - '0');
      }
      else
      {
       num = false;
      }
     }
    }
    if (num && IsPlayerConnected(id))
    {
     setarg(paramPos, 0, id);
    }
    else
    {
     #if !defined foreach
      #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
      #define __SSCANF_FOREACH__
     #endif
     string[end] = '\0';
     num = false;
     id = end - stringPos;
     foreach (Player, playerid)
     {
      GetPlayerName(playerid, name, sizeof (name));
      if (!strcmp(name, string[stringPos], true, id))
      {
       setarg(paramPos, 0, playerid);
       num = true;
       break;
      }
     }
     if (!num)
     {
      setarg(paramPos, 0, INVALID_PLAYER_ID);
     }
     string[end] = ch;
     #if defined __SSCANF_FOREACH__
      #undef foreach
      #undef __SSCANF_FOREACH__
     #endif
    }
    stringPos = end;
   }
   case 's', 'z':
   {
    new
     i = 0,
     ch;
    if (format[formatPos])
    {
     while ((ch = string[stringPos++]) && ch != delim)
     {
      setarg(paramPos, i++, ch);
     }
     if (!i)
     {
      return -1;
     }
    }
    else
    {
     while ((ch = string[stringPos++]))
     {
      setarg(paramPos, i++, ch);
     }
    }
    stringPos--;
    setarg(paramPos, i, '\0');
   }
   default:
   {
    continue;
   }
  }
  while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  {
   stringPos++;
  }
  while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  {
   stringPos++;
  }
  paramPos++;
 }
 do
 {
  if ((delim = format[formatPos++]) > ' ')
  {
   if (delim == '\'')
   {
    while ((delim = format[formatPos++]) && delim != '\'') {}
   }
   else if (delim != 'z')
   {
    return delim;
   }
  }
 }
 while (delim > ' ');
 return 0;
}
then you need to make the command
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

    new cmd[30], params[30];
    sscanf(cmdtext, "ss", cmd, params);
    if(!strcmp(cmd, "/ejectfromcar"))
    {
        new player;
        new string[128];
        new name[MAX_PLAYER_NAME+1];
        GetPlayerName(player, name, sizeof(name));
        if(sscanf(params,"u",player)) return SendClientMessage(playerid,0xAFAFAFAA,"USAGE: /ejectfomcar [playerid/PartOfName]");
        else if(!IsPlayerConnected(player))return SendClientMessage(playerid,0xAFAFAFAA, "Invalid Player ID/Name");
        else
        {
            if(IsPlayerInAnyVehicle(player))
            {
                    format(string, sizeof(string), "You've ejected %s from the vehicle.", name);
                    SendClientMessage(playerid, 0x33CCFFAA, string);
                    TogglePlayerControllable(player, 0);
                    SetTimerEx("removefromcar", 1000, false, "i", player);
            }
            else return SendClientMessage(playerid,0xAFAFAFAA,"This player is not in vehicle");
        }
        return 1;
    }
    return 0;
}
I've setted timer to 1 second because when player is frozen vehicle stops almost imediatly
and here is the function that ejects player and makes him able to move again
pawn Код:
forward removefromcar(player, playerid);
public removefromcar(player, playerid)
{
    new string[128];
    new name[MAX_PLAYER_NAME+1];
    TogglePlayerControllable(player, 1);
    GetPlayerName(playerid, name, sizeof(name));
    RemovePlayerFromVehicle(player);
    format(string, sizeof(string), "%s has ejected you from the vehicle.", name);
    SendClientMessage(player, 0x33CCFFAA, string);
}
Hope that helped you and you didn't just copy it over.

If you want to test it and you have nobody to test with you can /ejectfromcar yourself too
Reply
#4

@Zigonja: Why would you use the old sscanf? Update to the plugin, which works a lot better and has more features.
Reply
#5

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
@Zigonja: Why would you use the old sscanf? Update to the plugin, which works a lot better and has more features.
I presonally don't use it, but if he doesn't have the include, and for command that simple it's okay.
Reply
#6

EDITED the topic
Reply
#7

Umm not really, there is no timer to be set. Why don't you use that I've sent you and just edit it so you like it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)