Advertisement
Zumorio

Untitled

Feb 9th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.91 KB | None | 0 0
  1. //All credits goes to FireCat and EquinoX/Flaken
  2.  
  3.  
  4.  
  5. #include <a_samp>
  6. #include <SII>
  7. #include <sscanf2>
  8. #include <zcmd>
  9. #include <streamer>
  10.  
  11. #define MAX_HOUSES 100//Lets define that we can have the max limit of our houses to 100.
  12. enum HouseInfo//Naming the enum
  13. {
  14.     Owner[24],//This will be where it will store the house owner name, in a 24 bit size array.
  15.     Owned,//To store if the house is owned or not.
  16.     Price,//How much the house will cost.
  17.     Float:XPos,//Float X position of the checkpoint
  18.     Float:YPos,//Self explanatory.
  19.     Float:ZPos,//Self explanatory.
  20.     VirtualWorld,//The checkpoints virtual world.
  21.     Text3D:HouseLabel//That label where it says "Owned Price..."
  22. }
  23. new HInfo[MAX_HOUSES][HouseInfo];//This is the var where we will read the house info.
  24.  
  25. new HouseCount;//To check how many houses have we created.
  26. new HouseEnter[MAX_HOUSES];//This will be where we will store the house entrance checkpoint
  27. new HouseExit[MAX_HOUSES];//This will be where we will store the house exit checkpoint.
  28. new PlayerInHouseID[MAX_PLAYERS];//To check what house id is the player in.
  29.  
  30.  
  31. CMD:createhouse(playerid,params[])
  32. {
  33.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"You aren't an admin!");//Check if the player is currently rcon logged in.
  34.     new HousePrice,id = HouseCount;//Creating the house price for the selected value in the command, and the last house id created.
  35.     if(sscanf(params,"i",HousePrice)) return SendClientMessage(playerid,-1,"USAGE: /createhouse <price>");//Checking if the player uses the correct syntax. The parameter "i" in sscanf means integer, also could be used as "d".
  36.     new Float:x,Float:y,Float:z;//Creating the floats, to store the player's position.
  37.     GetPlayerPos(playerid,x,y,z);//Getting the player's position and storing it
  38.     HInfo[id][Price] = HousePrice;//Setting the house price to the selected one.
  39.     HInfo[id][Owned] = 0;//Setting the house id owned = 0
  40.     HInfo[id][XPos] = x;//Storing the XPos value to the player's x.
  41.     HInfo[id][YPos] = y;//Storing the YPos value to the player's y.
  42.     HInfo[id][ZPos] = z;//Storing the ZPos value to the player's z.
  43.     HInfo[id][VirtualWorld] = GetPlayerVirtualWorld(playerid);
  44.     format(HInfo[id][Owner],24,"Nonusablenameforthishouse");//Formating the "Owner" house id value to "Nonusablenameforthishouse".
  45.     SendClientMessage(playerid,-1,"House created");
  46.     HouseEnter[id] = CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));//Creating the checkpoint and storing it in the HouseEnter value.
  47.     HouseExit[id] = CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));//Creating the house exit checkpoint and storing it in the HouseExit value.
  48.     new file[40],labelstring[100];//Creating the "file", and the labelstring var.
  49.     format(file,sizeof(file),"FHouse/Houses/%i.ini",id);//Formating the var to the selected house directory.
  50.     INI_Open(file);//Opening the file with SII.
  51.     INI_WriteInt("Price",HousePrice);//Writing in the place "Price" the inputted "Price" value.
  52.     INI_WriteInt("Owned",0);//Setting to "Owned" = 0 in the ini file.
  53.     INI_WriteInt("VirtualWorld",GetPlayerVirtualWorld( playerid));//Writing "VirtualWorld" = GetPlayerVirtualWorld(..);
  54.     INI_WriteFloat("XPos",x);//Writing the players pos for the check point position.
  55.     INI_WriteFloat("YPos",y);//Self explanatory.
  56.     INI_WriteFloat("ZPos",z);//Self explanatory.
  57.     INI_WriteString("Owner","Nonusablenameforthishouse ");//Writing a string in "Owned" to "Nonusablenameforthishouse"
  58.     INI_Save();//Saving file with SII.
  59.     INI_Close();//Closing the file with SII.
  60.     format(labelstring,sizeof(labelstring),"Owned: No \nPrice: %i",HousePrice);
  61.     HInfo[id][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,x,y,z,25, 0,GetPlayerVirtualWorld(playerid));
  62.     HouseCount++;
  63.     return 1;
  64. }
  65.  
  66. CMD:buy(playerid,params[])
  67. {
  68.     for(new i = 0; i < MAX_HOUSES;i++)//Loop threw all houses.
  69.     {
  70.         if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;//Check if the player is near a house checkpoint
  71.         if(GetPlayerMoney(playerid) < HInfo[i][Price]) return SendClientMessage(playerid,-1,"You don't have enough money");//Checking the players money, to see if he has enough to buy the house.
  72.         if(HInfo[i][Owned] == 1) return SendClientMessage(playerid,-1,"This house is already owned");//Checking if the house is already owned.
  73.         HInfo[i][Owned] = 1;//Setting the house owned var to 1.
  74.         new file[60],pName[24],string[100];//Creating the necessary vars.
  75.         GetPlayerName(playerid,pName,sizeof(pName));//Retrieving the player's name.
  76.         format(HInfo[i][Owner],24,"%s",pName);//Setting the House Owner's var
  77.         format(file,sizeof(file),"FHouse/Houses/%i.ini",i);//Formating the house file
  78.         INI_Open(file);//Opening the house file
  79.         INI_WriteInt("Owned",1);//Setting in the ini file "Owned" to 1
  80.         INI_WriteString("Owner",pName);//Setting the "Owner" to the player's name.
  81.         INI_Save();//Saving the ini
  82.         INI_Close();//Closing the ini
  83.         format(string,sizeof(string),"Owned: Yes \nPrice: %i \nOwner: %s",HInfo[i][Price],pName);//Formating the string, so we can update the label of the house
  84.         Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);//Updating the label with a red color
  85.         GivePlayerMoney(playerid,-HInfo[i][Price]);
  86.         return 1;
  87.     }
  88.     SendClientMessage(playerid,-1,"You aren't near a house!");
  89.     return 1;
  90. }
  91.  
  92. CMD:sell(playerid,params[])
  93. {
  94.     for(new i = 0; i < MAX_HOUSES;i++)//Loop threw all houses.
  95.     {
  96.         if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;//Check if the player is near a house checkpoint
  97.         if(HInfo[i][Owned] == 0) return SendClientMessage(playerid,-1,"This house isn't owned");//Checking if the house is already owned.
  98.         new pName[24];
  99.         GetPlayerName(playerid,pName,sizeof(pName));//Retrieving the player's name.
  100.         if(HInfo[i][Owned] == 1 && strcmp(pName,HInfo[i][Owner]) != 0) return SendClientMessage(playerid,-1,"You aren't the owner of this house!");//Checking if the house is owned but the owners name is different
  101.         HInfo[i][Owned] = 0;//Setting the house owned var to 1.
  102.         new file[60],string[100];//Creating the necessary vars.
  103.         format(HInfo[i][Owner],24,"Nonusablenameforthishouse");//Setting the House Owner's var
  104.         format(file,sizeof(file),"FHouse/Houses/%i.ini",i);//Formating the house file
  105.         INI_Open(file);//Opening the house file
  106.         INI_WriteInt("Owned",0);//Setting in the ini file "Owned" to 0
  107.         INI_WriteString("Owner","Nonusablenameforthishouse ");//Setting the "Owner" to the "Nonusablenameforthishouse".
  108.         INI_Save();//Saving the ini
  109.         INI_Close();//Closing the ini
  110.         format(string,sizeof(string),"Owned: No \nPrice: %i \nOwner: None",HInfo[i][Price],pName);//Formating the string, so we can update the label of the house
  111.         Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);//Updating the label with a red color
  112.         return 1;
  113.     }
  114.     SendClientMessage(playerid,-1,"You aren't near a house!");
  115.     return 1;
  116. }
  117.  
  118.  
  119. public OnPlayerEnterDynamicCP(playerid,checkpointid)
  120. {
  121.     for(new i = 0; i < MAX_HOUSES;i++)//Looping threw all houses.
  122.     {
  123.         if(checkpointid == HouseEnter[i])//Checking if the checkpoint id corresponds to one of the house interiors
  124.         {
  125.             new pName[24];//Creating the new var for the players name
  126.             GetPlayerName(playerid,pName,24);//Storing the players name
  127.             if(HInfo[i][Owned] == 1 && strcmp(HInfo[i][Owner],pName) == 0)//String comparing between the players name and the house owners name, to check if they match.
  128.             {
  129.                 SetPVarInt(playerid,"PlayersInteriorHouse",GetPlayerInterior(playerid));//Storing, so later we can reset it back
  130.                 SetPVarInt(playerid,"PlayerVirtualWorldHouse",GetPlayerVirtualWorld(playerid));//Storing, so later we can reset it back
  131.                 SetPlayerInterior(playerid,12);//Setting the players interior.
  132.                 SetPlayerPos(playerid,446.7281,507.0475,1001.4195) ;//Setting the players position.
  133.                 SetPlayerVirtualWorld(playerid,HInfo[i][VirtualWorld]);//Preventing players from different houses, finding each other.
  134.                 PlayerInHouseID[playerid] = i;
  135.             }
  136.             if(HInfo[i][Owned] == 1 && strcmp(HInfo[i][Owner],pName) != 0)//Checking if the house is owned but the house owner and the players name don't match.
  137.             {
  138.                 SendClientMessage(playerid,-1,"You don't own this house");
  139.             }
  140.             if(HInfo[i][Owned] == 0)//Simply checking if the house isn't owned.
  141.             {
  142.                 SendClientMessage(playerid,-1,"/buy to buy this lovely house");
  143.             }
  144.         }
  145.         if(checkpointid == HouseExit[i])//Checking if the checkpointid is an House exit
  146.         {
  147.             SetPlayerPos(playerid,HInfo[i][XPos]+3,HInfo[i][YPos],HInfo[i][ZPos]);//Setting the players position to checkpoint position +3
  148.             SetPlayerInterior(playerid,GetPVarInt(playerid,"Pl ayersInteriorHouse"));//Setting the players interior to the one we stored
  149.             SetPlayerVirtualWorld(playerid,GetPVarInt(playerid ,"PlayerVirtualWorldHouse"));//Setting the players virtual world to the one we stored.
  150.         }
  151.     }
  152.     return 1;
  153. }
  154.  
  155. stock LoadHouses()//Creating the stock function
  156. {
  157.     new file[60],houseowner[24];//creating the "file" var. And also creating the "houseowner" var so we can store it, when we are reading the house owner ini line.
  158.     for(new i = 0; i < MAX_HOUSES;i++)//Looping threw every house
  159.     {
  160.         format(file,sizeof(file),"FAdmin/Houses/%i.ini",i);//Opening the house file with the current selected number with "i".
  161.         if(!INI_Exist(file)) continue;//Checking if the ini house file exist, if not to stop there.
  162.         INI_Open(file);//Opening the house ini
  163.         HInfo[i][Price] = INI_ReadInt("Price");//Reading the price.
  164.         HInfo[i][Owned] = INI_ReadInt("Owned");//Reading if it's owned.
  165.         HInfo[i][XPos] = INI_ReadInt("XPos");//Reading the X float position.
  166.         HInfo[i][YPos] = INI_ReadInt("YPos");//Reading the Y float position.
  167.         HInfo[i][ZPos] = INI_ReadInt("ZPos");//Reading the Z float position.
  168.         HInfo[i][VirtualWorld] = INI_ReadInt("VirtualWorld");//Reading the virtual world.
  169.         INI_ReadString(houseowner,"Owner");//Reading the house owner.
  170.         format(HInfo[i][Owner],24,"%s",houseowner);//Formating the "Owner" house id value to the red one.
  171.         HouseEnter[i] = CreateDynamicCP(HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos],1.5,HInfo[i][VirtualWorld]);//Creating the checkpoint and storing it in the HouseEnter value.
  172.         HouseExit[i] = CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,HI nfo[i][VirtualWorld]);//Creating the house exit checkpoint and storing it in the HouseExit value.
  173.         new labelstring[100];//Creating the labelstring var.
  174.         switch(HInfo[i][Owned])//Using the "switch" method to check if the house is owned
  175.         {
  176.             case 0:{format(labelstring,sizeof(labelstring),"Owned: No \nPrice: %i",HInfo[i][Price]);}//If it isnt...
  177.             case 1:{format(labelstring,sizeof(labelstring),"Owned: Yes \nPrice: %i \nOwner: %s",HInfo[i][Price],HInfo[i][Owner]);}//If it is...
  178.         }
  179.         HInfo[i][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos],25.0,HInfo[i][VirtualWorld]);//Creating the label with the formatted string.
  180.         HouseCount++;//+ counting the HouseCount var.
  181.         INI_Close();//Closing the SII file.
  182.     }
  183.     return 1;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement