Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <ocmd>
- /* Settings */
- // Bitte anpassen!
- #define MAX_PLANTS 50 //Maximale Plantagen insgesamt
- #define ReifZeit 30 //Zeit in Minute, die die Plantagen reifen müssen
- #define Drugs 1000 //Drogen in Gramm, die der Spieler bekommt, wenn er Drogen erntet ( in PVars! "Drogen" )
- #define SamenKosten 500 //Preis pro 10 Samen (PVars! "Samen")
- #define D_FILE "/Plantagen.ini" //Datei, wo die Drogen gespeichert werden sollen.
- stock bool:IsCop(playerid){
- switch(GetPVarInt(playerid,"Fraktion")){
- case 1,2,3:return true; //Hier die Copfraktionen eintragen
- default: return false;
- }
- return false;
- }
- /* Settings */
- //Farben
- #define Schwarz 0x000000FF
- #define Rot 0xE10000FF
- #define Gelb 0xFFE600FF
- #define HBlau 0x00FFFFFF
- #define DBlau 0x0000FFFF
- #define Blau 0x2E9AFEFF
- #define HGruen 0x00FF00FF
- #define HHGruen 0xCDFF00FF
- #define Orange 0xFFAB00FF
- #define Weiss 0xFFFFFFFF
- #define Grau 0xDCDCDCFF
- #define Lila 0x8C00FFFF
- new fmex[128];
- #define D_SCM(%0,%1,%2) format(fmex,128,%2) && SendClientMessage(%0,%1,fmex)
- forward ZeitTimer_(plant);
- enum EPlantage
- {
- d_besitzer[MAX_PLAYER_NAME],
- d_zeit,
- Float:d_pos[3],
- d_obj,
- d_timer,
- Text3D:d_label,
- bool:d_erstellt
- }
- new Plantage[MAX_PLANTS][EPlantage];
- public OnFilterScriptInit(){
- print("\n--------------------------------------");
- print(" Drogensystem by ErikSon");
- print("--------------------------------------\n");
- if(!fexist(D_FILE))SavePlants();
- return LoadPlants();
- }
- public OnFilterScriptExit()return SavePlants(),DestroyPlants();
- //Befehle
- ocmd:buysamen(playerid){
- if(GetPlayerMoney(playerid) < SamenKosten)return D_SCM(playerid,Rot,"Du hast nicht genug Geld bei! Benötigt: %i$",SamenKosten);
- D_SCM(playerid,Blau,"*Du hast dir 10 Samen für %i$ gekauft.*",SamenKosten);
- SetPVarInt(playerid,"Samen",GetPVarInt(playerid,"Samen") +10);
- return GivePlayerMoney(playerid,-SamenKosten);
- }
- ocmd:plantdrugs(playerid){
- new Float:x,Float:y,Float:z,string[64],i = 0;
- GetPlayerPos(playerid,x,y,z);
- if(GetPVarInt(playerid,"Samen") < 10)return D_SCM(playerid,Rot,"*Du besitzt nicht genug Samen! Benötigt: 10 | Besitz: %i*",GetPVarInt(playerid,"Samen"));
- for(; i<MAX_PLANTS; i++){
- if(Plantage[i][d_erstellt])continue;
- Plantage[i][d_obj] = CreateObject(822,x,y,z,0,0,0,100);
- format(Plantage[i][d_besitzer],MAX_PLAYER_NAME,"%s",SpielerName(playerid));
- Plantage[i][d_pos][0] = x,
- Plantage[i][d_pos][1] = y,
- Plantage[i][d_pos][2] = z,
- Plantage[i][d_zeit] = 0,
- Plantage[i][d_erstellt] = true;
- format(string,64,"Besitzer: '%s'\nZeit: %i / %i Minuten",Plantage[i][d_besitzer],Plantage[i][d_zeit],ReifZeit);
- Plantage[i][d_label] = Create3DTextLabel(string,Weiss,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2],50,0,1);
- Plantage[i][d_timer] = SetTimerEx("ZeitTimer_",1000*60,true,"i",i);
- SetPVarInt(playerid,"Samen",GetPVarInt(playerid,"Samen") -10);
- SendClientMessage(playerid,Blau,"*Du hast dir erfolgreich eine Plantage angebaut.*");
- return D_SCM(playerid,Blau,"*Du musst nun %i Minuten warten, bis die Drogen reif sind.*",ReifZeit);
- }
- return 1;
- }
- ocmd:takepdrugs(playerid){
- new i = 0;
- for(; i<MAX_PLANTS; i++){
- if(Plantage[i][d_erstellt] != true)continue;
- if(!IsPlayerInRangeOfPoint(playerid,5,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]))continue;
- if(strcmp(Plantage[i][d_besitzer],SpielerName(playerid)))continue;
- else if(Plantage[i][d_zeit] < ReifZeit)return SendClientMessage(playerid,Rot,"*Die Plantage ist noch nicht ausgereift!*");
- DestroyObject(Plantage[i][d_obj]),Delete3DTextLabel(Plantage[i][d_label]);
- Plantage[i][d_pos][0] = 0,Plantage[i][d_pos][1] = 0,Plantage[i][d_pos][2] = 0,Plantage[i][d_erstellt] = false;
- D_SCM(playerid,Blau,"*Du hast die Drogen der Plantage genommen und erhälst %i Gramm Drogen*",Drugs);
- return SetPVarInt(playerid,"Drogen",GetPVarInt(playerid,"Drogen") +Drugs);
- }
- return 1;
- }
- ocmd:removeplant(playerid){
- new i = 0;
- for(; i<MAX_PLANTS; i++){
- if(Plantage[i][d_erstellt] != true)continue;
- if(!IsPlayerInRangeOfPoint(playerid,5,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]))continue;
- if(strcmp(Plantage[i][d_besitzer],SpielerName(playerid)) && !IsCop(playerid))continue;
- Plantage[i][d_pos][0] = 0,Plantage[i][d_pos][1] = 0,Plantage[i][d_pos][2] = 0,Plantage[i][d_erstellt] = false;
- DestroyObject(Plantage[i][d_obj]), Delete3DTextLabel(Plantage[i][d_label]);
- return SendClientMessage(playerid,Blau,"*Du hast die Plantage erfolgreich entfernt.*");
- }
- return 1;
- }
- ocmd:planthelp(playerid)return SendClientMessage(playerid,-1,"'/buysamen' | '/plantdrugs' | '/takepdrugs' | '/removeplant'");
- public ZeitTimer_(plant){
- if(Plantage[plant][d_zeit] ++ >= ReifZeit){
- Plantage[plant][d_zeit] ++;
- SendClientMessage(Plantage[plant][d_besitzer],Blau,"*Deine Plantage ist nun reif. Du kannst die Drogen mit >/takepdrugs< an dich nehmen.*");
- return KillTimer(Plantage[plant][d_timer]);
- }
- Plantage[plant][d_zeit] ++;
- new string[64]; format(string,sizeof(string),"Besitzer: '%s'\nZeit: %i / %i Minuten",Plantage[plant][d_besitzer],Plantage[plant][d_zeit]);
- return Update3DTextLabelText(Plantage[plant][d_label],Weiss,string);
- }
- stock SpielerName(playerid){
- new GetName[MAX_PLAYER_NAME];
- GetPlayerName(playerid,GetName,sizeof(GetName));
- return GetName;
- }
- stock LoadPlants(){
- if(!fexist(D_FILE)){
- new File:tfFile=fopen(D_FILE,io_write);
- fclose(tfFile);
- }
- new File:fFile=fopen(D_FILE,io_read),Content[128],i,string[64];
- while(fread(fFile,Content))
- {
- StripNewLine(Content);
- d_sscanf(Content,"sifff",Plantage[i][d_besitzer],Plantage[i][d_zeit],Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]);
- Plantage[i][d_obj] = CreateObject(822,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2],0,0,0,100);
- Plantage[i][d_erstellt] = true;
- format(string,64,"Besitzer: '%s'\nZeit: %i / %i Minuten",Plantage[i][d_besitzer],Plantage[i][d_zeit],ReifZeit);
- Plantage[i][d_label] = Create3DTextLabel(string,Weiss,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2],50,0,1);
- Plantage[i][d_timer] = SetTimerEx("ZeitTimer_",1000*60,true,"i",i);
- i++;
- }
- fclose(fFile);
- return printf(" '%d' Plantage(n) wurde(n) geladen & erstellt.",i++);
- }
- stock SavePlants(){
- if(fexist(D_FILE))fremove(D_FILE);
- new File:fFile=fopen(D_FILE,io_append),Content[128];
- new i;while(i<MAX_PLANTS)
- {
- if(Plantage[i][d_erstellt])
- {
- format(Content,sizeof(Content),"%s %i %f %f %f\r\n",Plantage[i][d_besitzer],Plantage[i][d_zeit],Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]);
- fwrite(fFile,Content);
- }i++;
- }return fclose(fFile);
- }
- stock DestroyPlants(){
- for(new i = 0; i<MAX_PLANTS; i++){
- DestroyObject(Plantage[i][d_obj]);
- Delete3DTextLabel(Plantage[i][d_label]);
- }
- return 1;
- }
- stock StripNewLine(string[]){
- new len=strlen(string);
- if(string[0]==0)return;if((string[len-1]=='\n')||(string[len-1]=='\r')){
- string[len-1]=0; if(string[0]==0) return; if((string[len-2]=='\n')||(string[len-2]=='\r'))string[len-2]=0;
- }
- }
- stock d_sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- 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 = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[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(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++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
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- 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