Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Haus-System v2.0.1
- * Copyright by Piet_Meier, 2012
- */
- #include <a_samp>//normal
- #include <ocmd>//commands
- #include <dini>//zum speichern
- #define MAX_HOUSES 5//maximale häuser bis 100st wegen MAP ICONS.
- #define GRUN 0x00CA00FF
- #define ROT 0xFF1A24FF
- #define DIALOG_HAUS 13466//hier deine Freie Dialog ID eintragen
- #define SpielerName(%0) Player[%0][Name]
- new Text3D:Label[MAX_HOUSES];//3D Label vom Haus
- new HousePickup[MAX_HOUSES];//Haus Pickup
- enum HausEnum
- {
- Float:infox,
- Float:infoy,
- Float:infoz,
- Float:rx,
- Float:ry,
- Float:rz,
- Float:hx,
- Float:hy,
- Float:hz,
- int,
- preis,
- besitzer[MAX_PLAYER_NAME],
- besetzt
- };
- enum SpielerEnum
- {
- Haus,//abfrage ob jemand in einem Haus ist
- HausJA,//abfrage ob jemand ein haus besitzt
- HausNR,//Nr des Hauses
- Name[MAX_PLAYER_NAME]//Name des Spielers
- };
- new h[MAX_HOUSES][HausEnum],
- Player[MAX_PLAYERS][SpielerEnum];
- //Haus h=daten
- public OnFilterScriptInit()
- {
- print("\nHaus system by Piet™ v2.0.1\n");
- if(!dini_Exists("/Player_House_Data.ini"))dini_Create("/Player_House_Data.ini");
- LoadHouse();//lädt alle Häuser
- return 1;
- }
- public OnFilterScriptExit()
- {
- SaveHouse();//speichert alle Häuser
- return 1;
- }
- public OnPlayerConnect(playerid)//Mapicon
- {
- GetPlayerName(playerid, SpielerName(playerid), MAX_PLAYER_NAME);
- new str[32];
- format(str, 32, "%s_HausJA", SpielerName(playerid));
- Player[playerid][HausJA] = dini_Int("/Player_House_Data.ini", str);
- format(str, 32, "%s_HausNR", SpielerName(playerid));
- Player[playerid][HausNR] = dini_Int("/Player_House_Data.ini", str);
- for(new o=0; o<MAX_HOUSES; o++)
- {
- if(!h[o][besetzt])SetPlayerMapIcon(playerid, o, h[o][infox], h[o][infoy], 13.5, 31,0,MAPICON_LOCAL);
- else SetPlayerMapIcon(playerid, o, h[o][infox], h[o][infoy], 13.5, 32,0,MAPICON_LOCAL);
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new str[32];
- format(str, 32, "%s_HausJA", SpielerName(playerid));
- dini_IntSet("/Player_House_Data.ini", str, Player[playerid][HausJA]);
- format(str, 32, "%s_HausNR", SpielerName(playerid));
- dini_IntSet("/Player_House_Data.ini", str, Player[playerid][HausNR]);
- return 1;
- }
- ocmd:setposr(playerid,params[])//position wenn mann aus dem haus raus geht
- {
- new o;
- if(!isPlayerAnAdmin(playerid, 4))return SendClientMessage(playerid,ROT,"Du bist kein Adminstrator.");
- if(sscanf(params,"i",o))return SendClientMessage(playerid,ROT,"/setposr [hausid]");
- if(o>MAX_HOUSES||o<0)return SendClientMessage(playerid,ROT,"Das Haus existiert nicht.");
- GetPlayerPos(playerid, h[o][rx], h[o][ry], h[o][rz]);
- return 1;
- }
- ocmd:setposi(playerid,params[])//informationen position setzen
- {
- new o;
- if(!isPlayerAnAdmin(playerid, 4))return SendClientMessage(playerid,ROT,"Du bist kein Adminstrator");
- if(sscanf(params,"i",o))return SendClientMessage(playerid,ROT,"/setposi [hausid]");
- if(o>MAX_HOUSES||o<0)return SendClientMessage(playerid,ROT,"Das Haus existiert nicht.");
- GetPlayerPos(playerid, h[o][infox], h[o][infoy], h[o][infoz]);
- UpdateHouse(o);
- return 1;
- }
- ocmd:setposh(playerid,params[])//haus position vom interior und pos wenn mann rein geht
- {
- new o;
- if(!isPlayerAnAdmin(playerid, 4))return SendClientMessage(playerid,ROT,"Du bist kein Adminstrator");
- if(sscanf(params,"i",o))return SendClientMessage(playerid,ROT,"/setposh [hausid]");
- if(o>MAX_HOUSES||o<0)return SendClientMessage(playerid,ROT,"Das Haus existiert nicht.");
- GetPlayerPos(playerid, h[o][hx], h[o][hy], h[o][hz]);
- h[o][int] = GetPlayerInterior(playerid);
- return 1;
- }
- ocmd:setprice(playerid,params[])//preis setzten
- {
- new p, o;
- if(!isPlayerAnAdmin(playerid, 4))return SendClientMessage(playerid,ROT,"Du bist kein Adminstrator");
- if(sscanf(params,"ii",o,p))return SendClientMessage(playerid,ROT,"/setprice [hausid] [preis]");
- if(o>MAX_HOUSES||o<0)return SendClientMessage(playerid,ROT,"Das Haus existiert nicht");
- if(h[o][besetzt])return SendClientMessage(playerid,ROT,"Das Haus steht nicht zum Verkauf");
- if(p<1000||p>1000000)return SendClientMessage(playerid,ROT,"Min 1.000€ , Max 1.000.000€");
- //Preis wird jetzt gesetzt
- h[o][preis] = p;
- new string[128];
- format(string, sizeof(string), "Du hast den Preis vom Haus %d auf %d€ gesetzt", o, h[o][preis]);
- SendClientMessage(playerid, GRUN, string);
- UpdateHouse(o);
- return 1;
- }
- ocmd:sellhaus(playerid,params[])//haus verkaufen
- {
- new p;
- if(sscanf(params,"i",p))return SendClientMessage(playerid,ROT,"/sellhaus [preis]");
- if(!Player[playerid][HausJA])return SendClientMessage(playerid,ROT,"Sie besitzen kein Haus.");
- if(p<1000||p>1000000)return SendClientMessage(playerid,ROT,"Min 1.000€ , Max 1.000.000€.");
- new o = Player[playerid][HausNR];
- h[o][besetzt] = 0;
- Player[playerid][HausJA] = 0;
- Player[playerid][HausNR] = -1;
- h[o][preis] = p;
- GivePlayerMoney(playerid, p);
- UpdateHouse(o);
- return 1;
- }
- ocmd:buyhaus(playerid,params[])//haus kaufen
- {
- new o;
- if(sscanf(params,"i",o))return SendClientMessage(playerid,ROT,"/buyhaus [id]");
- if(Player[playerid][HausJA])return SendClientMessage(playerid,ROT,"Sie besitzen bereits ein Haus.");
- if(o>MAX_HOUSES||o<0)return SendClientMessage(playerid,ROT,"Das Haus existiert nicht.");
- if(h[o][besetzt])return SendClientMessage(playerid,ROT,"Das Haus steht nicht zum Verkauf.");
- new string[256];
- format(string, sizeof(string), "Sie Brauchen mindestens %d€ um Haus %d kaufen zu können.", h[o][preis]);
- if(GetPlayerMoney(playerid)<h[o][preis])return SendClientMessage(playerid,ROT,string);
- //Haus wird jetzt gekauft
- format(h[o][besitzer], MAX_PLAYER_NAME, "%s", SpielerName(playerid));
- Player[playerid][HausJA] = 1;
- Player[playerid][HausNR] = o;
- GivePlayerMoney(playerid, -h[o][preis]);
- h[o][besetzt] = 1;
- new str[128];
- format(str, sizeof(str), "%s hat das Haus NR %d gekauft", SpielerName(playerid));
- SendClientMessageToAll(GRUN, str);
- format(str, sizeof(str), "Du hast das Haus %d für %d gekauft", o, h[o][preis]);
- SendClientMessage(playerid, GRUN, str);
- UpdateHouse(o);
- h[o][preis] = 0;
- //haus gekauft
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])//alle commands
- {
- if(!strcmp("/hhelp", cmdtext, true))
- {
- ShowPlayerDialog(playerid,DIALOG_HAUS,DIALOG_STYLE_MSGBOX ,"Haus Help","/exit um haus zu verlassen \n/setposi um die Info zu versetzen \nsetposh um die Position vom haus interior und anderemzu versetzen \nsetposr um die position wenn mann raus kommt zu setzen \n/setprice um den preis des hauses zu setzen \n/buyhaus um ein haus zu kaufen \n/sellhaus um sein haus zu verkaufen","Ok","Cancel");
- return 1;
- }
- if(!strcmp("/exit", cmdtext, true))
- {
- if(Player[playerid][Haus])
- {
- new o=Player[playerid][HausNR];
- SetPlayerPos(playerid, h[o][rx], h[o][ry], h[o][rz]);
- SetPlayerInterior(playerid, 0);
- SendClientMessage(playerid, GRUN, "Du bist raus aus deinem Haus.");
- Player[playerid][Haus] = 0;
- }
- else SendClientMessage(playerid, ROT, "Sie sind in keinem Haus.");
- return 1;
- }
- return 0;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)//wenn die person in den pickup vom haus geht
- {
- for(new o=0; o<MAX_HOUSES; o++)
- {
- if(pickupid==HousePickup[o] && o==Player[playerid][HausNR])
- {
- SetPlayerPos(playerid, h[o][hx], h[o][hy], h[o][hz]);
- SetPlayerInterior(playerid, h[o][int]);
- SendClientMessage(playerid, GRUN, "Willkommen in deinem Haus.");
- Player[playerid][Haus] = 1;
- return 1;
- }
- }
- return 1;
- }
- stock UpdateHouse(o)//updatet das Haus
- {
- new str[512];
- DestroyPickup(HousePickup[o]);
- if(h[o][besetzt])
- {
- format(str, sizeof(str), "Haus-NR:%d \nBesitzer:%s \nBesetzt[ja] \nPreis:verkauft", o, h[o][besitzer]);
- Delete3DTextLabel(Label[o]);
- Label[o]=Create3DTextLabel(str, GRUN, h[o][infox], h[o][infoy], h[o][infoz], 7, 0);
- HousePickup[o]=CreatePickup(1273, 1, h[o][infox], h[o][infoy], h[o][infoz]);
- }
- else if(!h[o][besetzt])
- {
- format(str, sizeof(str), "Haus-NR:%d \nBesitzer:Niemand \nBesetzt[nein] \nPreis:%d€", o, h[o][preis]);
- Delete3DTextLabel(Label[o]);
- Label[o]=Create3DTextLabel(str, GRUN, h[o][infox], h[o][infoy], h[o][infoz], 7, 0);
- HousePickup[o]=CreatePickup(1272, 1, h[o][infox], h[o][infoy], h[o][infoz]);
- }
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(!h[o][besetzt])SetPlayerMapIcon(i, o, h[o][infox], h[o][infoy], 13.5, 31,0,MAPICON_LOCAL);
- else SetPlayerMapIcon(i, o, h[o][infox], h[o][infoy], 13.5, 32,0,MAPICON_LOCAL);
- }
- return 1;
- }
- stock LoadHouse()//Lädt alle Häuser
- {
- new load;
- for(new o=0; o<MAX_HOUSES; o++)
- {
- new dat[64], string[512];
- format(dat,sizeof(dat),"/House/%d.enumdat",o);
- if(!dini_Exists(dat)){printf("House %d doesn't exists.", o);continue;}
- printf("loadet %d from %s", o, dat);
- h[o][besetzt] = dini_Int(dat, "besetzt");
- format(h[o][besitzer], MAX_PLAYER_NAME, "%s", dini_Get(dat, "Besitzer"));
- if(!h[o][besetzt])
- {
- format(string, sizeof(string), "Haus-NR:%d \nBesitzer:Niemand \nBesetzt[nein] \nPreis:%d", o, dini_Int(dat, "preis"));
- HousePickup[o]=CreatePickup(1273, 1, h[o][infox], h[o][infoy], h[o][infoz]);
- }
- else if(h[o][besetzt])
- {
- format(string, sizeof(string), "Haus-NR:%d \nBesitzer:%s \nBesetzt[ja] \nPreis:verkauft", o, dini_Get(dat, "Besitzer"));
- HousePickup[o]=CreatePickup(1272, 1, h[o][infox], h[o][infoy], h[o][infoz]);
- }
- h[o][hx] = dini_Float(dat, "x");
- h[o][hy] = dini_Float(dat, "y");
- h[o][hz] = dini_Float(dat, "z");
- h[o][infox] = dini_Float(dat, "infox");
- h[o][infoy] = dini_Float(dat, "infoy");
- h[o][infoz] = dini_Float(dat, "infoz");
- h[o][rx] = dini_Float(dat, "rx");
- h[o][ry] = dini_Float(dat, "ry");
- h[o][rz] = dini_Float(dat, "rz");
- h[o][preis] = dini_Int(dat, "preis");
- h[o][int] = dini_Int(dat, "int");
- Label[o]=Create3DTextLabel(string, GRUN, h[o][infox], h[o][infoy], h[o][infoz], 7, 0);
- load++;
- }
- printf("Loadet %d Houses", load);
- return 1;
- }
- stock SaveHouse()//Speichert alle Häuser
- {
- new load;
- for(new o=0; o<MAX_HOUSES; o++)
- {
- new dat[64];
- format(dat,sizeof(dat),"/House/%d.enumdat",o);
- printf("save %d to %s", o, dat);
- if(!dini_Exists(dat))dini_Create(dat);
- dini_FloatSet(dat, "x", h[o][hx]);
- dini_FloatSet(dat, "y", h[o][hy]);
- dini_FloatSet(dat, "z", h[o][hz]);
- dini_FloatSet(dat, "rx", h[o][rx]);
- dini_FloatSet(dat, "ry", h[o][ry]);
- dini_FloatSet(dat, "rz", h[o][rz]);
- dini_FloatSet(dat, "infox", h[o][infox]);
- dini_FloatSet(dat, "infoy", h[o][infoy]);
- dini_FloatSet(dat, "infoz", h[o][infoz]);
- dini_IntSet(dat, "int", h[o][int]);
- dini_IntSet(dat, "preis", h[o][preis]);
- dini_Set(dat, "Besitzer", h[o][besitzer]);
- dini_IntSet(dat, "besetzt", h[o][besetzt]);
- load++;
- }
- printf("Save %d Houses", load);
- return 1;
- }
- stock isPlayerAnAdmin(playerid, rang)//ob spieler ein admin ist
- {
- #pragma unused rang
- if(IsPlayerAdmin(playerid))return 1;
- return 0;
- }
- stock sscanf(sstring[], format[], {Float,_}:...)//sscanf für die ocmd befehle
- {
- #if defined isnull
- if (isnull(sstring))
- #else
- if (sstring[0] == 0 || (sstring[0] == 1 && sstring[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- sstringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (sstring[sstringPos] && sstring[sstringPos] <= ' ')
- {
- sstringPos++;
- }
- while (paramPos < paramCount && sstring[sstringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = sstring[sstringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = sstring[++sstringPos];
- }
- do
- {
- sstringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = sstring[sstringPos];
- do
- {
- sstringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, sstring[sstringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = sstringPos;
- while(changepos < 16 && sstring[strpos] && sstring[strpos] != delim)
- {
- changestr[changepos++] = sstring[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(sstring, format[formatPos], false, sstringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- sstringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = sstringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = sstring[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- sstring[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - sstringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, sstring[sstringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- sstring[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- sstringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = sstring[sstringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = sstring[sstringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- sstringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (sstring[sstringPos] && sstring[sstringPos] != delim && sstring[sstringPos] > ' ')
- {
- sstringPos++;
- }
- while (sstring[sstringPos] && (sstring[sstringPos] == delim || sstring[sstringPos] <= ' '))
- {
- sstringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement