Guest User

Untitled

a guest
Aug 5th, 2010
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.68 KB | None | 0 0
  1. //-------------------------------------------------------
  2. //
  3. // GRAND LARCENY Property creation and management script
  4. //
  5. // by damospiderman 2008
  6. //
  7. //-------------------------------------------------------
  8.  
  9. #include <a_samp>
  10. #include "../include/gl_common.inc"
  11.  
  12. #define FILTERSCRIPT
  13. //#define USE_SQLITE
  14.  
  15. #define PROP_VW         (10000)
  16. #define MAX_INTERIORS   (146)
  17. #define MAX_PROPERTIES  (1000)
  18.  
  19. #define PROPERTY_FOLDER "properties" // Location of properties file
  20. #define PROPERTY_UNIQID_FILE    "properties/uniqId.txt" // Location of Uniq Interior Info
  21. #define DB_PROPERTIES   "properties/dbProperties.db" // Location of the properties Database
  22.  
  23. #define MAX_TYPES       (5)
  24. #define TYPE_EMPTY      (0)
  25. #define TYPE_HOUSE      (1)
  26. #define TYPE_BUSINESS   (2)
  27. #define TYPE_BANK       (3)
  28. #define TYPE_COP        (4)
  29.  
  30. enum // Property Type Enum
  31.     E_P_TYPES {
  32.         tIcon,
  33.         tName[32]
  34.     }
  35.  
  36. enum // Uniq Interiors Enum
  37.     E_INTERIORS {
  38.         inIntID,
  39.         Float:inExitX,
  40.         Float:inExitY,
  41.         Float:inExitZ,
  42.         Float:inExitA,
  43.         inName[64]
  44.     };
  45.  
  46. enum // Properties Enum
  47.     E_PROPERTIES {
  48.         eInterior,
  49.         eType,
  50.         Float:eEntX,
  51.         Float:eEntY,
  52.         Float:eEntZ,
  53.         Float:eEntA,
  54.         eUniqIntId,
  55.         eOwner,
  56.         ePrice,
  57.         ePname[64]
  58.     };
  59.  
  60. //  [ uniq property id ]
  61. new unid;
  62.  
  63. //  [ Array of all the property interior info ]
  64. new interiorInfo[MAX_INTERIORS][E_INTERIORS];
  65.  
  66. //  [ Pickup array with property id assigned via array slot ( pickupid ) ]
  67. new propPickups[MAX_PROPERTIES] = {-1};
  68.  
  69. //  [ Handles for 3D text displayed at property entrances ]
  70. new Text3D:propTextInfo[MAX_PROPERTIES];
  71.  
  72. //  [ Mass array of all the properties and info about them ]
  73. new properties[MAX_PROPERTIES][E_PROPERTIES];
  74.  
  75. //  [ The last pickup the player went through so they can do /enter command ]
  76. new lastPickup[MAX_PLAYERS] = {-1};
  77.  
  78. //  [ Current property Unique Interior the player is in.. defaults to -1 when not in any property ]
  79. new currentInt[MAX_PLAYERS] = {-1};
  80.  
  81. //  [ Player Position array to store the last place the player was before /view command so they can be teleported back ]
  82. new Float:plPos[MAX_PLAYERS][3];
  83.  
  84. //  [ Players actual interior id used for /view /return command ]
  85. new plInt[MAX_PLAYERS];
  86.  
  87. //  [ Array of property type iconid's and strings for property type ]
  88. new propIcons[MAX_TYPES][E_P_TYPES] =   {
  89.                                             { 0, "" },                  // TYPE_EMPTY ( not used )
  90.                                             { 1318, "Casa" },           // TYPE_HOUSE green house icon
  91.                                             { 1318, "Entrar" },         // TYPE_BUSINESS blue house icon
  92.                                             { 1274, "Banco" },          // TYPE_BANK dollar sign icon
  93.                                             { 1247, "Policia" } // TYPE_COP Bribe Star 1247
  94.                                         };
  95.                                        
  96. new propFile[MAX_TYPES][64] =   {
  97.                                     { "blank" },
  98.                                     { "properties/houses.txt" },
  99.                                     { "properties/businesses.txt" },
  100.                                     { "properties/banks.txt" },
  101.                                     { "properties/police.txt" }
  102.                                 };
  103.                                
  104. //  Keep track of what properties we've sent an /enter notification for
  105. new gLastPropertyEnterNotification[MAX_PLAYERS];
  106.  
  107.  
  108. /********************************
  109. *   Interior Info Functions     *
  110. ********************************/
  111. stock Float:GetInteriorExit( id, &Float:x, &Float:y, &Float:z ){
  112.     if( id > MAX_INTERIORS ) return 0.0;
  113.     else {
  114.         x = interiorInfo[id][inExitX];
  115.         y = interiorInfo[id][inExitY];
  116.         z = interiorInfo[id][inExitZ];
  117.         return interiorInfo[id][inExitA];
  118.     }
  119. }
  120.  
  121. // Gets interior exit info from uniq Interior Id. Returns InteriorId or -1 if interior doesn't exist
  122. stock GetInteriorExitInfo( uniqIntId, &Float:exitX, &Float:exitY, &Float:exitZ, &Float:exitA ){
  123.     if( uniqIntId < MAX_INTERIORS ){
  124.         exitX = interiorInfo[uniqIntId][inExitX];
  125.         exitY = interiorInfo[uniqIntId][inExitY];
  126.         exitZ = interiorInfo[uniqIntId][inExitZ];
  127.         exitA = interiorInfo[uniqIntId][inExitA];
  128.         return interiorInfo[uniqIntId][inIntID];
  129.     }
  130.     return -1;
  131. }
  132.  
  133.  
  134. stock GetInteriorIntID( id ){ // Gets the interior id of a uniq Interior Id :S
  135.     if( id > MAX_INTERIORS ) return -1;
  136.     else return interiorInfo[id][inIntID];
  137. }
  138.  
  139. stock GetInteriorName( id )
  140. {
  141.     new tmp[64];
  142.     if( id > MAX_PROPERTIES ) return tmp;
  143.  
  144.     else {
  145.         format( tmp, 64, "%s", interiorInfo[id][inName] );
  146.         return tmp;
  147.     }
  148. }
  149.  
  150. /********************************************************
  151. ********************************************************/
  152.  
  153.  
  154. /********************************
  155. *    Property Functions         *
  156. ********************************/
  157.  
  158. stock Float:GetPropertyEntrance( id, &Float:x, &Float:y, &Float:z ){
  159.     if( id > MAX_PROPERTIES ) return 0.0;
  160.     x = properties[id][eEntX];
  161.     y = properties[id][eEntY];
  162.     z = properties[id][eEntZ];
  163.     return properties[id][eEntA];
  164. }
  165.  
  166. stock Float:GetPropertyExit( id, &Float:x, &Float:y, &Float:z ){
  167.     if( id > MAX_PROPERTIES ) return 0.0;
  168.     return GetInteriorExit( properties[id][eUniqIntId], x, y, z );
  169. }
  170.  
  171. stock GetPropertyInteriorFileId( id ){
  172.     if( id > MAX_PROPERTIES ) return 0;
  173.     else return properties[id][eUniqIntId];
  174. }
  175.  
  176. stock GetPropertyInteriorId( id ){
  177.     if( id > MAX_PROPERTIES ) return 0;
  178.     else return GetInteriorIntID( properties[id][eUniqIntId] );
  179. }
  180.  
  181. stock GetPropertyType( id ){
  182.     if( id > MAX_PROPERTIES ) return 0;
  183.     else return properties[id][eType];
  184. }
  185.  
  186. stock GetPropertyOwner( id ){
  187.     if( id > MAX_PROPERTIES ) return -1;
  188.     else return properties[id][eOwner];
  189. }
  190.  
  191. stock GetPropertyPrice( id ){
  192.     if( id > MAX_PROPERTIES ) return -1;
  193.     else return properties[id][ePrice];
  194. }
  195.  
  196. stock GetPropertyName( id ){
  197.     new tmp[64];
  198.     if( id > MAX_PROPERTIES ) return tmp;
  199.     else {
  200.         format( tmp, 64, "%s", properties[id][ePname] );
  201.         return tmp;
  202.     }
  203. }
  204.  
  205. /********************************************************
  206. ********************************************************/
  207.  
  208. /********************************
  209. *       Database Functions      *
  210. ********************************/
  211.  
  212. stock Float:dbGetPropertyEntrance( database[], uniqId, &Float:x, &Float:y, &Float:z ){
  213.     new
  214.         DB:prop,
  215.         DBResult:query_result,
  216.         query[128],
  217.         num;
  218.  
  219.     prop = db_open( database );
  220.     format( query, 128,"SELECT entX, entY, enZ, entA FROM properties WHERE id = %d LIMIT 1", uniqId );
  221.  
  222.     query_result = db_query( prop, query );
  223.     num = db_num_rows(query_result);
  224.     if(!num) return -1.0;
  225.  
  226.     else {
  227.         db_get_field_assoc( query_result, "entX", query, 128 );
  228.         x = floatstr( query );
  229.         db_get_field_assoc( query_result, "entY", query, 128 );
  230.         y = floatstr( query );
  231.         db_get_field_assoc( query_result, "entZ", query, 128 );
  232.         z = floatstr( query );
  233.         db_get_field_assoc( query_result, "entA", query, 128 );
  234.         return floatstr( query );
  235.     }
  236. }
  237.  
  238. stock dbSetPropertyOwner( database[], uniqId, ownerId ){
  239. }
  240.  
  241. stock dbSetPropertyPrice( database[], uniqId, price ){
  242. }
  243.  
  244. stock dbDeleteProperty( database[], uniqId ){
  245. }
  246.  
  247. stock dbCreateProperty( database[], uniqId, Float:entX, Float:entY, Float:entZ, Float:entA ){ // remember to add rest of params
  248. }
  249.  
  250. stock dbLoadProperties( database[] )
  251. {
  252.     new
  253.             DB:prop,
  254.             DBResult:query_result,
  255.             query[128],
  256.             num,
  257.             i;
  258.  
  259.     prop = db_open( database );
  260.     format( query, 128,"SELECT * FROM properties", uniqId );
  261.  
  262.     query_result = db_query( prop, query );
  263.     num = db_num_rows(query_result);
  264.     if(!num) return 0;
  265.     else {
  266.         while( i < num ){
  267.             db_get_field_assoc( query_result, "entX", query, 128 );
  268.             x = floatstr( query );
  269.             db_get_field_assoc( query_result, "entX", query, 128 );
  270.             x = floatstr( query );
  271.             db_get_field_assoc( query_result, "entY", query, 128 );
  272.             y = floatstr( query );
  273.             db_get_field_assoc( query_result, "entZ", query, 128 );
  274.             z = floatstr( query );
  275.             db_get_field_assoc( query_result, "entA", query, 128 );
  276.             i++;
  277.         }
  278.     }
  279.  
  280. }
  281. /********************************************************
  282. ********************************************************/
  283.  
  284. /*********************************
  285. *   Property System Functions    *
  286. *********************************/
  287.  
  288. ReadInteriorInfo( fileName[] )
  289. {
  290.     new
  291.         File:file_ptr,
  292.         buf[256],
  293.         tmp[64],
  294.         idx,
  295.         uniqId;
  296.  
  297.  
  298.     file_ptr = fopen( fileName, io_read );
  299.     if( file_ptr ){
  300.         while( fread( file_ptr, buf, 256 ) > 0){
  301.             idx = 0;
  302.  
  303.             idx = token_by_delim( buf, tmp, ' ', idx );
  304.             if(idx == (-1)) continue;
  305.             uniqId = strval( tmp );
  306.  
  307.             if( uniqId >= MAX_INTERIORS ) return 0;
  308.  
  309.             idx = token_by_delim( buf, tmp, ' ', idx+1 );
  310.             if(idx == (-1)) continue;
  311.             interiorInfo[uniqId][inIntID] = strval( tmp );
  312.  
  313.             idx = token_by_delim( buf, tmp, ' ', idx+1 );
  314.             if(idx == (-1)) continue;
  315.             interiorInfo[uniqId][inExitX] = floatstr( tmp );
  316.  
  317.             idx = token_by_delim( buf, tmp, ' ', idx+1 );
  318.             if(idx == (-1)) continue;
  319.             interiorInfo[uniqId][inExitY] = floatstr( tmp );
  320.  
  321.             idx = token_by_delim( buf, tmp, ' ', idx+1);
  322.             if(idx == (-1)) continue;
  323.             interiorInfo[uniqId][inExitZ] = floatstr( tmp );
  324.  
  325.             idx = token_by_delim( buf, tmp, ' ', idx+1 );
  326.             if(idx == (-1)) continue;
  327.             interiorInfo[uniqId][inExitA] = floatstr( tmp );
  328.  
  329.             idx = token_by_delim( buf, interiorInfo[uniqId][inName], ';', idx+1 );
  330.             if(idx == (-1)) continue;
  331.  
  332.             /*
  333.             printf( "ReadInteriorInfo(%d, %d, %f, %f, %f, %f ( %s ))",
  334.                     uniqId,
  335.                     interiorInfo[uniqId][inIntID],
  336.                     interiorInfo[uniqId][inExitX],
  337.                     interiorInfo[uniqId][inExitY],
  338.                     interiorInfo[uniqId][inExitZ],
  339.                     interiorInfo[uniqId][inExitA],
  340.                     interiorInfo[uniqId][inName] );*/
  341.  
  342.         }
  343.         //printf( "Interiors File read successfully" );
  344.         fclose( file_ptr );
  345.         return 1;
  346.     }
  347.     printf( "Could Not Read Interiors file ( %s )", fileName );
  348.     return 0;
  349. }
  350.  
  351. ReadPropertyFile( fileName[] )
  352. {
  353.     new  File:file_ptr,
  354.         tmp[128],
  355.         buf[256],
  356.         idx,
  357.         Float:enX,
  358.         Float:enY,
  359.         Float:enZ,
  360.         Float:enA,
  361.         uniqIntId,
  362.         p_type,
  363.         pIcon;
  364.  
  365.     printf("Reading File: %s",fileName);
  366.  
  367.     file_ptr = fopen( fileName, io_read );
  368.  
  369.     if(!file_ptr )return 0;
  370.  
  371.     while( fread( file_ptr, buf, 256 ) > 0){
  372.         idx = 0;
  373.  
  374.         idx = token_by_delim( buf, tmp, ',', idx );
  375.         if(idx == (-1)) continue;
  376.         pIcon = strval( tmp );
  377.  
  378.         idx = token_by_delim( buf, tmp, ',', idx+1 );
  379.         if(idx == (-1)) continue;
  380.         enX = floatstr( tmp );
  381.  
  382.         idx = token_by_delim( buf, tmp, ',', idx+1 );
  383.         if(idx == (-1)) continue;
  384.         enY = floatstr( tmp );
  385.  
  386.         idx = token_by_delim( buf, tmp, ',', idx+1 );
  387.         if(idx == (-1)) continue;
  388.         enZ = floatstr( tmp );
  389.  
  390.         idx = token_by_delim( buf, tmp, ',', idx+1 );
  391.         if(idx == (-1)) continue;
  392.         enA = floatstr( tmp );
  393.  
  394.         idx = token_by_delim( buf, tmp, ',', idx+1 );
  395.         if(idx == (-1)) continue;
  396.         uniqIntId = strval( tmp );
  397.  
  398.         idx = token_by_delim( buf, tmp, ';', idx+1 );
  399.         if(idx == (-1)) continue;
  400.         p_type = strval( tmp );
  401.  
  402.         CreateProperty( uniqIntId, pIcon, enX, enY, enZ, enA, p_type  );
  403.     }
  404.     fclose( file_ptr );
  405.     return 1;
  406. }
  407.  
  408. PutPlayerInProperty( playerid, propId, propVW = 0 )
  409. {
  410.     new Float:x, Float:y, Float:z, Float:a;
  411.     new intFileId;
  412.    
  413.     a = GetPropertyExit( propId, x, y, z );
  414.     SetPlayerPos( playerid, x, y, z );
  415.     SetPlayerFacingAngle( playerid, a );
  416.     SetPlayerInterior( playerid, GetPropertyInteriorId( propId ));
  417.     SetPlayerVirtualWorld( playerid, (propVW==0)? propId+PROP_VW:propVW );
  418.     intFileId = GetPropertyInteriorFileId(propId);
  419.     currentInt[playerid] = propId;
  420.    
  421.     //new dbgstring[128];
  422.     //format(dbgstring,sizeof(dbgstring),"PutPlayerInProperty(%d): FileInt=%d",propId,intFileId);
  423.     //SendClientMessage(playerid,0xFFFFFFFF,dbgstring);
  424.    
  425.     // the following will make the client shop scripts run if we tell it
  426.     // the name of the shop.
  427.     if(intFileId == 22) {
  428.         SetPlayerShopName(playerid,"FDPIZA");
  429.     }
  430.     else if(intFileId == 47) {
  431.         SetPlayerShopName(playerid,"FDBURG");
  432.     }
  433.     else if(intFileId == 130) {
  434.         SetPlayerShopName(playerid,"FDCHICK");
  435.     }
  436.     else if(intFileId == 32) {
  437.         SetPlayerShopName(playerid,"AMMUN1");
  438.     }
  439.     else if(intFileId == 96) {
  440.         SetPlayerShopName(playerid,"AMMUN2");
  441.     }
  442.     else if(intFileId == 122) {
  443.         SetPlayerShopName(playerid,"AMMUN3");
  444.     }
  445.     else if(intFileId == 123) {
  446.         SetPlayerShopName(playerid,"AMMUN5");
  447.     }
  448.    
  449. }
  450.  
  451. // Adds new property to property file
  452. AddProperty( uniqIntId, Float:entX, Float:entY, Float:entZ, Float:entA, p_type, comment[]="" )
  453. {
  454.     new
  455.         Float:exitX,
  456.         Float:exitY,
  457.         Float:exitZ,
  458.         Float:exitA,
  459.         interiorId,
  460.         File:file_ptr,
  461.         tmp[128];
  462.  
  463.     interiorId = GetInteriorExitInfo( uniqIntId, exitX, exitY, exitZ, exitA );
  464.  
  465.     if( interiorId != -1 ){
  466.         file_ptr = fopen( propFile[p_type], io_append );
  467.         if(file_ptr){
  468.             format( tmp, 128, "%d, %f, %f, %f, %f, %d, %d ; //%s\r\n", propIcons[p_type][tIcon],entX, entY, entZ, entA, uniqIntId, p_type, comment );
  469.  
  470.             fwrite( file_ptr, tmp );
  471.             fclose( file_ptr );
  472.             printf( "PropDB - %s", tmp );
  473.             return CreateProperty( uniqIntId, propIcons[p_type][tIcon], entX, entY, entZ, entA,  p_type );
  474.         }
  475.     }
  476.     return -1;
  477. }
  478.  
  479. CreateProperty( uniqIntId, iconId,  Float:entX, Float:entY, Float:entZ, Float:entA, p_type, name[64]="", owner=-1, price=0 )
  480. {
  481.     if( (unid+1) < MAX_PROPERTIES ){
  482.         new Id = CreatePickup( iconId ,23, entX, entY, entZ, 0 );
  483.         //printf( "CreateProperty(%d, %d, %f, %f, %f, %f, %d)", uniqIntId, iconId, entX, entY, entZ, entA, p_type );
  484.         propPickups[Id] = unid;
  485.         properties[unid][eEntX]     = entX;
  486.         properties[unid][eEntY]     = entY;
  487.         properties[unid][eEntZ]     = entZ;
  488.         properties[unid][eEntA]     = entA;
  489.         properties[unid][eUniqIntId] = uniqIntId;
  490.         properties[unid][eOwner]    = owner;
  491.         properties[unid][ePrice]    = price;
  492.         properties[unid][eType]     = p_type;
  493.         format( properties[unid][ePname], 64, "%s", name );
  494.        
  495.         new text_info[256];
  496.        
  497.         propTextInfo[unid] = Text3D:INVALID_3DTEXT_ID;
  498.        
  499.         if(p_type == TYPE_HOUSE) {
  500.             format(text_info,256,"[Casa]");
  501.             propTextInfo[unid] = Create3DTextLabel(text_info,0x88EE88FF,entX,entY,entZ+0.75,20.0,0,1);
  502.         }
  503.         else if(p_type == TYPE_BUSINESS) {
  504.             format(text_info,256,"[Local]");
  505.             propTextInfo[unid] = Create3DTextLabel(text_info,0xAAAAFFFF,entX,entY,entZ+0.75,20.0,0,1);
  506.         }
  507.         else if(p_type == TYPE_BANK) {
  508.             format(text_info,256,"[Banco]");
  509.             propTextInfo[unid] = Create3DTextLabel(text_info,0xEEEE88FF,entX,entY,entZ+0.75,20.0,0,1);
  510.         }
  511.         else if(p_type == TYPE_COP) {
  512.             format(text_info,256,"[Central Policial]");
  513.             propTextInfo[unid] = Create3DTextLabel(text_info,0xEEEE88FF,entX,entY,entZ+0.75,20.0,0,1);
  514.         }
  515.  
  516.         return unid++;
  517.     }
  518.     else print( "Property Limit Reached" );
  519.     return -1;
  520. }
  521.  
  522. PropertyCommand( playerid, cmd[],cmdtext[],idx, p_type )
  523. {
  524.     new
  525.             Float:x,
  526.             Float:y,
  527.             Float:z,
  528.             Float:a,
  529.             tmp[256],
  530.             string[128],
  531.             uniqId,
  532.             id;
  533.  
  534.     if( GetPlayerInterior(playerid) != 0 || GetPlayerVirtualWorld(playerid)!= 0 ){
  535.         SendClientMessage(playerid, 0x550000FF, "You can only create properties in Interior 0 and VW 0" );
  536.         return 1;
  537.     }
  538.  
  539.     GetPlayerPos( playerid, x, y, z );
  540.     GetPlayerFacingAngle( playerid, a );
  541.  
  542.     tmp = strtok( cmdtext, idx );
  543.     if(!strlen(tmp)){
  544.         format( string, 128, "Usage: %s [uniqInteriorId] [optional-comment]", cmd );
  545.         SendClientMessage( playerid, 0xFF00CC, string );
  546.         return 1;
  547.     }
  548.     if(!isNumeric(tmp)){
  549.         SendClientMessage(playerid, 0x550000, "Uniq Interior Id must be a number" );
  550.         return 1;
  551.     }
  552.     uniqId = strval( tmp );
  553.  
  554.     if( uniqId > MAX_INTERIORS || uniqId < 0 ){
  555.         SendClientMessage( playerid, 0xFFFFCC, "Invalid Uniq Interior Id" );
  556.         return 1;
  557.     }
  558.  
  559.     idx = token_by_delim( cmdtext, tmp, '\0', idx );
  560.     if(idx){
  561.         id = AddProperty( uniqId, x, y, z, a, p_type, tmp );
  562.     }
  563.  
  564.     else {
  565.         id = AddProperty( uniqId, x, y, z, a, p_type );
  566.     }
  567.  
  568.     if( id != -1 ){
  569.         format( tmp, 256, "Property Type ( %d ) Added Successfully: UniqId: %d Interior: %d IntName: %s",p_type, id, interiorInfo[uniqId][inIntID], interiorInfo[uniqId][inName] );
  570.         SendClientMessage( playerid, 0xCC7700, tmp );
  571.     }else{
  572.         SendClientMessage( playerid, 0x00FF55, "Error: Something went wrong/Property Limit Reached" );
  573.     }
  574.     return 1;
  575. }
  576.  
  577. LoadProperties()
  578. {
  579.     if( properties[0][eType] != TYPE_EMPTY ){
  580.         UnloadProperties();
  581.     }
  582.     unid = 0;
  583.     for( new i = 0; i < MAX_PROPERTIES; i++ ){
  584.         properties[i][eType] = TYPE_EMPTY;
  585.     }
  586.  
  587.     ReadInteriorInfo( "properties/interiors.txt" );
  588.  
  589.     for( new i = 0; i < MAX_TYPES; i++ ){
  590.         ReadPropertyFile( propFile[i] );
  591.     }
  592.     return 1;
  593. }
  594.  
  595. UnloadProperties()
  596. {
  597.     new
  598.         p;
  599.     for( new i = 0; i < MAX_PROPERTIES; i++ ){
  600.         if( propPickups[i] != -1 ){
  601.             DestroyPickup( i );
  602.             p = propPickups[i];
  603.             propPickups[i] = -1;
  604.             properties[p][eInterior] = -1;
  605.             properties[p][eType] = TYPE_EMPTY;
  606.             properties[p][eOwner] = -1;
  607.             properties[p][ePrice] = 0;
  608.             properties[p][ePname][0] = '\0';
  609.         }
  610.     }
  611. }
  612.  
  613. /********************************************************
  614. ********************************************************/
  615.  
  616.  
  617. /************************************
  618. *           Callbacks               *
  619. ************************************/
  620.  
  621.  
  622. public OnFilterScriptInit()
  623. {
  624.     print("\n-----------------------------------");
  625.     print("Grand Larceny Property Filterscript      ");
  626.     print("-----------------------------------\n");
  627.     return 1;
  628. }
  629.  
  630. public OnFilterScriptExit()
  631. {
  632.     UnloadProperties();
  633.     return 1;
  634. }
  635.  
  636. public OnGameModeInit()
  637. {
  638.     LoadProperties();
  639.     return 1;
  640. }
  641.  
  642. public OnGameModeExit()
  643. {
  644.     UnloadProperties();
  645.     return 1;
  646. }
  647.  
  648. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  649. {
  650.     if( newinteriorid == 0 ){
  651.         currentInt[playerid] = -1;
  652.         SetPlayerVirtualWorld( playerid, 0 );
  653.     }
  654.     return 1;
  655. }
  656.  
  657. public OnPlayerSpawn( playerid )
  658. {
  659.     gLastPropertyEnterNotification[playerid] = -1;
  660.     return 1;
  661. }
  662.  
  663. public OnPlayerPickUpPickup(playerid, pickupid)
  664. {
  665.     //printf( "DEBUG: Player %d pickedup Pickup %d Prop Id %d", playerid, pickupid );
  666.     lastPickup[playerid] = pickupid;
  667.     new id = propPickups[pickupid];
  668.     new pmsg[256];
  669.  
  670.     if( properties[id][eType] > 0 ){
  671.    
  672.         if(gLastPropertyEnterNotification[playerid] != id){
  673.             gLastPropertyEnterNotification[playerid] = id;
  674.             switch( properties[id][eType] ){
  675.                 case TYPE_HOUSE:{
  676.                     format(pmsg,256,"* Casa: Use /entrar para entrar");
  677.                     SendClientMessage( playerid, 0xFF55BBFF, pmsg );
  678.                     return 1;
  679.                 }
  680.  
  681.                 case TYPE_BUSINESS:{
  682.                     format(pmsg,256,"* Local: Use /entrar para entrar");
  683.                     SendClientMessage( playerid, 0xFF55BBFF, pmsg );
  684.                     return 1;
  685.                 }
  686.  
  687.                 case TYPE_BANK:{
  688.                     format(pmsg,256,"* Banco: Use /entrar para entrar");
  689.                     SendClientMessage( playerid, 0xFF55BBFF, pmsg );
  690.                     return 1;
  691.                 }
  692.  
  693.                 case TYPE_COP:{
  694.                     format(pmsg,256,"* Centro Policial: Use /entrar para entrar");
  695.                     SendClientMessage( playerid, 0xFF55BBFF, pmsg );
  696.                     return 1;
  697.                 }
  698.             }
  699.         }
  700.     }
  701.     else SendClientMessage( playerid, 0xFF9900FF, "Esta Propriedade não existe." );
  702.  
  703.     return 1;
  704. }
  705.  
  706. public OnPlayerCommandText(playerid, cmdtext[])
  707. {
  708.     new idx;
  709.     new cmd[256];
  710.  
  711.     cmd = strtok(cmdtext, idx);
  712.    
  713.     // Public commands.
  714.     if(strcmp("/entrar", cmd, true) == 0) // enter property
  715.     {
  716.         if( lastPickup[playerid] != -1 || properties[lastPickup[playerid]][eType] > 0 ){
  717.             new
  718.                 id = propPickups[lastPickup[playerid]],
  719.                 Float:x,
  720.                 Float:y,
  721.                 Float:z;
  722.  
  723.             GetPropertyEntrance( id, x, y, z );
  724.             if( IsPlayerInRangeOfPoint( playerid, 3.0, x, y, z )){
  725.                 PutPlayerInProperty( playerid, id );
  726.                 SendClientMessage( playerid, 0x55AADDFF, "* Você entrou em uma propriedade para sair digite /sair" );
  727.                 return 1;
  728.             }
  729.         }
  730.         return 1;
  731.     }
  732.     else if(strcmp("/sair", cmd, true) == 0) // exit property
  733.     {
  734.         if( currentInt[playerid] > -1 && GetPlayerInterior(playerid) == GetPropertyInteriorId( currentInt[playerid] )){
  735.  
  736.             new id = currentInt[playerid];
  737.             new Float:x;
  738.             new Float:y;
  739.             new Float:z;
  740.             new Float:a;
  741.  
  742.             // make sure they're near the exit before allowing them to exit.
  743.             GetPropertyExit( id, x, y, z );
  744.             if(!IsPlayerInRangeOfPoint(playerid,4.5,x,y,z)) {
  745.                 SendClientMessage(playerid,0xDDAA55FF,"* Fique perto da saiada e digite /sair - Caso queira sair");
  746.                 return 1;
  747.             }
  748.  
  749.             a = GetPropertyEntrance( id, x, y, z );
  750.             SetPlayerPos( playerid, x, y, z );
  751.             SetPlayerFacingAngle( playerid, a );
  752.             SetPlayerInterior( playerid, 0 );
  753.             SetPlayerVirtualWorld( playerid, 0 );
  754.         }
  755.         currentInt[playerid] = -1;
  756.         return 1;
  757.     }
  758.    
  759.     // The rest of the commands here are for
  760.     // property creation which is admin only.
  761.    
  762.     if(!IsPlayerAdmin(playerid)) return 0;
  763.  
  764.     if(strcmp("/chouse", cmd, true) == 0) // creates a house type property
  765.     {
  766.         PropertyCommand( playerid, cmd, cmdtext,idx, TYPE_HOUSE );
  767.         return 1;
  768.     }
  769.     else if(strcmp("/cbus", cmd, true) == 0) // creates a business type property
  770.     {
  771.         PropertyCommand( playerid, cmd, cmdtext,idx, TYPE_BUSINESS );
  772.         return 1;
  773.     }
  774.     else if(strcmp("/ccop", cmd, true) == 0) // creates a police station property
  775.     {
  776.         PropertyCommand( playerid, cmd, cmdtext,idx, TYPE_COP );
  777.         return 1;
  778.     }
  779.     else if(strcmp("/cbank", cmd, true) == 0) // creates a bank type property
  780.     {
  781.         PropertyCommand( playerid, cmd, cmdtext,idx, TYPE_BANK );
  782.         return 1;
  783.     }
  784.     else if(strcmp("/ver", cmd, true) == 0) //Basically lets you view an interior from the interiors.txt file by id
  785.     {
  786.  
  787.         new
  788.             tmp[256],
  789.             string[128],
  790.             uniqId,
  791.             Float:x,
  792.             Float:y,
  793.             Float:z,
  794.             Float:a;
  795.         tmp = strtok( cmdtext, idx );
  796.         if(!strlen(tmp)){
  797.             format( string, 128, "Use: %s [uniqInteriorId]", cmd );
  798.             SendClientMessage( playerid, 0xFF00CC, string );
  799.  
  800.             return 1;
  801.         }
  802.         if(!isNumeric(tmp)){
  803.             SendClientMessage(playerid, 0x550000, "O ID do Interior deve ser numero" );
  804.             return 1;
  805.         }
  806.         uniqId = strval( tmp );
  807.  
  808.         if( uniqId > MAX_INTERIORS || uniqId < 0 ){
  809.             SendClientMessage( playerid, 0xFFFFCC, "Interior invalido" );
  810.             return 1;
  811.         }
  812.         if( GetPlayerInterior( playerid ) == 0 ){
  813.             GetPlayerPos( playerid, plPos[playerid][0], plPos[playerid][1], plPos[playerid][2] );
  814.             plInt[playerid] = GetPlayerInterior( playerid );
  815.         }
  816.         a = GetInteriorExit( uniqId, x, y, z );
  817.         SetPlayerInterior( playerid, GetInteriorIntID( uniqId ) );
  818.         SetPlayerPos( playerid, x, y, z );
  819.         SetPlayerFacingAngle( playerid, a );
  820.         format( string, 128, "Id: %d InteriorId: %d Nome: %s | Use /retornar Para Retornar", uniqId,GetInteriorIntID( uniqId ), GetInteriorName( uniqId ));
  821.         SendClientMessage( playerid, 0x556600FF, string );
  822.         return 1;
  823.     }
  824.     else if( strcmp( "/retornar", cmd, true ) == 0 ) // return from /view command to last position
  825.     {
  826.         SetPlayerPos( playerid, plPos[playerid][0], plPos[playerid][1], plPos[playerid][2] );
  827.         SetPlayerInterior( playerid, plInt[playerid] );
  828.         return 1;
  829.     }
  830.  
  831.     return 0;
  832. }
  833.  
  834. /***********************************************************************
  835. ***********************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment