Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <SII>
- #include <sscanf2>
- #define MAX_PROPS 500//Self explanatory
- #define PROP_DEFAULT_LABEL_DISTANCE 20.0//Self explanatory
- #define PROP_DEFAULT_NAME "Newly property created"//Original name of a newly create prop
- #define File "FProps/%i.ini"//Self explanatory
- #define DIALOG_DEFAULT_RANGE 2360//Default dialog range
- //=============================== [RRGGBB] =====================================
- #define lblue "{33BBCC}"
- #define lgrey "{BEBEBE}"
- #define lyellow2 "{E1DE1C}"
- //============================= [Colors] =======================================
- #define green 0x00DE28FF
- #define red 0xFF0000FF
- #define yellow 0xF5FF00FF
- #define white 0xF0F0F0FF
- //============================= [Colors] =======================================
- forward GiveCash();
- enum PropInfo
- {
- Float:XPos,
- Float:YPos,
- Float:ZPos,
- Owner[23],
- Owned,
- Price,
- Ownings,
- Pickup,
- World,
- Name[128]
- };
- new PInfo[MAX_PROPS][PropInfo];
- new PropCount;
- new Text3D:PropLabel[MAX_PROPS];
- new NearPickup[MAX_PLAYERS];
- new EditingProp[MAX_PLAYERS];
- new PlayerEarnings[MAX_PLAYERS];
- new PlayerAmmountOfProperties[MAX_PLAYERS];
- new Propertyprice[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print("Fprops - Property system");
- print("--------------------------------------\n");
- SetTimer("GiveCash",60000,true);
- LoadProps();
- for(new i; i < MAX_PROPS; i++)
- {
- if(PInfo[i][Owned] == 1)
- {
- for(new j = 0; j < GetMaxPlayers();i++)
- {
- if(IsPlayerConnected(j))
- {
- if(strcmp(PInfo[i][Owner], GetPName(j), true) == 0)
- {
- PlayerEarnings[j] = PlayerEarnings[j]+PInfo[i][Ownings];
- PlayerAmmountOfProperties[j]++;
- }
- }
- }
- }
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- PlayerEarnings[playerid] = 0;//Preventing the player earning from the owner of the last property connected (Hard to explain xD)
- for(new i; i < MAX_PROPS; i++)
- {
- if(PInfo[i][Owned] == 1)
- {
- if(strcmp(PInfo[i][Owner], GetPName(playerid), true) == 0)
- {
- PlayerEarnings[playerid] = PlayerEarnings[playerid]+PInfo[i][Ownings];
- PlayerAmmountOfProperties[playerid]++;
- }
- }
- }
- return 1;
- }
- COMMAND:createprop(playerid,params[])
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+4,1,"Price","How much will the property cost? \n","Next »","Cancel");
- return 1;
- }
- COMMAND:gotoprop(playerid,params[])
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- new id;
- if(sscanf(params,"i",id)) return SendHelpMessage(playerid,"/gotoprop <propid>","It will teleport you to the specified property id");
- new file[64];
- format(file,sizeof(file),File,id);
- if(!INI_Exist(file)) return SendClientMessage(playerid,red,"That property does not exist!");
- INI_Open(file);
- SetPlayerPos(playerid,INI_ReadFloat("XPos"),INI_ReadFloat("YPos")+2,INI_ReadFloat("ZPos"));
- INI_Close();
- return 1;
- }
- stock SendHelpMessage(playerid, const str1[],const str2[])
- {
- new string[160];
- format(string,sizeof(string),""lyellow2"USAGE: "lgrey"%s",str1);
- SendClientMessage(playerid,0xFF1E00FF,string);
- format(string,sizeof(string),""lblue"FUNCTION: "lgrey"%s",str2);
- SendClientMessage(playerid,0xFF1E00FF,string);
- return 1;
- }
- public OnPlayerPickUpPickup(playerid,pickupid)
- {
- new str[250];
- for(new i = 0; i < MAX_PROPS;i++)
- {
- if(pickupid == PInfo[i][Pickup])
- {
- if(NearPickup[playerid] == 1) return 0;
- NearPickup[playerid] = 1;
- EditingProp[playerid] = i;
- if(PInfo[i][Owned] == 0)
- {
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE,2,"Property","Buy Property","Choose","Cancel");
- }
- else if(PInfo[i][Owned] == 1 && strcmp(PInfo[i][Owner], GetPName(playerid), true) != 0)
- {
- format(str,sizeof(str),"Owned: Yes \nOwner: %s \nOwnings: %i \nProperty name: %s",PInfo[i][Owner],PInfo[i][Ownings],PInfo[i][Name]);
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+1,0,"Property",str,"Ok","Close");
- }
- else if(strcmp(PInfo[i][Owner], GetPName(playerid), true) == 0)
- {
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+2,2,"Property","Sell property \nChange property name \nDeposit money \nWithdraw money","Choose","Cancel");
- }
- break;
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- #define propid EditingProp[playerid]
- new string[200];
- if(dialogid == DIALOG_DEFAULT_RANGE+5)
- {
- if(!response) return ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+4,1,"Price","How much will the property cost? \n","Next »","Cancel");
- new Float:x,Float:y,Float:z,ID = PropCount,ownerstring[120],file[128];
- if(!IsPlayerAdmin(playerid)) return 0;
- if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
- format(ownerstring,sizeof(ownerstring),""lyellow2"Property name: %s \nOwner: None \nCost: %i \nOwnings: %i \nProperty id: %i",PROP_DEFAULT_NAME,Propertyprice[playerid],strval(inputtext),ID);
- format(PInfo[ID][Owner],4,"%s","None");
- format(PInfo[ID][Name],200,"%s",PROP_DEFAULT_NAME);
- format(file,sizeof(file),File,ID);
- GetPlayerPos(playerid,x,y,z);
- PInfo[ID][XPos] = x;
- PInfo[ID][YPos] = y;
- PInfo[ID][ZPos] = z;
- PInfo[ID][Price] = Propertyprice[playerid];
- PInfo[ID][Ownings] = strval(inputtext);
- PInfo[ID][World] = GetPlayerVirtualWorld(playerid);
- PInfo[ID][Pickup] = CreatePickup(1273,23,x,y,z,GetPlayerVirtualWorld(playerid));
- PropLabel[ID] = Create3DTextLabel(ownerstring,white,x,y,z+0.7,PROP_DEFAULT_LABEL_DISTANCE,GetPlayerVirtualWorld(playerid));
- INI_Open(file);
- INI_WriteFloat("XPos",x);
- INI_WriteFloat("YPos",y);
- INI_WriteFloat("ZPos",z);
- INI_WriteInt("Price",Propertyprice[playerid]);
- INI_WriteInt("Ownings",strval(inputtext));
- INI_WriteInt("World",GetPlayerVirtualWorld(playerid));
- INI_WriteInt("Owned",0);
- INI_WriteString("Owner","None");
- INI_WriteString("Name",PROP_DEFAULT_NAME);
- INI_Save();
- INI_Close();
- PropCount++;
- }
- if(dialogid == DIALOG_DEFAULT_RANGE+4)
- {
- if(!response) return 0;
- if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
- Propertyprice[playerid] = strval(inputtext);
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+5,1,"Ownings","How much will the owner gain for each minute? \n","Create","Back «");
- }
- if(!response)
- {
- NearPickup[playerid] = 0;
- return 0;
- }
- if(dialogid == DIALOG_DEFAULT_RANGE)
- {
- switch(listitem)
- {
- case 0:
- {
- new file[128];
- if(GetPlayerMoney(playerid) < PInfo[propid][Price]) {SendClientMessage(playerid,red,"You dont have enough cash!");NearPickup[playerid] = 0;return 1;}//Added brackets here
- format(PInfo[propid][Owner],23,"%s",GetPName(playerid));
- PInfo[propid][Owned] = 1;
- PlayerAmmountOfProperties[playerid]++;
- PlayerEarnings[playerid] = PlayerEarnings[playerid]+PInfo[propid][Ownings];
- format(string,sizeof(string),""lyellow2"Property name: %s \nOwner: %s \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[propid][Name],PInfo[propid][Owner],PInfo[propid][Price],PInfo[propid][Ownings],propid);
- Update3DTextLabelText(PropLabel[propid],yellow,string);
- GivePlayerMoney(propid,-PInfo[propid][Price]);
- format(file,sizeof(file),File,propid);
- INI_Open(file);
- INI_WriteInt("Owned",1);
- INI_WriteString("Owner",PInfo[propid][Owner]);
- INI_Save();
- INI_Close();
- }
- }
- NearPickup[playerid] = 0;
- }
- if(dialogid == DIALOG_DEFAULT_RANGE+2)
- {
- switch(listitem)
- {
- case 0:
- {
- new file[128];
- format(file,sizeof(file),File,propid);
- format(PInfo[propid][Owner],23,"None",GetPName(playerid));
- PInfo[propid][Owned] = 0;
- format(PInfo[propid][Name],200,"%s",PROP_DEFAULT_NAME);
- PlayerAmmountOfProperties[playerid]--;
- PlayerEarnings[playerid] -= PInfo[propid][Ownings];
- format(string,sizeof(string),""lyellow2"Prop name: %s \nOwner: None \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[propid][Name],PInfo[propid][Price],PInfo[propid][Ownings],propid);
- Update3DTextLabelText(PropLabel[propid],yellow,string);
- NearPickup[playerid] = 0;
- INI_Open(file);
- INI_WriteInt("Owned",0);
- INI_WriteString("Owner","None");
- INI_WriteString("Name",PROP_DEFAULT_NAME);
- INI_Save();
- INI_Close();
- NearPickup[playerid] = 0;
- }
- case 1:
- {
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+3,1,"Property","Insert the name name of the property you want to change\n","Ok","Cancel");
- }
- case 2:
- {
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+6,1,"Deposit","How much money would you like to deposit? \n","Deposit","Cancel");
- }
- case 3:
- {
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+8,1,"Withdraw","How much money would you like to withdraw \n","Withdraw","Cancel");
- }
- }
- }
- if(dialogid == DIALOG_DEFAULT_RANGE+6)
- {
- NearPickup[playerid] = 0;
- if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
- if(strval(inputtext) > GetPlayerMoney(playerid)) return SendClientMessage(playerid,red,"You don't have that much money!");
- static Float:p[3],file[64];
- GetPlayerPos(playerid, p[0], p[1], p[2]);
- format(file,sizeof(file),File,propid);
- INI_Open(file);
- INI_WriteInt("Deposited",INI_ReadInt("Deposited")+strval(inputtext));
- format(string,sizeof(string),"You had: %i \nYou now have: %i \nYou deposited: %i \nYou now have in in total %i in your property",GetPlayerMoney(playerid),GetPlayerMoney(playerid)-strval(inputtext),strval(inputtext),INI_ReadInt("Deposited"));
- INI_Save();
- INI_Close();
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+7,0,"Deposited",string,"Ok","");
- GivePlayerMoney(playerid,-strval(inputtext));
- PlayerPlaySound(playerid, 1057, p[0], p[1], p[2]);
- }
- if(dialogid == DIALOG_DEFAULT_RANGE+8)
- {
- NearPickup[playerid] = 0;
- if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
- static Float:p[3],file[64];
- GetPlayerPos(playerid, p[0], p[1], p[2]);
- format(file,sizeof(file),File,propid);
- INI_Open(file);
- if(INI_ReadInt("Deposited") < strval(inputtext)) return SendClientMessage(playerid,red,"You don't have that much money!");
- INI_WriteInt("Deposited",INI_ReadInt("Deposited")-strval(inputtext));
- format(string,sizeof(string),"You had: %i \nYou now have: %i \nYou with drawed: %i \nYou now have in total %i in your property",GetPlayerMoney(playerid),strval(inputtext),strval(inputtext),INI_ReadInt("Deposited"));
- INI_Save();
- INI_Close();
- ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+7,0,"Withdrawed",string,"Ok","");
- GivePlayerMoney(playerid,strval(inputtext));
- PlayerPlaySound(playerid, 1057, p[0], p[1], p[2]);
- }
- if(dialogid == DIALOG_DEFAULT_RANGE+3)
- {
- new file[128];
- NearPickup[playerid] = 0;
- format(file,sizeof(file),File,propid);
- if(strlen(inputtext) == 0) return 0;
- format(PInfo[propid][Name],200,"%s",inputtext);
- format(string,sizeof(string),""lyellow2"Prop name: %s \nOwner: %s \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[propid][Name],PInfo[propid][Owner],PInfo[propid][Price],PInfo[propid][Ownings],propid);
- Update3DTextLabelText(PropLabel[propid],yellow,string);
- SendClientMessage(playerid,green,"Property name successfully changed!");
- NearPickup[playerid] = 0;
- INI_Open(file);
- INI_WriteString("Name",PInfo[propid][Name]);
- INI_Save();
- INI_Close();
- }
- if(dialogid == DIALOG_DEFAULT_RANGE+1)
- {
- NearPickup[playerid] = 0;
- }
- return 0;
- }
- stock GetPName(playerid)
- {
- new p_name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,p_name,sizeof(p_name));
- return p_name;
- }
- public GiveCash()
- {
- new string[200];
- for(new i = 0; i < MAX_PLAYERS;i++)
- {
- if(IsPlayerConnected(i))
- {
- if(PlayerAmmountOfProperties[i] > 0)
- {
- GivePlayerMoney(i,PlayerEarnings[i]);
- format(string,sizeof(string),""lgrey"You have earned "lyellow2"%i$ "lgrey"from your properties!",PlayerEarnings[i]);
- SendClientMessage(i,white,string);
- }
- }
- }
- }
- stock LoadProps()
- {
- new file[128],ownername[23],name[200],ownerstring[200];
- for(new i = 0; i < MAX_PROPS;i++)
- {
- format(file,sizeof(file),File,i);
- if(INI_Exist(file))
- {
- INI_Open(file);
- INI_ReadString(ownername,"Owner",23);
- INI_ReadString(name,"Name",200);
- format(PInfo[i][Owner],23,"%s",ownername);
- format(PInfo[i][Name],200,"%s",name);
- PInfo[i][XPos] = INI_ReadFloat("XPos");
- PInfo[i][YPos] = INI_ReadFloat("YPos");
- PInfo[i][ZPos] = INI_ReadFloat("ZPos");
- PInfo[i][Price] = INI_ReadInt("Price");
- PInfo[i][Ownings] = INI_ReadInt("Ownings");
- PInfo[i][World] = INI_ReadInt("World");
- PInfo[i][Owned] = INI_ReadInt("Owned");
- PInfo[i][Pickup] = CreatePickup(1273,23,PInfo[i][XPos],PInfo[i][YPos],PInfo[i][ZPos],PInfo[i][World]);
- if(PInfo[i][Owned] == 1)
- {
- format(ownerstring,sizeof(ownerstring),""lyellow2"Prop name: %s \nOwner: %s \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[i][Name],PInfo[i][Owner],PInfo[i][Price],PInfo[i][Ownings],i);
- PropLabel[i] = Create3DTextLabel(ownerstring,white,PInfo[i][XPos],PInfo[i][YPos],PInfo[i][ZPos]+0.7,PROP_DEFAULT_LABEL_DISTANCE,PInfo[i][World]);
- }
- else
- {
- format(ownerstring,sizeof(ownerstring),""lyellow2"Prop name: %s \nOwner: None \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[i][Name],PInfo[i][Price],PInfo[i][Ownings],i);
- PropLabel[i] = Create3DTextLabel(ownerstring,white,PInfo[i][XPos],PInfo[i][YPos],PInfo[i][ZPos]+0.7,PROP_DEFAULT_LABEL_DISTANCE,PInfo[i][World]);
- }
- INI_Close();
- PropCount++;
- }
- }
- return 1;
- }
- //Dunno who made this :b
- stock isNumeric(const string[])
- {
- new length=strlen(string);
- if (length==0) return false;
- for (new i = 0; i < length; i++)
- {
- if (
- (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
- || (string[i]=='-' && i!=0) // A '-' but not at first.
- || (string[i]=='+' && i!=0) // A '+' but not at first.
- ) return false;
- }
- if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment