11.09.2012, 08:16
I learnt how to use these stuff and i applied each piece info i knew to create this house info
Needed foreach,sscanf2,streamer,zcmd
Simple
Everythings is pratically self explain if you reach care fully you will know what to do and have 0 errors like i did if you did not follow 100% then you will have errors
/enter & /exit
Needed foreach,sscanf2,streamer,zcmd
Simple
Everythings is pratically self explain if you reach care fully you will know what to do and have 0 errors like i did if you did not follow 100% then you will have errors
Код:
#include <a_samp> //this is for the main publics we use #include <streamer> //Streamer for objects #include <sscanf2> //sscanf for cmds #include <zcmd> //zcmd for creating cmds #include <foreach>//for cmds #define COLOR_PURPLE 0x8A2BE2AA //colour purple..This iz needed to send player(s) message in that particular colour #define MAX_HOUSES 1//define max amount houses you want to have //add b4 gamemodeint enum pInfo { pHouseKey, // playerhouse key pCash//Player Money } new PlayerInfo[MAX_PLAYERS][pInfo];//where are we loading the info from //add b4 gaemodeint enum houseInfo { hPrice, //price for house hStatus, //lock or unlock house hOwner[32], //owner name of the house Float:hX,//house pickup position X Float:hY,//house pickup position Y Float:hZ,//house pickup position Z hPickup, //house pickup iz Text3D:hText//the textdraw the house iz going to have } new HouseInfo[MAX_HOUSES][houseInfo]; //Add @ the bottom of the script stock LoadHouses() { new tstar[21][32];//for the file new string[256];//string new File:file = fopen("houses.cfg", io_read);//check the file for the information if(file)//for the files { new idx = 1;//ids while(idx < MAX_HOUSES)//while iz 2 check #define MAX_HOUSES to max sure the house ids arent over the limit { fread(file, string);//reading the files split(string, tstar, '|');//split to get file info HouseInfo[idx][hPrice] = strval(tstar[1]);//getting house price HouseInfo[idx][hStatus] = strval(tstar[2]);//getting house name format(HouseInfo[idx][hOwner], 32, "%s", tstar[3]); HouseInfo[idx][hX] = floatstr(tstar[4]);//floatin pos x HouseInfo[idx][hY] = floatstr(tstar[5]);//floatin pos y HouseInfo[idx][hZ] = floatstr(tstar[6]);//floatin pos z {//creating pickup and labeling it, i use the id system so it would be easier to edit HouseInfo[idx][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ], 0); if(!strcmp("trapstar2020", HouseInfo[idx][hOwner])) format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d", idx, HouseInfo[idx][hOwner], HouseInfo[idx][hPrice]); else format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: %s", idx, HouseInfo[idx][hOwner], hlock(idx)); HouseInfo[idx][hText] = CreateDynamic3DTextLabel(string, COLOR_PURPLE, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]+0.3, 15); } idx++;//house ids } } print("trapstar2020 loaded you houses."); return 1; } stock SaveHouses() { new idx = 1, File:file; new string[256]; while(idx < MAX_HOUSES) { format(string, sizeof(string), "%d|%d|%s|%f|%f|%f\r\n",//%d iz use for info %s iz used for player names && %f iz for floating positions HouseInfo[idx][hPrice],//price HouseInfo[idx][hStatus],//locks HouseInfo[idx][hOwner],//owner name HouseInfo[idx][hX],//pos X HouseInfo[idx][hY],//pos Y HouseInfo[idx][hZ]//pos Z ); if(idx == 1) { file = fopen("houses.cfg", io_write);//creates files } else { file = fopen("houses.cfg", io_append); } fwrite(file, string);//updates info and fclose(file);//then closes idx++;//writes house ids } print("Houses saved successfully."); } //creating the file stock fcreate(filename[]) { if (fexist(filename)) return false;//search to see if file exsist new File:fhnd; fhnd=fopen(filename,io_write);//open file if (fhnd) {//if file found fclose(fhnd);//close it return true;//end if itz true } return false;//create file if itz false } //split stock split(const strsrc[], strdest[][], delimiter)//used for reading files { new i, li; new aNum; new len; while(i <= strlen(strsrc)) { if(strsrc[i] == delimiter || i == strlen(strsrc)) { len = strmid(strdest[aNum], strsrc, li, i, 128); strdest[aNum][len] = 0; li = i+1; aNum++; } i++; } return 1; } //creating house lock stock hlock(hid) { new string[16];//string we going to use if(!HouseInfo[hid][hStatus]) format(string, sizeof(string), "Closed"); else if(HouseInfo[hid][hStatus]) format(string, sizeof(string), "Open"); return string; } //saving and loading houses public OnGameModeInit() { LoadHouses();//load houses when GM Start return 1; } public OnGameModeExit() { SaveHouses();//save house info when GM closed/Restarts(GMX) return 1; } //CMD-TIME(ADMINS) /creating a house,deleting the houses and going to the house CMD:createhouse(playerid, params[])//cmd /createhouse { new string[128];//new for the string we are going to create if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_PURPLE, "You are not an authorized to use this command.");//if the player Isnt Rcon admin he cannot createhouse for(new idx=1; idx<MAX_HOUSES; idx++)//set house id +1 everyone a house iz create { new Float:X, Float:Y, Float:Z;//float the positions GetPlayerPos(playerid, X, Y, Z);//Search for player X Y Z position // Making House HouseInfo[idx][hPrice] = 1; //price the house would be when created HouseInfo[idx][hStatus] = 0; //the lock status of the houses format(HouseInfo[idx][hOwner], 32, "Trapstar2020 House");//the name the will appear when house iz created HouseInfo[idx][hX] = X;//position X of house creation HouseInfo[idx][hY] = Y;//position Y of house creation HouseInfo[idx][hZ] = Z;//position Z of house creation HouseInfo[idx][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ], 0);//create house ticket in the player XYZ postion format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d", HouseInfo[idx][hOwner], HouseInfo[idx][hPrice]);//house going to shown on houseticket HouseInfo[idx][hText] = CreateDynamic3DTextLabel(string, COLOR_PURPLE, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]+0.3, 15);//showing the info idx = MAX_HOUSES; } return 1; } CMD:deletehouse(playerid, params[]) { new id, string[128];//the house id n the string if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_PURPLE, "You are not an authorized to use this command.");//if player not rcon admin if(sscanf(params, "i", id)) return SendClientMessage(playerid, COLOR_PURPLE, "USAGE: /deletehouse [houseid]");//if player didnt input right contanent foreach(Player, i)// { PlayerInfo[i][pHouseKey] = 0;//checks for online if he ownes house format(string, sizeof(string), " Admin %s has deleted your house.", playername(playerid));//tells player his house his delete SendClientMessage(i, COLOR_PURPLE, string);//sends the player the above string } if(!strcmp("Trapstar2020 House", HouseInfo[id][hOwner]))//if trapstar2020 house send the below strings { format(string, sizeof(string), ": %s has deleted house ID %d.", playername(playerid), id);//if no one owns it send this message } else { format(string, sizeof(string), "%s has deleted %s's house. (ID %d)", playername(playerid), HouseInfo[id][hOwner], id);//string saying admin & who house iz delete n the id } //the following will delete all house info HouseInfo[id][hPrice] = 0;//sets house info price 2 0 HouseInfo[id][hStatus] = 0;//sets house info lock 2 0 format(HouseInfo[id][hOwner], 32, "");//delete house name HouseInfo[id][hX] = 0;//sets X position 2 0 HouseInfo[id][hY] = 0;//sets Y position 2 0 HouseInfo[id][hZ] = 0;//sets Z position 2 0 DestroyDynamicPickup(HouseInfo[id][hPickup]);//delete pick DestroyDynamic3DTextLabel(HouseInfo[id][hText]);//no more house text return 1; } CMD:gotohouse(playerid, params[]) { new idx, string[128];//house ids n string for messages if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_PURPLE, "You are not an authorized to use this command.");//if player isnt rcon admin if(sscanf(params, "i", idx)) return SendClientMessage(playerid, COLOR_PURPLE, "USAGE: /gotohouse [houseid]");//if player didnt imput text right SetPlayerVirtualWorld(playerid, 0);//setiing player virtual world to go to SetPlayerInterior(playerid, 0);//setting player interior world to go to SetPlayerPos(playerid, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]);//setting player XYZ psotion to go to format(string, sizeof(string), " You have teleported to house ID %d.", idx);//string for telling player hes there SendClientMessage(playerid, COLOR_PURPLE, string);//sending the string return 1; } stock playername(playerid)//getting player name { new name[MAX_PLAYER_NAME];//what to call the search (new name0 GetPlayerName(playerid,name,sizeof(name));//searches for player name for(new i = 0; i < MAX_PLAYER_NAME; i++)//search all players for the name { if(name[i] == '_') name[i] = ' ';//get the player name } return name;//closes once name gotton } CMD:buyhouse(playerid, params[])//cmd { new string[128], done;//if itz done and string for(new idx=1; idx<MAX_HOUSES; idx++)//house ids { if(IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))//once player in range of house XYZ { if(!strcmp("Trapstar2020 House", HouseInfo[idx][hOwner], false))//if the owner of this house has this name it is not owned { if(PlayerInfo[playerid][pCash] < HouseInfo[idx][hPrice]) return SendClientMessage(playerid, COLOR_PURPLE, "You don't have enough money to buy this house.");//if player dont have enough money GivePlayerMoney(playerid, -HouseInfo[idx][hPrice]);//give player -houseprice money PlayerInfo[playerid][pHouseKey] = idx;//writes that player has house key format(HouseInfo[idx][hOwner], 32, "%s", playername(playerid));//gets player name and change owner file to playername format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: %s", idx, HouseInfo[idx][hOwner], hlock(idx));//sets house info UpdateDynamic3DTextLabelText(HouseInfo[idx][hText], COLOR_PURPLE, string);//writes the abouse tex SendClientMessage(playerid, COLOR_PURPLE, " You have successfully bought a house.");//sends message to player that the bought a house idx = MAX_HOUSES; done = 1; } if(idx == MAX_HOUSES-1 && !done) { SendClientMessage(playerid, COLOR_PURPLE, "This house is owned by someone else.");//if house has a different name then a player ownes it } } if(idx == MAX_HOUSES-1 && !done) { SendClientMessage(playerid, COLOR_PURPLE, "You are not near a buyable house.");//player not in range of the house } } return 1; } CMD:hlock(playerid, params[])//cmd { new string[128], idx, lockdone;//string for text,houseid,lock if(PlayerInfo[playerid][pHouseKey])//checks for phousekey { idx = PlayerInfo[playerid][pHouseKey];//phousekey and if(IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))//if player in range of house XYZ position { if(!HouseInfo[PlayerInfo[playerid][pHouseKey]][hStatus])//checks house stats { HouseInfo[PlayerInfo[playerid][pHouseKey]][hStatus] = 1;//sets the locks stats to 1 check stock hlock to see format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: %s", idx, HouseInfo[idx][hOwner], playername(idx));//changes the text UpdateDynamic3DTextLabelText(HouseInfo[PlayerInfo[playerid][pHouseKey]][hText], COLOR_PURPLE, string);//applies the change GameTextForPlayer(playerid, "~g~House Unlocked", 3500, 3);//sends a message to player the his house iz unlock in the colour green 3.5seconds } else if(HouseInfo[PlayerInfo[playerid][pHouseKey]][hStatus])//checks house status once again { HouseInfo[PlayerInfo[playerid][pHouseKey]][hStatus] = 0;//changes the lock stats check stock hlock for it format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: %s", idx, HouseInfo[idx][hOwner], playername(idx));//changes the pick info UpdateDynamic3DTextLabelText(HouseInfo[PlayerInfo[playerid][pHouseKey]][hText], COLOR_PURPLE, string);//applies the change GameTextForPlayer(playerid, "~r~House Locked", 3500, 3);//marks lock in the colour red for 3.5secs } lockdone = 1;//itz lock } } if(!lockdone)//player not near house to lock it { SendClientMessage(playerid, COLOR_PURPLE, "You are not near something you can lock/unlock.");//sends the player a message saying so } return 1;//return true/false 1 = true } CMD:sellhousetomarket(playerid, params[])// { new string[128], done;//string and if sell 2 market iz done if(!PlayerInfo[playerid][pHouseKey] ) return SendClientMessage(playerid, COLOR_PURPLE, "You don't own a house.");//if playerinfo player doesnt have house key if(sscanf(params, "s[8]", params)) return SendClientMessage(playerid, COLOR_PURPLE, "USAGE: /sellhousetomarket [confirm]");//house to succesfull sell your to the market if(!strcmp(params, "confirm", true))//apply the salee { new idx = PlayerInfo[playerid][pHouseKey];//checks player for house key if(IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[PlayerInfo[playerid][pHouseKey]][hX], HouseInfo[PlayerInfo[playerid][pHouseKey]][hY], HouseInfo[PlayerInfo[playerid][pHouseKey]][hZ]))//checks to see if player is in point of house positions { GivePlayerMoney(playerid, (75*HouseInfo[PlayerInfo[playerid][pHouseKey]][hPrice])/100);//gives player 75% of his money back HouseInfo[PlayerInfo[playerid][pHouseKey]][hStatus] = 0;//sets player house key 2 0 format(HouseInfo[PlayerInfo[playerid][pHouseKey]][hOwner], 32, "Trapstar2020 House");//change the house name back to the non house owner name format(string, sizeof(string), "ID: %d\nOwner: %s\nStatus: For Sale\nPrice: $%d", idx, HouseInfo[idx][hOwner], HouseInfo[idx][hPrice]);//changing text info UpdateDynamic3DTextLabelText(HouseInfo[PlayerInfo[playerid][pHouseKey]][hText], COLOR_PURPLE, string);//applying text info PlayerInfo[playerid][pHouseKey] = 0; SendClientMessage(playerid, COLOR_PURPLE, " You have successfully sold your house to The State. (75 percent of the original price was paid back)");//telling player how much they for 4 the house done = 1;//sale done } if(!done)//if itz not done itz gonna send a message { SendClientMessage(playerid, COLOR_PURPLE, "You are not near your house.");//if it isnt dont message sent return 1; } } return 1; }
Код:
CMD:enter(playerid, params[])//cmd { for(new idx=1; idx<MAX_HOUSES; idx++) //house and there ids { if(IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))//is player in range of door { if(!HouseInfo[idx][hStatus] && PlayerInfo[playerid][pHouseKey] != idx) return SendClientMessage(playerid, COLOR_PURPLE, "This house is locked.");//if house iz locked SetPlayerVirtualWorld(playerid, idx+500);//set the person world 500+ids=id { SetPlayerPos(playerid, X,Y,Z);//input the XYZ you want SetPlayerFacingAngle(playerid, Angle);//angle you want SetCameraBehindPlayer(playerid);//sets camera behind player SetPlayerInterior(playerid, interior);//input interior you want <<<^^^^^ if the following inputs were inputed it will not compile } } return 1; } CMD:exit(playerid, params[])//cmd { new fin;//house if(IsPlayerInRangeOfPoint(playerid, range, X,Y,Z)//input player xyz n range { new idx;//house ids idx = GetPlayerVirtualWorld(playerid)-500;//set back the player virtual world 2 50less if(!fin && idx < MAX_HOUSES && HouseInfo[idx]])//if the player is in house { SetPlayerPos(playerid, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]);//sets player in the house XYZ position/where house iz created SetPlayerInterior(playerid, 0);//sets player int SetPlayerVirtualWorld(playerid, 0);//sets player virtual world fin = 1;//house } } return 1;//return value = true }