Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- "Killable Cows" v0.1 by ~AWESOME~
- 17.12.2010
- Changelog:
- o Added Counters
- */
- #include <a_samp>
- #define SCRIPT_VERSION "0.1"
- #define MAX_COWS 3
- #define FILE_COWS "KillableCows.txt"
- #define COLOR_RED 0xFF0000AA
- #define COLOR_ORANGE 0xFF9900AA
- #define IsPlayerSpawned(%1) IsPlayerSpawned[%1]
- #define IsCowConnected(%1) CowInfo[%1][IsValid]
- #define GetDistanceBetweenCoords(%1,%2,%3,%4,%5,%6) floatsqroot((%4 - %1)*(%4 - %1) + (%5 - %2)*(%5 - %2) + (%6 - %3)*(%6 - %3))
- #if !defined dcmd
- #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
- #endif
- enum cowinfos
- {
- iObjectID,
- Float:sX,
- Float:sY,
- Float:sZ,
- Float:Angle[3],
- IsDead,
- IsValid
- }
- new CowInfo[MAX_COWS][cowinfos];
- new bool:IsPlayerSpawned[MAX_PLAYERS];
- forward LoadCows();
- forward OnCowConnect(CowID);
- stock Float:GetDistanceToObject(playerid,objectid)
- {
- new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
- GetPlayerPos(playerid,x1,y1,z1);
- GetObjectPos(objectid,x2,y2,z2);
- return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- }
- public OnFilterScriptInit()
- {
- printf(".:: Killable Cows v%s by ~AWESOME~ loaded ::.",SCRIPT_VERSION);
- LoadCows();
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new id = 0; id < MAX_PLAYERS; id++)
- {
- DestroyObject(CowInfo[id][iObjectID]);
- }
- return 1;
- }
- public LoadCows()
- {
- new File:cowfile, string[128], data[26][32], count;
- if(fexist(FILE_COWS))
- {
- cowfile = fopen(FILE_COWS,io_read);
- for(new id = 0; id < MAX_COWS; id++)
- {
- fread(cowfile,string);
- OnCowConnect(id);
- if(!strlen(string))
- {
- CowInfo[id][IsValid] = 0;
- continue;
- }
- split(string,data,',');
- CowInfo[id][IsValid] = 1;
- CowInfo[id][IsDead] = 0;
- CowInfo[id][sX] = floatstr(data[0]);
- CowInfo[id][sY] = floatstr(data[1]);
- CowInfo[id][sZ] = floatstr(data[2]);
- CowInfo[id][Angle][0] = floatstr(data[3]);
- CowInfo[id][Angle][1] = floatstr(data[4]);
- CowInfo[id][Angle][2] = floatstr(data[5]);
- 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]);
- count++;
- }
- if(!count) print("» ERROR: Cows couldn't be loaded");
- else printf("» %d Cows loaded.",count);
- fclose(cowfile);
- }
- else print("» ERROR: Cows couldn't be loaded");
- return 1;
- }
- public OnCowConnect(CowID)
- {
- CowInfo[CowID][iObjectID] = -1;
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- new wstate = GetPlayerWeaponState(playerid);
- if(newkeys & KEY_FIRE && GetPlayerWeapon(playerid) != 0 && IsPlayerSpawned(playerid))
- {
- if(wstate != WEAPONSTATE_RELOADING || wstate != WEAPONSTATE_NO_BULLETS)
- {
- new Float:X,
- Float:Y,
- Float:Z,
- Float:Distance,
- CowID = GetPlayerClosestCow(playerid);
- Distance = GetDistanceToObject(playerid,CowInfo[CowID][iObjectID]);
- GetPosFromView(playerid,Distance,X,Y,Z);
- if(ObjectToPoint(3.0,CowInfo[CowID][iObjectID],X,Y,Z) != 0)
- {
- KillCow(CowID);
- }
- }
- }
- return 0;
- }
- public OnPlayerCommandText(playerid,cmdtext[])
- {
- dcmd(respawncows,11,cmdtext);
- return 0;
- }
- dcmd_respawncows(playerid,params[])
- {
- #pragma unused params
- new string[100], count = 0;
- if(IsPlayerAdmin(playerid))
- {
- if(CountCows() == 0)
- {
- SendClientMessage(playerid,COLOR_RED,"» There aren't any cows connected!");
- return 1;
- }
- for(new id = 0; id < MAX_COWS; id++)
- {
- if(IsCowConnected(id))
- {
- if(CowInfo[id][IsDead])
- {
- SetObjectPos(CowInfo[id][iObjectID], CowInfo[id][sX], CowInfo[id][sY], CowInfo[id][sZ]);
- SetObjectRot(CowInfo[id][iObjectID], CowInfo[id][Angle][0], CowInfo[id][Angle][1], CowInfo[id][Angle][2]);
- CowInfo[id][IsDead] = 0;
- count++;
- }
- }
- }
- if(!count)
- {
- SendClientMessage(playerid,COLOR_ORANGE,"» There is no dead cow!");
- return 1;
- }
- format(string,sizeof(string),"» %d Cows respawned.",count);
- SendClientMessage(playerid,COLOR_ORANGE,string);
- }
- else SendClientMessage(playerid,COLOR_RED,"» You aren't an administrator!");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- IsPlayerSpawned(playerid) = false;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- IsPlayerSpawned(playerid) = true;
- return 1;
- }
- public OnPlayerDeath(playerid,killerid,reason)
- {
- IsPlayerSpawned(playerid) = false;
- return 1;
- }
- stock KillCow(CowID)
- {
- CowInfo[CowID][IsDead] = 1;
- if(wait(3))
- {
- SetObjectRot(CowInfo[CowID][iObjectID], 90.0, CowInfo[CowID][Angle][1], CowInfo[CowID][Angle][2]);
- SetObjectPos(CowInfo[CowID][iObjectID], CowInfo[CowID][sX], CowInfo[CowID][sY], CowInfo[CowID][sZ] - 1.25);
- }
- return 1;
- }
- stock CountCows()
- {
- new cowcount = 0;
- for(new i = 0; i < MAX_COWS; i++)
- {
- if(IsCowConnected(i))
- {
- cowcount++;
- }
- }
- return cowcount;
- }
- stock ObjectToPoint(Float:Scale, ObjectID, Float:X, Float:Y, Float:Z)
- {
- new Float:oldposx, Float:oldposy, Float:oldposz, Float:tempposx, Float:tempposy, Float:tempposz;
- GetObjectPos(ObjectID, oldposx, oldposy, oldposz);
- tempposx = (oldposx -X);
- tempposy = (oldposy -Y);
- tempposz = (oldposz -Z);
- if(((tempposx < Scale) && (tempposx > -Scale)) && ((tempposy < Scale) && (tempposy > -Scale)) && ((tempposz < Scale) && (tempposz > -Scale)))
- {
- return 1;
- }
- return 0;
- }
- stock GetPosFromView(playerid, Float:Distance, &Float:X, &Float:Y, &Float:Z)
- {
- new Float:cx,
- Float:cy,
- Float:cz,
- Float:fx,
- Float:fy,
- Float:fz;
- GetPlayerCameraPos(playerid,cx,cy,cz);
- GetPlayerCameraFrontVector(playerid,fx,fy,fz);
- X = fx * Distance + cx;
- Y = fy * Distance + cy;
- Z = fz * Distance + cz;
- return 1;
- }
- stock split(const strsrc[], strdest[][], delimiter)
- {
- new i, li;
- new aNum;
- new len;
- while(i <= strlen(strsrc))
- {
- if(strsrc[i] == delimiter || i == strlen(strsrc))
- {
- len = strmid(strdest[aNum], strsrc, li, i, 128);
- strdest[aNum][len] = 0;
- li = i+1;
- aNum++;
- }
- i++;
- }
- return 1;
- }
- stock wait(time)
- {
- new stamp = tickcount();
- while (tickcount() - stamp < time){}
- return 1;
- }
- stock GetPlayerClosestCow(playerid)
- {
- new cid = -1,
- Float:distance = 69000.0,
- Float:tmp[7];
- GetPlayerPos(playerid,tmp[0],tmp[1],tmp[2]);
- for(new id = 0; id < MAX_COWS; id++)
- {
- if(!IsCowConnected(id)) continue;
- if(CowInfo[id][IsDead]) continue;
- tmp[3] = CowInfo[id][sX];
- tmp[4] = CowInfo[id][sY];
- tmp[5] = CowInfo[id][sZ];
- tmp[6] = GetDistanceBetweenCoords(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
- if(distance < tmp[6]) continue;
- distance = tmp[6];
- cid = id;
- }
- return cid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement