pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C++ pastebin - collaborative debugging tool View Help


Posted by zeruel_angel on Wed 27 Feb 18:48 (modification of post by view diff)
report abuse | View followups from jessica, Anonymous, asdw and daeesdasdsssssssssssss | download | new post

  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]={-1,...};
  20. new ownedcar[MAX_PLAYERS]={-1,...};
  21. new lockedCar[MAX_VEHICLES]={-1,...};
  22. new wasInVehicle[MAX_PLAYERS]={-1,...};
  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,"AYUDA: usa /carhelp para conocer los comandos de los autos");
  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,"Comandos disponibles:");
  70.             SendClientMessage(playerid, COLOR_YELLOW,"/traba, /destraba, /ComprarCoche, /VenderCoche, /LlamarCoche, /eject, /ejectall");
  71.             return 1;
  72.             }
  73.  
  74.         if      (strcmp(cmdtext, "/traba", true)==0)
  75.         {
  76.         if      (IsPlayerInAnyVehicle(playerid))
  77.                 {
  78.             new State=GetPlayerState(playerid);
  79.             if  (State!=PLAYER_STATE_DRIVER)
  80.                 {
  81.                 SendClientMessage(playerid,0xFFFF00AA,"Solo el conductor puede trabar las puertas");
  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, "Vehiculo cerrado!");
  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, "No estas en un vehiculo!");
  101.             }
  102.         return 1;
  103.         }
  104.  
  105.     if  (strcmp(cmdtext, "/destraba", true)==0)
  106.         {
  107.         if      (IsPlayerInAnyVehicle(playerid))
  108.             {
  109.             new State=GetPlayerState(playerid);
  110.             if  (State!=PLAYER_STATE_DRIVER)
  111.                 {
  112.                 SendClientMessage(playerid,0xFFFF00AA,"Solo el conductor puede destrabar las puertas");
  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, "Vehiculo destrabado!");
  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, "No estas en un vehiculo!");
  129.             }
  130.         return 1;
  131.         }
  132.     if  (strcmp(cmdtext, "/ComprarCoche", 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,"No tienes suficiente dinero para comprar un auto");
  137.             return 1;
  138.             }
  139.         if  (!(IsPlayerInAnyVehicle(playerid)))
  140.             {
  141.             SendClientMessage(playerid,COLOR_YELLOW,"No estas en un vehiculo!.");
  142.             return 1;
  143.             }
  144.         if  (owner[GetPlayerVehicleID(playerid)]!=-1)
  145.             {
  146.             SendClientMessage(playerid,COLOR_YELLOW,"Este vehiculo ya tiene dueño");
  147.             return 1;
  148.             }
  149.         if  (ownedcar[playerid]!=-1)
  150.             {
  151.             SendClientMessage(playerid,COLOR_YELLOW,"Ya tienes un vehiculo, usa /venderCoche si lo quieres vender para comprar este");
  152.             return 1;
  153.             }
  154.         ownedcar[playerid] = GetPlayerVehicleID(playerid);
  155.         owner[ownedcar[playerid]] = playerid;
  156.         SendClientMessage(playerid,COLOR_YELLOW,"FELICITACIONES! has comprado un vehiculo");
  157.         GivePlayerMoney(playerid,-CAR_COST);
  158.         return 1;
  159.         }
  160.     if  (strcmp(cmdtext, "/VenderCoche", true)==0)
  161.         {
  162.         if  (ownedcar[playerid]==-1)
  163.             {
  164.             SendClientMessage(playerid,COLOR_YELLOW,"NO posees ningun vehiculo...");
  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,"Has vendido tu vehiculo, recuperas la mitad de tu dinero");
  178.         GivePlayerMoney(playerid,CAR_COST/2);
  179.         return 1;
  180.         }
  181.     if  (strcmp(cmdtext, "/LlamarCoche", true)==0)
  182.         {
  183.         if      (ownedcar[playerid] != -1)
  184.             {
  185.             if  (GetPlayerMoney(playerid) < 1000)
  186.                 {
  187.                 SendClientMessage(playerid,COLOR_YELLOW,"Lo sentimos mucho, pero no tienes dinero suficiente para ese servicio.");
  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,"Gracias por usar nuestro servicio, aqui esta tu coche.");
  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,"No estas en un vehiculo");
  210.                         return 1;
  211.                         }
  212.                 if      (playerstate == PLAYER_STATE_PASSENGER)
  213.                         {
  214.                         SendClientMessage(playerid,COLOR_RED,"Los pasajeros no pueden usar este comando!");
  215.                         return 1;
  216.                         }
  217.                 vehicleid = GetPlayerVehicleID(playerid);
  218.                 if      (!strlen(tmp))
  219.                         {
  220.                         SendClientMessage(playerid,COLOR_WHITE,"USo: /eject [playerid]");
  221.                         return 1;
  222.                         }
  223.                 pid = strval(tmp);
  224.                 if      ((!IsPlayerConnected(pid))||(!IsPlayerInVehicle(pid,vehicleid)))
  225.                         {
  226.                         SendClientMessage(playerid,COLOR_RED,"Ese jugador no esta en tu vehiculo.");
  227.                         return 1;
  228.                         }
  229.                 else
  230.                         {
  231.                         RemovePlayerFromVehicle(pid);
  232.                         GameTextForPlayer(pid,"~w~Te han ~r~TIRADO ~w~ del vehiculo!!",3000,5);
  233.                         return 1;
  234.                         }
  235.                 }
  236.     if  (strcmp(cmd,"/ejectall", true)==0){
  237.                 new vehicleid;
  238.                 new playerstate = GetPlayerState(playerid);
  239.                 if      (!IsPlayerInAnyVehicle(playerid))
  240.                         {
  241.                         SendClientMessage(playerid,COLOR_YELLOW,"No estas en un vehiculo");
  242.                         return 1;
  243.                         }
  244.                 if      (playerstate == PLAYER_STATE_PASSENGER)
  245.                         {
  246.                         SendClientMessage(playerid,COLOR_RED,"Los pasajeros no pueden usar este comando!");
  247.                         return 1;
  248.                         }
  249.                 vehicleid = GetPlayerVehicleID(playerid);
  250.                 for (new i=0;i<MAX_PLAYERS;i++)
  251.                     {
  252.                         if      ((IsPlayerConnected(i))&&(IsPlayerInVehicle(i,vehicleid)))
  253.                                 {
  254.                                 RemovePlayerFromVehicle(i);
  255.                                 GameTextForPlayer(i,"~w~Te han ~r~TIRADO ~w~ del vehiculo!!",3000,5);
  256.                                 return 1;
  257.                                 }
  258.                         }
  259.                 }
  260.     return 0;
  261.     }
  262. //------------------------------------------------------------------------------
  263. public OnPlayerStateChange(playerid, newstate, oldstate)
  264.         {
  265.         if      (newstate==PLAYER_STATE_DRIVER)
  266.             {
  267.                 wasInVehicle[playerid]=GetPlayerVehicleID(playerid);
  268.                 if      ((owner[GetPlayerVehicleID(playerid)]!=-1)&&(owner[GetPlayerVehicleID(playerid)]!=playerid))
  269.                     {
  270.                     new name[MAX_PLAYER_NAME];
  271.                     new msg[256];
  272.                     GetPlayerName(owner[GetPlayerVehicleID(playerid)],name,sizeof(name));
  273.                     format(msg,sizeof(msg),"Este vehiculo pertenece a: %s",name);
  274.                     }
  275.             }
  276.         if      (newstate==PLAYER_STATE_PASSENGER)
  277.                 {
  278.                 if      ((owner[GetPlayerVehicleID(playerid)]!=-1)&&(owner[GetPlayerVehicleID(playerid)]!=playerid))
  279.                     {
  280.                     new name[MAX_PLAYER_NAME];
  281.                     new msg[256];
  282.                     GetPlayerName(owner[GetPlayerVehicleID(playerid)],name,sizeof(name));
  283.                     format(msg,sizeof(msg),"Este vehiculo pertenece a: %s",name);
  284.                     SendClientMessage(playerid,COLOR_YELLOW,msg);
  285.                     }
  286.                 }
  287.         if      (newstate==PLAYER_STATE_ONFOOT)
  288.             {
  289.             if  ((wasInVehicle[playerid]!=ownedcar[playerid])&&(lockedCar[wasInVehicle[playerid]]==1))
  290.                 {
  291.             lockedCar[GetPlayerVehicleID(playerid)]=0;
  292.             for (new i=0;i<MAX_PLAYERS;i++)
  293.                 {
  294.                 SetVehicleParamsForPlayer(ownedcar[playerid],i, 0, 0);
  295.                 }
  296.             SendClientMessage(playerid, 0xFFFF00AA, "Vehicle destrabado!");
  297.             new Float:pX, Float:pY, Float:pZ;
  298.             GetPlayerPos(playerid,pX,pY,pZ);
  299.             PlayerPlaySound(playerid,1057,pX,pY,pZ);
  300.                 }
  301.             }
  302.         return 1;
  303.         }
  304. //------------------------------------------------------------------------------
  305. public OnPlayerDisconnect(playerid, reason)
  306.         {
  307.         if      ((ownedcar[playerid]!=-1)&&(lockedCar[ownedcar[playerid]]=1))
  308.             {
  309.             lockedCar[ownedcar[playerid]]=0;
  310.         for     (new i=0;i<MAX_PLAYERS;i++)
  311.             {
  312.             SetVehicleParamsForPlayer(ownedcar[playerid],i, 0, 0);
  313.             }
  314.             }
  315.         if      (ownedcar[playerid]!=-1)
  316.             {
  317.         owner[ownedcar[playerid]]=-1;
  318.         ownedcar[playerid]=-1;
  319.         }
  320.     wasInVehicle[playerid]=-1;
  321.         return 1;
  322.         }
  323.  
  324. //------------------------------------------------------------------------------
  325.  strtok(const string[], &index)
  326. {
  327.         new length = strlen(string);
  328.         while ((index < length) && (string[index] <= ' '))
  329.         {
  330.                 index++;
  331.         }
  332.  
  333.         new offset = index;
  334.         new result[20];
  335.         while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  336.         {
  337.                 result[index - offset] = string[index];
  338.                 index++;
  339.         }
  340.         result[index - offset] = EOS;
  341.         return result;
  342. }
  343. //------------------------------------------------------------------------------

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post