Advertisement
_Rolux_

Farmer Munka v2

Jun 16th, 2018
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.55 KB | None | 0 0
  1. #include <a_samp>
  2. #include <foreach>
  3.  
  4. #define MAX_WHEAT 100
  5. #define GROW_SPEED 30000
  6. #define WHEAT_SIZE 7.59
  7.  
  8. #define PRESSED(%0) \
  9.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  10.  
  11. enum WHEAT_DATA
  12. {
  13.     Float:bX,
  14.     Float:bY,
  15.     Float:bZ,
  16.     object,
  17.     kesz,
  18.     levagva,
  19.     Text3D:btext,
  20.     felveve
  21. }
  22. new Iterator:Wheat< MAX_WHEAT >,
  23.     bInfo[MAX_WHEAT][WHEAT_DATA],
  24.     binveh[MAX_VEHICLES],
  25.     DummyWheat[WHEAT_DATA],
  26.     bt[MAX_PLAYERS];
  27.  
  28. public OnPlayerSpawn(playerid)
  29. {
  30.     SetPVarInt(playerid, "Mag", 0);
  31.     return 1;
  32. }
  33.  
  34. public OnPlayerCommandText(playerid, cmdtext[])
  35. {
  36.     if (strcmp("/mag-felvesz", cmdtext, true, 10) == 0)
  37.     {
  38.         if(GetPVarInt(playerid, "Mag") > 0) return SendClientMessage(playerid,-1,"Még van nálad mag! ");
  39.         SetPVarInt(playerid, "Mag", 30);
  40.         SendClientMessage(playerid,-1,"Kaptál 30 magot! ");
  41.         return 1;
  42.     }
  43.     if (strcmp("/lead", cmdtext, true, 10) == 0)
  44.     {
  45.         new string [128],veh = GetPlayerVehicleID(playerid);
  46.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0x00FF00AA, "Nem ülsz jármuben");
  47.  
  48.         if(binveh[veh] == 0 ) return SendClientMessage(playerid, 0x00FF00AA, "Ebben a jármuben nincs búza");
  49.         format(string,sizeof(string),"Leadtál {d0b02c}%d {ffffff}kg búzát és kapál érte {d0b02c}%d${ffffff}-t",binveh[veh],binveh[veh]*2);
  50.         SendClientMessage(playerid,0xFFFFFFAA,string);
  51.         GivePlayerMoney(playerid,binveh[veh]*2);
  52.         binveh[veh] = 0;
  53.         return 1;
  54.     }
  55.     return 0;
  56. }
  57.  
  58. public OnPlayerStateChange(playerid, newstate, oldstate)
  59. {
  60.     if(newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER)
  61.     {
  62.         bt[playerid] = SetTimerEx("CheckCombine", 200, true, "d", playerid);
  63.     }
  64.     if(newstate != PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_DRIVER)
  65.     {
  66.         KillTimer(bt[playerid]);
  67.     }
  68.     return 1;
  69. }
  70.  
  71. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  72. {
  73.     if (PRESSED(KEY_YES))
  74.     {
  75.         if (IsPlayerInAnyVehicle(playerid))
  76.         {
  77.             new vehicleid = GetPlayerVehicleID(playerid);
  78.  
  79.             if(GetVehicleModel(vehicleid) == 531)//ha traktor
  80.             {
  81.                 if(GetPVarInt(playerid, "Mag") <= 0) return SendClientMessage(playerid,-1,"Nincs nálad mag! ");
  82.  
  83.                 new str[64], Float:x, Float:y, Float:z,id = Iter_Free(Wheat),Float: speed;
  84.                 format(str,sizeof(str),"Elültettél egy magot. {d0b02c}(%d/30)",GetPVarInt(playerid, "Mag"));
  85.                 SendClientMessage(playerid,-1,str);
  86.  
  87.                 GetPlayerPos(playerid, x, y, z);
  88.                 bInfo[id][bX] = x;
  89.                 bInfo[id][bY] = y;
  90.                 bInfo[id][bZ] = z;
  91.                
  92.                 speed = WHEAT_SIZE / ( GROW_SPEED / 1000);
  93.                
  94.                 bInfo[id][object] = CreateObject(855, bInfo[id][bX], bInfo[id][bY], bInfo[id][bZ]-7.59,   0.00, 0.00, 0.00);
  95.                 MoveObject(bInfo[id][object], bInfo[id][bX], bInfo[id][bY], bInfo[id][bZ], speed);
  96.  
  97.                 SetTimerEx("GrowWheat",GROW_SPEED, false, "i", id);
  98.                 SetPVarInt(playerid, "Mag",GetPVarInt(playerid, "Mag")-1);
  99.                 Iter_Add(Wheat,id);
  100.  
  101.             }
  102.             if(GetVehicleModel(vehicleid) == 478)//ha walton
  103.             {
  104.                 foreach(new o:Wheat)
  105.                 {
  106.                     if(bInfo[o][levagva] == 1)
  107.                     {
  108.                         if(bInfo[o][felveve] == 0)
  109.                         {
  110.                             if(IsPlayerInRangeOfPoint(playerid, 5.0, bInfo[o][bX],bInfo[o][bY], bInfo[o][bZ]))
  111.                             {
  112.                                 Delete3DTextLabel(bInfo[o][btext]);
  113.                                 SendClientMessage(playerid,-1,"Felvettél 1 kg búzát");
  114.                                 binveh[vehicleid] ++;
  115.                                 new string[64];
  116.                                 format(string,sizeof(string),"Az autóban {d0b02c}%d {ffffff}kg búza van",binveh[vehicleid]);
  117.                                 SendClientMessage(playerid,0xFFFFFFAA,string);
  118.  
  119.                                 bInfo[o] = DummyWheat;
  120.                                 Iter_Remove(Wheat,o);
  121.  
  122.                             }
  123.                         }
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.     }
  129.     return 1;
  130. }
  131.  
  132. forward GrowWheat(id);
  133. public GrowWheat(id)
  134. {
  135.     bInfo[id][btext] = Create3DTextLabel("[ Búza ]", 0x919191FF, bInfo[id][bX], bInfo[id][bY], bInfo[id][bZ], 3.0, 0, 0);
  136.     bInfo[id][kesz] = 1;
  137. }
  138.  
  139. forward CheckCombine(playerid);
  140. public CheckCombine(playerid)
  141. {
  142.     new vehicleid = GetPlayerVehicleID(playerid);
  143.     if(GetVehicleModel(vehicleid) == 532)
  144.     {
  145.         foreach(new o:Wheat)
  146.         {
  147.             if(bInfo[o][kesz] == 1)
  148.             {
  149.                 if(bInfo[o][levagva] == 0)
  150.                 {
  151.                     if(IsPlayerInRangeOfPoint(playerid, 7.0, bInfo[o][bX],bInfo[o][bY], bInfo[o][bZ]))
  152.                     {
  153.                         DestroyObject(bInfo[o][object]);
  154.                         Delete3DTextLabel(bInfo[o][btext]);
  155.                         bInfo[o][levagva] = 1;
  156.                         bInfo[o][btext] = Create3DTextLabel("Levágott Búza[Flevételhez Y gomb]", 0xd8a758FF, bInfo[o][bX], bInfo[o][bY], bInfo[o][bZ], 20.0, 0, 0);
  157.                         SendClientMessage(playerid,-1,"Levágtál 1kg búzát");
  158.                     }
  159.                 }
  160.             }
  161.         }
  162.     }
  163.     return 1;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement