Guest User

Dchidell

a guest
Aug 28th, 2010
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.02 KB | None | 0 0
  1. #include <a_samp>
  2. #define CARSPAWND 21929
  3.  
  4. public OnFilterScriptInit()
  5. {
  6.     print("Vehicle Spawner loaded. Script by Andrus Riis(Mr Dzx)");
  7.     return 1;
  8. }
  9. //Removed OnFilterScriptExit - Wasn't being used
  10.  
  11. public OnPlayerCommandText(playerid, cmdtext[])
  12. {
  13.     //Removed "new cmd[128];" - No requirement for it
  14.     //Changed "cmd" to "cmdtext[1]", the "cmd" variable had been newly assigned, so would be null. String comparing to it would have failed as the string would have contained nothing.
  15.     //Changed the == 0 to ! as its evaluated slightly faster
  16.     if(!strcmp(cmdtext[1], "carspawn", true))
  17.     {
  18.         ShowPlayerDialog(playerid, CARSPAWND, DIALOG_STYLE_INPUT, "Car Spawner", "Please type in car model id you want to spawn.\n\nNB! For full list of car model ID's, please visit weedarr.com", "Spawn", "Cancel");
  19.         //This "return 1;" was missing from inside the code, OnPlayerCommandText has to return 0 to continue processing the commands in other scripts (i.e the gamemode).
  20.         return 1;
  21.     }
  22.     //Heres the return 0 you need.
  23.     return 0;
  24. }
  25.  
  26. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  27. {
  28.     //This switch case statement makes it easier to add more dialogs to the system for future expansion.
  29.     switch(dialogid)
  30.     {
  31.         case CARSPAWND:
  32.         {
  33.             if(response)
  34.             {
  35.                 //Moved the creation of new variables and functions inside the response check. No point doing all that work if its not going to be used!
  36.                 new Float:X,Float:Y,Float:Z,Float:A;
  37.                 new text = strval(inputtext); //Strval isn't really the best way to go, but it will do. sscanf is much better!
  38.                 GetPlayerPos(playerid,X,Y,Z);
  39.                 GetPlayerFacingAngle(playerid,A);
  40.                 if(text < 400 || text > 611)
  41.                 {
  42.                     return SendClientMessage(playerid, 0x00FF00FF, "Error: Invalid model ID.");
  43.                 }
  44.                 CreateVehicle(text, X,Y,Z+2,A, 126, 126, -1);
  45.                 return SendClientMessage(playerid, 0x00FF00FF, "Vehicle created successfully.");
  46.             }
  47.             else
  48.             {
  49.                 return SendClientMessage(playerid, 0x00FF00FF, "Selection canceled.");
  50.             }
  51.         }
  52.     }
  53.     return 1;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment