Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Bambi Ally!
- By Alternative112
- Do NOT recirculate without first asking me!
- */
- #include <a_samp>
- #define Holding(%0) \
- ((newkeys & (%0)) == (%0))
- new bambi;
- new bambiOwner = -1;
- new respawnTimer;
- new bool:canBambiAttack = true; //He only charges once every 5 seconds
- new bool:attacking = false; //If bambi is charging, don't make him follow the player
- new bool:canAttackPeople = true; //Can Bambi charge at players when the person who has him shoots them?
- new mapIcon = 69; //It must be unique, no other icons in your scripts must use it!
- //Where Bambi spawns - change it to wherever you like.
- //By default he spawns under the bridge that connects Red County and LV.
- new Float:spawnX = 1777.2007;
- new Float:spawnY = 595.1467;
- new Float:spawnZ = 10.5952;
- main() {
- print("||=-------------------------------=||");
- print("||= BAMBI TIME!!!! ||");
- print("||=-------------------------------=||");
- }
- forward rechargeBambi();
- public rechargeBambi() {
- attacking = false;
- canBambiAttack = true;
- return 1;
- }
- forward respawnBambi();
- public respawnBambi() {
- DestroyObject(bambi);
- bambi = CreateObject(19315, spawnX, spawnY, spawnZ, 0.0, 0.0, 0.0);
- return 1;
- }
- stock detachBambi() {
- new Float:x, Float:y, Float:z;
- GetObjectPos(bambi, x, y, z);
- DestroyObject(bambi);
- bambi = CreateObject(19315, x, y, z, 0.0, 0.0, 0.0);
- return 1;
- }
- public OnFilterScriptInit() {
- bambi = CreateObject(19315, spawnX, spawnY, spawnZ, 0.0, 0.0, 0.0);
- return 1;
- }
- public OnFilterScriptExit() {
- DestroyObject(bambi);
- for (new i = 0; i < GetMaxPlayers(); i++) {
- if (IsPlayerConnected(i)) {
- RemovePlayerMapIcon(i, mapIcon);
- }
- }
- return 1;
- }
- public OnPlayerSpawn(playerid) {
- SetPlayerMapIcon(playerid, mapIcon, spawnX, spawnY, spawnZ, 21, 0, MAPICON_LOCAL);
- if (playerid == bambiOwner) {
- respawnTimer = SetTimer("respawnBambi", 30000, false);
- bambiOwner = -1;
- detachBambi();
- }
- return 1;
- }
- public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) {
- if (canAttackPeople) {
- if (issuerid == bambiOwner && canBambiAttack && GetPlayerTeam(issuerid) != GetPlayerTeam(playerid)) {
- attacking = true;
- new Float:x, Float:y, Float:z, Float:bX, Float:bY, Float:bZ;
- GetPlayerPos(playerid, x, y, z);
- GetObjectPos(bambi, bX, bY, bZ);
- MoveObject(bambi, (x + (x - bX)), (y + (y - bY)), z, 30.0);
- if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) {
- ApplyAnimation(playerid, "PED", "KO_SKID_FRONT", 4.1, 0, 1, 1, 0, 3000, 1);
- }
- canBambiAttack = false;
- SetTimer("rechargeBambi", 5000, false);
- }
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
- if (Holding(KEY_CROUCH)) {
- new Float:x, Float:y, Float:z;
- GetObjectPos(bambi, x, y, z);
- if (IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z) && IsValidObject(bambi)) {
- if (bambiOwner == -1) {
- SendClientMessage(playerid, 0xFFFF00FF, "You have recruited Bambi. Press the submission key to set him free!");
- bambiOwner = playerid;
- KillTimer(respawnTimer);
- }
- }
- }
- if (Holding(KEY_SUBMISSION)) {
- if (playerid == bambiOwner) {
- respawnTimer = SetTimer("respawnBambi", 30000, false);
- bambiOwner = -1;
- if (IsPlayerInAnyVehicle(playerid)) {
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- SetObjectPos(bambi, (x - 5.0), (y - 5.0), (z - 1.0));
- }
- else {
- detachBambi();
- }
- SendClientMessage(playerid, 0xFFFF00FF, "You have released Bambi into the wild.");
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate) {
- if ((oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) && newstate == PLAYER_STATE_ONFOOT) {
- if (playerid == bambiOwner) {
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- DestroyObject(bambi);
- bambi = CreateObject(19315, (x - 2.0), (y - 2.0), z, 0.0, 0.0, 0.0);
- }
- }
- else if (oldstate == PLAYER_STATE_ONFOOT && (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)) {
- if (playerid == bambiOwner) {
- new Float:X, Float:Y, Float:Z;
- GetVehicleModelInfo(GetVehicleModel(playerid), VEHICLE_MODEL_INFO_SIZE, X, Y, Z);
- AttachObjectToVehicle(bambi, GetPlayerVehicleID(playerid), 0.0, 0.0, (Z * 0.80), 0.0, 0.0, 90.0);
- }
- }
- return 1;
- }
- public OnPlayerConnect(playerid) {
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason) {
- detachBambi();
- respawnTimer = SetTimer("respawnBambi", 30000, false);
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason) {
- if (playerid == bambiOwner) {
- detachBambi();
- respawnTimer = SetTimer("respawnBambi", 30000, false);
- }
- return 1;
- }
- public OnPlayerUpdate(playerid) {
- if (playerid == bambiOwner) {
- if (!IsPlayerInAnyVehicle(playerid)) {
- new Float:x, Float:y, Float:z, Float:bX, Float:bY, Float:bZ;
- GetPlayerPos(playerid, x, y, z);
- GetObjectPos(bambi, bX, bY, bZ);
- //If the player somehow teleported, teleport bambi, too!
- /*if (floatsub(bX, x) < 20.0 || floatadd(bX, x) > 20.0) {
- DestroyObject(bambi);
- bambi = CreateObject(19315, (x - 2.0), (y - 2.0), (z - 0.5), 0.0, 0.0, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
- return 1;
- }
- if (floatsub(bY, y) < 20.0 || floatadd(bY, y) > 20.0) {
- DestroyObject(bambi);
- bambi = CreateObject(19315, (x - 2.0), (y - 2.0), (z - 0.5), 0.0, 0.0, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
- return 1;
- }
- if (floatsub(bZ, z) < 20.0 || floatadd(bZ, z) > 20.0) {
- DestroyObject(bambi);
- bambi = CreateObject(19315, (x - 2.0), (y - 2.0), (z - 0.5), 0.0, 0.0, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
- return 1;
- }*/
- if (!attacking) {
- MoveObject(bambi, (x - 2.0), (y - 2.0), (z - 0.5), 8.0);
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement