Recent Posts
None | 17 sec ago
C++ | 17 sec ago
Python | 26 sec ago
C | 34 sec ago
None | 48 sec ago
C# | 57 sec ago
VB.NET | 59 sec ago
PHP | 1 min ago
None | 1 min ago
ASM (NASM) | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Chriss on the 19th of Sep 2008 01:06:42 PM Download | Raw | Embed | Report
  1. //------------------------------------------------------------------------------
  2. // Simple car commands FilterScritp
  3. // packed indented and adapted by zeruel_angel
  4. // CREDITS TO
  5. // pekay http://forum.sa-mp.com/index.php?topic=26414.0
  6. // Allan (/lock /unlock and strtok) http://forum.sa-mp.com/index.php?topic=2868.msg18858#msg18858
  7. // Joshua Yu (/purchase and /callmycar) http://forum.sa-mp.com/index.php?topic=2868.msg22605#msg22605
  8. // Alfredk (/eject) http://forum.sa-mp.com/index.php?topic=26402
  9. //------------------------------------------------------------------------------
  10.  
  11. #include <a_samp>
  12.  
  13. #define COLOR_GREEN 0x33AA33AA
  14. #define COLOR_YELLOW 0xFFFF00AA
  15. #define COLOR_RED 0xAA3333AA
  16. #define COLOR_WHITE 0xFFFFFFAA
  17. #define CAR_COST 50000
  18.  
  19. new owner[MAX_VEHICLES];
  20. new ownedcar[MAX_PLAYERS];
  21. new lockedCar[MAX_VEHICLES];
  22. new wasInVehicle[MAX_PLAYERS];
  23.  
  24. //------------------------------------------------------------------------------
  25. public OnFilterScriptInit()
  26.         {
  27.         print(" ");
  28.         print(" ---------------------------------- ");
  29.         print("     Car Commands Filterscript      ");
  30.         print("    Packed indented and adapted     ");
  31.                 print("         by zeruel_angel            ");
  32.                 print("            Credits to:             ");
  33.                 print("  pekay, Allan, Joshua Yu, Alfredk  ");
  34.         print(" ---------------------------------- ");
  35.         print(" ");
  36.         for (new i=0;i<MAX_PLAYERS;i++)
  37.             {
  38.             ownedcar[i]=-1;
  39.             wasInVehicle[i]=-1;
  40.             }
  41.         for (new i=0;i<MAX_VEHICLES;i++)
  42.             {
  43.             owner[i]=-1;
  44.             lockedCar[i]=0;
  45.             }
  46.         }
  47. //------------------------------------------------------------------------------
  48. public OnPlayerConnect(playerid)
  49.         {
  50.         SendClientMessage(playerid,COLOR_YELLOW,"Car Help Here /carhelp");
  51.         for (new i=0;i<700;i++)
  52.             {
  53.             if  (lockedCar[i]==1)
  54.                 {
  55.                 SetVehicleParamsForPlayer( i, playerid, 0, 1);
  56.                 }
  57.             }
  58.         }
  59. //------------------------------------------------------------------------------
  60. public OnPlayerCommandText(playerid, cmdtext[])
  61.         {
  62.         new idx;
  63.         new cmd[255];
  64.         new tmp[255];
  65.         cmd = strtok(cmdtext,idx);
  66.        
  67.         if  (strcmp(cmdtext, "/carhelp", true)==0)
  68.             {
  69.             SendClientMessage(playerid, COLOR_GREEN,"Available commands:");
  70.             SendClientMessage(playerid, COLOR_YELLOW,"/lock, /unlock, /purchase, /sellmycar, /callmycar, /eject, /ejectall");
  71.             return 1;
  72.             }
  73.  
  74.         if      (strcmp(cmdtext, "/lock", true)==0)
  75.         {
  76.         if      (IsPlayerInAnyVehicle(playerid))
  77.                 {
  78.             new State=GetPlayerState(playerid);
  79.             if  (State!=PLAYER_STATE_DRIVER)
  80.                 {
  81.                 SendClientMessage(playerid,0xFFFF00AA,"You can only lock the doors as the driver.");
  82.                 return 1;
  83.                 }
  84.             lockedCar[GetPlayerVehicleID(playerid)]=1;
  85.             new i;
  86.                 for (i=0;i<MAX_PLAYERS;i++)
  87.                     {
  88.                         if(i != playerid)
  89.                         {
  90.                         SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
  91.                         }
  92.                     }
  93.                 SendClientMessage(playerid, 0xFFFF00AA, "Vehicle locked!");
  94.                 new Float:pX, Float:pY, Float:pZ;
  95.                 GetPlayerPos(playerid,pX,pY,pZ);
  96.                 PlayerPlaySound(playerid,1056,pX,pY,pZ);
  97.                 }
  98.         else
  99.             {
  100.             SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
  101.             }
  102.         return 1;
  103.         }
  104.  
  105.     if  (strcmp(cmdtext, "/unlock", true)==0)
  106.         {
  107.         if      (IsPlayerInAnyVehicle(playerid))
  108.             {
  109.             new State=GetPlayerState(playerid);
  110.             if  (State!=PLAYER_STATE_DRIVER)
  111.                 {
  112.                 SendClientMessage(playerid,0xFFFF00AA,"You can only unlock the doors as the driver.");
  113.                 return 1;
  114.                 }
  115.             new i;
  116.             lockedCar[GetPlayerVehicleID(playerid)]=0;
  117.             for (i=0;i<MAX_PLAYERS;i++)
  118.                 {
  119.                 SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
  120.                 }
  121.             SendClientMessage(playerid, 0xFFFF00AA, "Vehicle unlocked!");
  122.             new Float:pX, Float:pY, Float:pZ;
  123.             GetPlayerPos(playerid,pX,pY,pZ);
  124.             PlayerPlaySound(playerid,1057,pX,pY,pZ);
  125.             }
  126.         else
  127.             {
  128.             SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
  129.             }
  130.         return 1;
  131.         }
  132.     if  (strcmp(cmdtext, "/purchase", true)==0) // to set the vehicle that you register to be teleported
  133.         {
  134.         if (GetPlayerMoney(playerid) < CAR_COST)
  135.             {
  136.             SendClientMessage(playerid,COLOR_YELLOW,"Sorry, you don't have enough money to buy a car.");
  137.             return 1;
  138.             }
  139.         if  (!(IsPlayerInAnyVehicle(playerid)))
  140.             {
  141.             SendClientMessage(playerid,COLOR_YELLOW,"Please get in a vehicle to buy it.");
  142.             return 1;
  143.             }
  144.         if  (owner[GetPlayerVehicleID(playerid)]!=-1)
  145.             {
  146.             SendClientMessage(playerid,COLOR_YELLOW,"This car already have an owner");
  147.             return 1;
  148.             }
  149.         if  (ownedcar[playerid]!=-1)
  150.             {
  151.             SendClientMessage(playerid,COLOR_YELLOW,"You already have a car, use /sellmycar to sell it in any moment.");
  152.             return 1;
  153.             }
  154.         ownedcar[playerid] = GetPlayerVehicleID(playerid);
  155.         owner[ownedcar[playerid]] = playerid;
  156.         SendClientMessage(playerid,COLOR_YELLOW,"Congragulations! You have purchased a new car.");
  157.         GivePlayerMoney(playerid,-CAR_COST);
  158.         return 1;
  159.         }
  160.     if  (strcmp(cmdtext, "/sellmycar", true)==0)
  161.         {
  162.         if  (ownedcar[playerid]==-1)
  163.             {
  164.             SendClientMessage(playerid,COLOR_YELLOW,"You don't have any car...");
  165.             return 1;
  166.             }
  167.                 if      (lockedCar[ownedcar[playerid]]==1)
  168.                     {
  169.                     lockedCar[ownedcar[playerid]]=0;
  170.                 for     (new i=0;i<MAX_PLAYERS;i++)
  171.                     {
  172.                     SetVehicleParamsForPlayer(ownedcar[playerid],i, 0, 0);
  173.                     }
  174.                     }
  175.         owner[ownedcar[playerid]] = -1;
  176.         ownedcar[playerid] = -1;
  177.         SendClientMessage(playerid,COLOR_YELLOW,"You have sold your car, you get back half of your money");
  178.         GivePlayerMoney(playerid,CAR_COST/2);
  179.         return 1;
  180.         }
  181.     if  (strcmp(cmdtext, "/callmycar", true)==0)
  182.         {
  183.         if      (ownedcar[playerid] != -1)
  184.             {
  185.             if  (GetPlayerMoney(playerid) < 1000)
  186.                 {
  187.                 SendClientMessage(playerid,COLOR_YELLOW,"Sorry, you don't have enough money to use the car teleport service.");
  188.                 }
  189.              else
  190.                 {
  191.                 new Float:playerpos[4];
  192.                 GetPlayerPos(playerid,playerpos[0],playerpos[1],playerpos[2]);
  193.                 GetPlayerFacingAngle(playerid,playerpos[3]);
  194.                 SetVehicleZAngle(ownedcar[playerid],playerpos[3]+90.0);
  195.                 SetVehiclePos(ownedcar[playerid],playerpos[0]+3.0*floatsin(-playerpos[3],degrees),playerpos[1]+3.0*floatcos(-playerpos[3],degrees),playerpos[2]+0.5); // This one is cool that I am using trigo functions to set the vehicle just before you.
  196.                 SendClientMessage(playerid,COLOR_YELLOW,"Thank you for using car teleport service. Your car has came.");
  197.                 GivePlayerMoney(playerid,-1000);
  198.                 }
  199.             }
  200.         }
  201.  
  202.     if  (strcmp(cmd,"/eject", true)==0){
  203.                 new vehicleid;
  204.                 new pid;
  205.                 new playerstate = GetPlayerState(playerid);
  206.                 tmp = strtok(cmdtext,idx);
  207.                 if      (!IsPlayerInAnyVehicle(playerid))
  208.                         {
  209.                         SendClientMessage(playerid,COLOR_YELLOW,"You're not in a vehicle");
  210.                         return 1;
  211.                         }
  212.                 if      (playerstate == PLAYER_STATE_PASSENGER)
  213.                         {
  214.                         SendClientMessage(playerid,COLOR_RED,"Passengers can't use This!");
  215.                         return 1;
  216.                         }
  217.                 vehicleid = GetPlayerVehicleID(playerid);
  218.                 if      (!strlen(tmp))
  219.                         {
  220.                         SendClientMessage(playerid,COLOR_WHITE,"USAGE: /eject [playerid]");
  221.                         return 1;
  222.                         }
  223.                 pid = strval(tmp);
  224.                 if      (!IsPlayerConnected(pid))
  225.                         {
  226.                         SendClientMessage(playerid,COLOR_RED,"That Player Is Not Connected...");
  227.                         return 1;
  228.                         }
  229.                 if      (!IsPlayerInVehicle(pid,vehicleid))
  230.                         {
  231.                         SendClientMessage(playerid,COLOR_RED,"That Player Is Not In Your Vehicle...");
  232.                         return 1;
  233.                         }
  234.                 else
  235.                         {
  236.                         RemovePlayerFromVehicle(pid);
  237.                         GameTextForPlayer(pid,"~r~YOU'VE BEEN EJECTED!",3000,5);
  238.                         return 1;
  239.                         }
  240.                 }
  241.     if  (strcmp(cmd,"/ejectall", true)==0){
  242.                 new vehicleid;
  243.                 new playerstate = GetPlayerState(playerid);
  244.                 if      (!IsPlayerInAnyVehicle(playerid))
  245.                         {
  246.                         SendClientMessage(playerid,COLOR_YELLOW,"You're not in a vehicle");
  247.                         return 1;
  248.                         }
  249.                 if      (playerstate == PLAYER_STATE_PASSENGER)
  250.                         {
  251.                         SendClientMessage(playerid,COLOR_RED,"Passengers can't use This!");
  252.                         return 1;
  253.                         }
  254.                 vehicleid = GetPlayerVehicleID(playerid);
  255.                 for (new i=0;i<MAX_PLAYERS;i++)
  256.                     {
  257.                         if      ((IsPlayerConnected(i))&&(IsPlayerInVehicle(i,vehicleid)))
  258.                                 {
  259.                                 RemovePlayerFromVehicle(i);
  260.                                 GameTextForPlayer(i,"~r~YOU'VE BEEN EJECTED!",3000,5);
  261.                                 return 1;
  262.                                 }
  263.                         }
  264.                 }
  265.     return 0;
  266.     }
  267. //------------------------------------------------------------------------------
  268. public OnPlayerStateChange(playerid, newstate, oldstate)
  269.         {
  270.         if      (newstate==PLAYER_STATE_DRIVER)
  271.             {
  272.                 wasInVehicle[playerid]=GetPlayerVehicleID(playerid);
  273.                 if      ((owner[GetPlayerVehicleID(playerid)]!=-1)&&(owner[GetPlayerVehicleID(playerid)]!=playerid))
  274.                     {
  275.                     new name[MAX_PLAYER_NAME];
  276.                     new msg[256];
  277.                     GetPlayerName(owner[GetPlayerVehicleID(playerid)],name,sizeof(name));
  278.                     format(msg,sizeof(msg),"This vehicle belongs to: %s",name);
  279.                     }
  280.             }
  281.         if      (newstate==PLAYER_STATE_PASSENGER)
  282.                 {
  283.                 if      ((owner[GetPlayerVehicleID(playerid)]!=-1)&&(owner[GetPlayerVehicleID(playerid)]!=playerid))
  284.                     {
  285.                     new name[MAX_PLAYER_NAME];
  286.                     new msg[256];
  287.                     GetPlayerName(owner[GetPlayerVehicleID(playerid)],name,sizeof(name));
  288.                     format(msg,sizeof(msg),"This vehicle belongs to: %s",name);
  289.                     SendClientMessage(playerid,COLOR_YELLOW,msg);
  290.                     }
  291.                 }
  292.         if      (newstate==PLAYER_STATE_ONFOOT)
  293.             {
  294.             if  ((wasInVehicle[playerid]!=ownedcar[playerid])&&(lockedCar[wasInVehicle[playerid]]==1))
  295.                 {
  296.             lockedCar[GetPlayerVehicleID(playerid)]=0;
  297.             for (new i=0;i<MAX_PLAYERS;i++)
  298.                 {
  299.                 SetVehicleParamsForPlayer(ownedcar[playerid],i, 0, 0);
  300.                 }
  301.             SendClientMessage(playerid, 0xFFFF00AA, "Vehicle unlocked!");
  302.             new Float:pX, Float:pY, Float:pZ;
  303.             GetPlayerPos(playerid,pX,pY,pZ);
  304.             PlayerPlaySound(playerid,1057,pX,pY,pZ);
  305.                 }
  306.             }
  307.         return 1;
  308.         }
  309. //------------------------------------------------------------------------------
  310. public OnPlayerDisconnect(playerid, reason)
  311.         {
  312.         if      ((ownedcar[playerid]!=-1)&&(lockedCar[ownedcar[playerid]]=1))
  313.             {
  314.             lockedCar[ownedcar[playerid]]=0;
  315.         for     (new i=0;i<MAX_PLAYERS;i++)
  316.             {
  317.             SetVehicleParamsForPlayer(ownedcar[playerid],i, 0, 0);
  318.             }
  319.             }
  320.         if      (ownedcar[playerid]!=-1)
  321.             {
  322.         owner[ownedcar[playerid]]=-1;
  323.         ownedcar[playerid]=-1;
  324.         }
  325.     wasInVehicle[playerid]=-1;
  326.         return 1;
  327.         }
  328.  
  329. //------------------------------------------------------------------------------
  330.  strtok(const string[], &index)
  331. {
  332.         new length = strlen(string);
  333.         while ((index < length) && (string[index] <= ' '))
  334.         {
  335.                 index++;
  336.         }
  337.  
  338.         new offset = index;
  339.         new result[20];
  340.         while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  341.         {
  342.                 result[index - offset] = string[index];
  343.                 index++;
  344.         }
  345.         result[index - offset] = EOS;
  346.         return result;
  347. }
  348. //------------------------------------------------------------------------------
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: