Guest User

.:: ~AWeSoMe~ ::.

a guest
Dec 16th, 2010
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.55 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define SCRIPT_VERSION  "0.1"
  4. #define MAX_COWS        25
  5. #define FILE_COWS       "KillableCows.txt"
  6.  
  7. #define COLOR_RED       0xFF0000AA
  8. #define COLOR_ORANGE    0xFF9900AA
  9.  
  10. #if !defined dcmd
  11.     #define dcmd(%1,%2,%3) if((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  12. #endif
  13.  
  14. enum cowinfos
  15. {
  16.     iObjectID,
  17.     Float:sX,
  18.     Float:sY,
  19.     Float:sZ,
  20.     Float:Angle[3],
  21.     IsDead
  22. }
  23.  
  24. new CowInfo[MAX_COWS][cowinfos];
  25. new bool:IsPlayerSpawned[MAX_PLAYERS];
  26.  
  27. forward LoadCows();
  28.  
  29. public OnFilterScriptInit()
  30. {
  31.     new string[128];
  32.     format(string,sizeof(string),".:: Killable Cows v%d by ~AWESOME~ loaded ::.\n",SCRIPT_VERSION);
  33.     print(string);
  34.     LoadCows();
  35. }
  36.  
  37. public LoadCows()
  38. {
  39.     new File:cowfile, string[128], data[26][32], count = 0;
  40.     if(fexist(FILE_COWS))
  41.     {
  42.         cowfile = fopen(FILE_COWS,io_read);
  43.         for(new id = 0; id < MAX_COWS; id++)
  44.         {
  45.             fread(cowfile,string);
  46.             split(string,data,',');
  47.             CowInfo[id][IsDead] = 0;
  48.             CowInfo[id][sX] = floatstr(data[0]);
  49.             CowInfo[id][sY] = floatstr(data[1]);
  50.             CowInfo[id][sZ] = floatstr(data[2]);
  51.             CowInfo[id][Angle][0] = floatstr(data[3]);
  52.             CowInfo[id][Angle][1] = floatstr(data[4]);
  53.             CowInfo[id][Angle][2] = floatstr(data[5]);
  54.             CowInfo[id][iObjectID] = CreateObject(16442,CowInfo[id][sX],CowInfo[id][sY],CowInfo[id][sZ],CowInfo[id][Angle][0],CowInfo[id][Angle][1],CowInfo[id][Angle][2]);
  55.             count++;
  56.         }
  57.         printf(">=== Cows loaded\n",count);
  58.         fclose(cowfile);
  59.     }
  60.     else
  61.     {
  62.         print(">=== ERROR: Cows couldn't be loaded\n");
  63.     }
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  68. {
  69.     if(newkeys == KEY_FIRE && GetPlayerWeapon(playerid) != 0 && IsPlayerSpawned[playerid] == true)
  70.     {
  71.         new Float:X,
  72.             Float:Y,
  73.             Float:Z;
  74.         GetPosFromView(playerid,80.0,X,Y,Z);
  75.         for(new id = 0; id < MAX_COWS; id++)
  76.         {
  77.             if(ObjectToPoint(playerid,4.0,CowInfo[id][iObjectID],X,Y,Z) != 0)
  78.             {
  79.                 if(CowInfo[id][IsDead] == 0)
  80.                 {
  81.                     KillCow(id);
  82.                 }
  83.             }
  84.         }
  85.     }
  86.     return 0;
  87. }
  88.  
  89. public OnPlayerCommandText(playerid,cmdtext[])
  90. {
  91.     dcmd(respawncows,11,cmdtext);
  92.     return 0;
  93. }
  94.  
  95. dcmd_respawncows(playerid,params[])
  96. {
  97.     #pragma unused params
  98.     new string[100], count = 0;
  99.     for(new id = 0; id < MAX_COWS; id++)
  100.     {
  101.         if(CowInfo[id][IsDead] == 1)
  102.         {
  103.             SetObjectPos(CowInfo[id][iObjectID], CowInfo[id][sX], CowInfo[id][sY], CowInfo[id][sZ]);
  104.             SetObjectRot(CowInfo[id][iObjectID], CowInfo[id][Angle][0], CowInfo[id][Angle][1], CowInfo[id][Angle][2]);
  105.             CowInfo[id][IsDead] = 0;
  106.             count++;
  107.         }
  108.     }
  109.     format(string,sizeof(string),">> %d Cows respawnt.",count);
  110.     SendClientMessage(playerid,COLOR_ORANGE,string);
  111.     return 1;
  112. }
  113.  
  114. public OnPlayerConnect(playerid)
  115. {
  116.     IsPlayerSpawned[playerid] = false;
  117.     return 1;
  118. }
  119.  
  120. public OnPlayerSpawn(playerid)
  121. {
  122.     IsPlayerSpawned[playerid] = true;
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerDeath(playerid,killerid,reason)
  127. {
  128.     IsPlayerSpawned[playerid] = false;
  129.     return 1;
  130. }
  131.  
  132. stock KillCow(CowID)
  133. {
  134.     SetObjectRot(CowInfo[CowID][iObjectID], 90.0, CowInfo[CowID][Angle][1], CowInfo[CowID][Angle][2]);
  135.     SetObjectPos(CowInfo[CowID][iObjectID], CowInfo[CowID][sX], CowInfo[CowID][sY], CowInfo[CowID][sZ] - 1.25);
  136.     CowInfo[CowID][IsDead] = 0;
  137.     return 1;
  138. }
  139.  
  140. stock ObjectToPoint(playerid, Float:Distance, ObjectID, Float:X, Float:Y, Float:Z)
  141. {
  142.    new Float:oldposx, Float:oldposy, Float:oldposz, Float:tempposx, Float:tempposy, Float:tempposz;
  143.    GetPlayerObjectPos(playerid, ObjectID, oldposx, oldposy, oldposz);
  144.    tempposx = (oldposx -X);
  145.    tempposy = (oldposy -Y);
  146.    tempposz = (oldposz -Z);
  147.    if(((tempposx < Distance) && (tempposx > -Distance)) && ((tempposy < Distance) && (tempposy > -Distance)) && ((tempposz < Distance) && (tempposz > -Distance)))
  148.    {
  149.       return 1;
  150.    }
  151.    return 0;
  152. }
  153.  
  154. stock GetPosFromView(playerid, Float:Distance, &Float:X, &Float:Y, &Float:Z)
  155. {
  156.     new Float:cx,
  157.         Float:cy,
  158.         Float:cz,
  159.         Float:fx,
  160.         Float:fy,
  161.         Float:fz;
  162.     GetPlayerCameraPos(playerid,cx,cy,cz);
  163.     GetPlayerCameraFrontVector(playerid,fx,fy,fz);
  164.     X = fx * Distance + cx;
  165.     Y = fy * Distance + cy;
  166.     Z = fz * Distance + cz;
  167.     return 1;
  168. }
  169.  
  170. stock split(const strsrc[], strdest[][], delimiter)
  171. {
  172.     new i, li;
  173.     new aNum;
  174.     new len;
  175.     while(i <= strlen(strsrc))
  176.     {
  177.         if(strsrc[i] == delimiter || i == strlen(strsrc))
  178.         {
  179.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  180.             strdest[aNum][len] = 0;
  181.             li = i+1;
  182.             aNum++;
  183.         }
  184.         i++;
  185.     }
  186.     return 1;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment