Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <Dini>
- #include <streamer>
- #define MAX_HOUSES 200
- #define COLOR_WHITE 0xFFFFFFAA //White color
- #define COLOR_RED 0xFF0000AA //Red Color
- #define COLOR_GREEN 0x00FF00AA //Green color
- enum hInfo
- {
- Float:hEnterX, //Entrance X. It's an float! example: 0.0000000. I'm gonna use the same with the other entrances/exits
- Float:hEnterY,
- Float:hEnterZ,
- Float:hExitX,
- Float:hExitY,
- Float:hExitZ,
- InsideInt, //The inside interior.. DUH!
- InsideVir, //Already subscribed above
- OutsideInt,
- OutsideVir,
- bool:hOwned, //boolean! Is house owned? NO = False, YES = True
- hOwner[MAX_PLAYER_NAME], //The house owner! I'm gonna use MAX_PLAYER_NAME, because a player can't have a longer name :')
- hPrice, //Will store the price
- hPickup, //The pickup. This is used to remove/move the pickup icon!
- hIcon, //The map icon. Also used to remove/move it! We are going to need an ID. Without an ID we can't do NOTHING!
- };
- new HouseInfo[MAX_HOUSES][hInfo];
- stock LoadHouse(houseid)
- {
- new fstring[10]; //The string for the file [format]
- format(fstring, 10, "Houses/%d", houseid); //Format the filename
- if(!dini_Exists(fstring)) return 0; //"If Houses/{houseid} not exists then return False (0)"
- HouseInfo[houseid][hEnterX] = dini_Float(fstring, "EnterX");
- HouseInfo[houseid][hEnterY] = dini_Float(fstring, "EnterY");
- HouseInfo[houseid][hEnterZ] = dini_Float(fstring, "EnterZ");
- HouseInfo[houseid][hExitX] = dini_Float(fstring, "ExitX");
- HouseInfo[houseid][hExitY] = dini_Float(fstring, "ExitY");
- HouseInfo[houseid][hExitZ] = dini_Float(fstring, "ExitZ");
- HouseInfo[houseid][hInsideInt] = dini_Int(fstring, "InsideInt");
- HouseInfo[houseid][hInsideVir] = dini_Int(fstring, "InsideVir");
- HouseInfo[houseid][hOutsideInt] = dini_Int(fstring, "OutsideInt");
- HouseInfo[houseid][hOUtsideVir] = dini_Int(fstring, "OutsideVir");
- HouseInfo[houseid][hOwned] = dini_Bool(fstring, "Owned") ? true : false; //Because it is an boolean: ? true : false;
- strmid(HouseInfo[houseid][hOwner], dini_Get(fstring, "Owner"), 0, false, strlen(dini_Get("Owner"))); //Used this one instead of {string} = {string}. I've ever read that this is faster
- HouseInfo[houseid][hPrice] = dini_Int(fstring, "Price");
- return 1;
- }
- stock LoadHouseVisual(houseid, bool:reload = false)
- {
- if(reload)
- {
- DestroyDynamicMapIcon(HouseInfo[houseid][hIcon]);
- DestroyDynamicPickup(HouseInfo[houseid][hPickup]);
- }
- if(!HouseInfo[houseid][hOwned]) //Also known as 'if(HouseInfo[houseid][hOwned] == false)' - With aan boolean you can use '!{option}' and "{option}"! (!IsPlayerAdmin())) (IsPlayerAdmin())
- {
- //So the house is not owned. Let's make an green mapicon and en green house pickup!
- HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
- HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
- }
- else
- {
- //House is already owned. Blue pickup and red icon!
- HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
- HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
- }
- return 1;
- }
- stock SaveHouse(houseid)
- {
- dini_FloatSet(fstring, "EnterX", HouseInfo[houseid][hEnterX]);
- dini_FloatSet(fstring, "EnterY", HouseInfo[houseid][hEnterY]);
- dini_FloatSet(fstring, "EnterZ", HouseInfo[houseid][hEnterZ]);
- dini_FloatSet(fstring, "ExitX", HouseInfo[houseid][hExitX]);
- dini_FloatSet(fstring, "ExitY", HouseInfo[houseid][hExitY]);
- dini_FloatSet(fstring, "ExitZ", HouseInfo[houseid][hExitZ]);
- dini_IntSet(fstring, "InsideInt", HouseInfo[houseid][hInsideInt]);
- dini_IntSet(fstring, "InsideVir", HouseInfo[houseid][hInsideVir]);
- dini_IntSet(fstring, "OutsideInt", HouseInfo[houseid][hOutsideInt]);
- dini_IntSet(fstring, "OutsideVir", HouseInfo[houseid][hOUtsideVir]);
- dini_BoolSet(fstring, "Owned", HouseInfo[houseid][hOwned]);
- dini_Get(fstring, "Owner", HouseInfo[houseid][hOwner]); //No, not "GetSet"! :P
- dini_IntSet(fstring, "Price", HouseInfo[houseid][hPrice]);
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & 16 && !IsPlayerInAnyVehicle(playerid)) //If player pressed ENTER_VEHICLe and if he's not in an vehicle
- {
- for(new i = 0; i < MAX_HOUSES; i++) //Loop through all the houses
- {
- if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir]) //Is player near house entrance, and if player is in interior of that house + virtual world
- {
- SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
- SetPlayerInterior(playerid, HouseInfo[i][hInsideInt]);
- SetPlayerVirtualWorld(playerid, HouseInfo[i][hInsideVir]);
- //This will put the player IN the house
- }
- else if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hInsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hInsideVir]) //Same as the previous IsPlayerInRangeOfPoint, but now if the player is near the house exit+int+vir
- {
- SetPlayerPos(playerid, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]);
- SetPlayerInterior(playerid, HouseInfo[i][hOutsideInt]);
- SetPlayerVirtualWorld(playerid, HouseInfo[i][hOutsideVir]);
- }
- }
- }
- return 1;
- }
- public OnGameModeInit()
- {
- SetTimer("UpdatePlayersHouseInfo", 1000, true); //Every 1000 milli seconds (1 sec.) it will be used again
- return 1;
- }
- public UpdatePlayersHouseInfo()
- {
- new str[100]; //The string we are gonna format
- for(new i = 0; i < MAX_PLAYERS; i++) //Loop through all the players
- {
- for(new j = 0; j < MAX_HOUSES; j++) //Loop through all the houses
- {
- if(IsPlayerInRangeOfPoint(j, HouseInfo[j][hEnterX], HouseInfo[j][hEnterY], HouseInfo[j][hEnterZ]) && GetPlayerInterior(i) == HouseInfo[j][hOutsideInt] && GetPlayerVirtualWorld(i) == HouseInfo[j][hOutsideVir]) //You already know this! If you don't know it, do step 3 again!
- {
- if(HouseInfo[j][hOwned]) //Is house owned?
- format(str, 100, "~w~House owned by ~r~%s", HouseInfo[j][hOwner]); //Will give: {white_color}House owned by {yellow_color}OWNER
- else //House isn't owned
- format(str, 100, "~w~House for sale!~n~Price: ~g~$%d,-", HouseInfo[j][hPrice]); //Will give: {white_color}House for sale!{new line}Price: {green_color}$PRICE
- GameTextForPlayer(i, str, 2000, 3); //Show the text 2 seconds!
- }
- }
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext, "/buyhouse", true))
- {
- new pName[MAX_PLAYER_NAME]; //For the player's name - For the house
- GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Get the name of the player and store it in [u]pName[/u]
- for(new i = 0; i < MAX_HOUSES; i++) //Last time I'm gonna say it: Loop through all the houses
- {
- if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir]) //Is player near house entrance, and if player is in interior of that house + virtual world (Last time I said this too!)
- {
- if(HouseInfo[i][hOwned]) return SendClientMessage(playerid, COLOR_RED, "This house is already owned!"); //Is the house owned? Then send message that it's owned and stop.
- if(GetPlayerMoney(playerid) < HouseInfo[i][hPrice]) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money for this!"); //Has player too less money? Send him a message!
- HouseInfo[i][hOwned] = true; //The house is owned, where the player used /buyhouse
- strmid(HouseInfo[i][hOwner], pName, 0, false, strlen(pName)); //Put the players name into the "hOwner" of the house
- GivePlayerMoney(playerid, -HouseInfo[i][hPrice]); //Remove some money of the player.. The value of the house
- SendClientMessage(playerid, COLOR_GREEN, "House bought!"); //Send the player an message.
- SaveHouse(i);
- LoadHouseVisual(i, true); //Load House Visual. Now, I've added ', true': It will RELOAD now!
- return 1;
- }
- }
- return 1;
- }
- if(!strcmp(cmdtext, "/sellhouse", true))
- {
- new pName[MAX_PLAYER_NAME]; //See /buyhouse
- GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //See new pName[MAX_PLAYER_NAME];
- for(new i = 0; i < MAX_HOUSES; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
- {
- if(!strcmp(HouseInfo[i][hOwner], pName, false)) //Is the owner of the house the same as the players name (is the player the owner?? !)
- {
- strmid(HouseInfo[i][hOwner], "For Sale", 0, false, 8); //Set the owner of the house to "For Sale"
- HouseInfo[i][hOwned] = false; //House is not owner anymore!
- GivePlayerMoney(playerid, HouseInfo[i][hPrice]/2); //Give the player 50% of the house value back!
- SendClientMessage(playerid, COLOR_GREEN, "House sold!");
- SaveHouse(i);
- LoadHouseVisual(i, true); //Load House Visual. Now, I've added ', true': It will RELOAD now!
- return 1;
- }
- }
- }
- return 1;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment