Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #using scripts\codescripts\struct;
- #using scripts\shared\util_shared;
- #using scripts\shared\array_shared;
- #insert scripts\zm\_zm_utility.gsh;
- #insert scripts\zm\_espi_minigames.gsh;
- #using scripts\zm\_zm_utility;
- #namespace espi_minigames;
- #precache( "model", "p7_boat_life_preserver" );
- #precache( "model", "n_0" );
- #precache( "model", "n_1" );
- #precache( "model", "n_2" );
- #precache( "model", "n_3" );
- #precache( "model", "n_4" );
- #precache( "model", "n_5" );
- #precache( "model", "n_6" );
- #precache( "model", "n_7" );
- #precache( "model", "n_8" );
- #precache( "model", "n_9" );
- function main()
- {
- level._minigames = [];
- add_minigame("firing_range", "fr_score", &firing_range_think, &firing_range_init);
- add_minigame("attack_tooth", "at_score", &attack_tooth_think, &attack_tooth_init);
- //add_minigame("water_gun", "wg_score", &water_gun_think, &water_gun_init);
- thread minigames();
- }
- function add_minigame(name, score_ent, func, func_init)
- {
- minigame = SpawnStruct();
- minigame.name = name;
- minigame.score_ent = score_ent;
- minigame.func = func;
- minigame.func_init = func_init;
- minigame.record = 0;
- level._minigames[name] = minigame;
- }
- function minigames()
- {
- keys = GetArrayKeys(level._minigames);
- foreach(key in keys)
- level._minigames[key] thread start_minigame();
- }
- function start_minigame()
- {
- trigger = GetEnt(self.name + "_trig", "targetname");
- trigger endon("delete");
- trigger SetHintString("Press to start");
- thread show_score(0, false, self.score_ent);
- while(1)
- {
- if(IsDefined(self.func_init))
- self [[self.func_init]]();
- trigger waittill("trigger", player);
- if(!zm_utility::is_player_valid( player ))
- continue;
- if(!IsDefined(player._minigames_score))
- player._minigames_score = [];
- player._minigames_score[self.name] = 0;
- thread show_score(0, false, self.score_ent);
- trigger TriggerEnable(false);
- player teleport_set_ignoreme(true);
- player teleportToStartPos(self.name + "_tp_player");
- wait 0.1;
- player [[self.func]]();
- if(player._minigames_score[self.name] > self.record)
- {
- self.record = player._minigames_score[self.name];
- thread show_score(self.record, true, self.score_ent);
- wait 2;
- }
- wait 0.1;
- player unlink();
- trigger TriggerEnable(true);
- }
- }
- function firing_range_init()
- {
- if(!IsDefined(self.sound_org))
- {
- orgs = struct::get_array( "s", "targetname" );
- org = (0, 0, 0);
- foreach(o in orgs)
- org += o.origin;
- org /= orgs.size;
- self.sound_org = org;
- self.model_gallery = util::spawn_model( "p7_boat_life_preserver", (0, 0, -1000), (0, 0, 0) );
- self.model_gallery.angle_init = stringToAngles(FIRING_RANGE_ANGLE_INIT);
- self.model_gallery.angle_end = stringToAngles(FIRING_RANGE_ANGLE_END);
- self.model_gallery hide();
- self.model_gallery SetCanDamage(true);
- }
- else
- self.model_gallery hide();
- }
- function firing_range_think()
- {
- base = level._minigames["firing_range"];
- model = base.model_gallery;
- PlaySoundAtPosition("gallery_start", base.sound_org);
- orgs = struct::get_array( "s", "targetname" );
- order = [];
- for(i=0;i<FIRING_RANGE_NUM;i++)
- order[i] = orgs[randomint(orgs.size)];
- num = 0;
- targets = 0;
- while(num < FIRING_RANGE_NUM)
- {
- model notify("move_target");
- model.origin = order[num].origin;
- model.angles = model.angle_init;
- model show();
- PlaySoundAtPosition("gallery_blanco", model.origin);
- model RotateTo(model.angle_end, FIRING_RANGE_ROTATE_TIME);
- wait 0.1;
- model thread target_timeout();
- nt = model util::waittill_any_return("damage", "timeout");
- if(nt != "timeout" || !IsDefined(nt))
- {
- self._minigames_score[base.name]++;
- thread show_score(self._minigames_score[base.name], false, base.name);
- model RotateTo(model.angle_init, FIRING_RANGE_ROTATE_TIME/10);
- wait (FIRING_RANGE_ROTATE_TIME/10);
- }
- else
- {
- model RotateTo(model.angle_init, FIRING_RANGE_ROTATE_TIME/2);
- wait (FIRING_RANGE_ROTATE_TIME/2);
- }
- model hide();
- wait FIRING_RANGE_BETWEEN_TIME;
- num++;
- }
- }
- function target_timeout()
- {
- self endon("damage");
- self endon("move_target");
- wait (FIRING_RANGE_ROTATE_TIME + FIRING_RANGE_TIMEOUT - 0.1);
- self notify("timeout");
- }
- function attack_tooth_init()
- {
- teeth = GetEntArray("tooth", "targetname");
- foreach(tooth in teeth)
- {
- if(!IsDefined(tooth.real_origin))
- {
- tooth.real_origin = spawn("script_model", tooth.origin + (0, 0, ATTACK_TOOTH_Z));
- tooth.initial_angles = tooth.real_origin.angles;
- tooth.end_angles = stringToAngles(ATTACK_TOOTH_ANGLE_END);
- tooth LinkTo(tooth.real_origin);
- tooth.maxhealth = 100000;
- tooth.health = tooth.maxhealth;
- tooth SetCanDamage(true);
- }
- else
- {
- if(tooth.real_origin.angles != tooth.initial_angles)
- tooth.real_origin RotateTo(tooth.initial_angles, ATTACK_TOOTH_ROTATE_TIME/3);
- tooth.health = tooth.maxhealth;
- }
- }
- }
- function attack_tooth_think()
- {
- self._minigames_score["attack_tooth"] = 0;
- teeth = GetEntArray("tooth", "targetname");
- trigger = GetEnt("attack_tooth_trig", "targetname");
- array::thread_all(teeth, &initGameAttackTooth, self, trigger);
- self thread AttackToothTries();
- self waittill("attack_tooth_end");
- }
- function initGameAttackTooth(player, trig)
- {
- player endon("attack_tooth_end");
- while(1)
- {
- self waittill( "damage", amount, attacker, direction_vec, point, type, tagName, modelName, partName, weapon );
- if(attacker != player)
- continue;
- /*if(weapon != ATTACK_TOOTH_WEAPON)
- continue;*/
- player._at_impact = true;
- player._at_impact_time = GetTime();
- self.real_origin RotateTo(self.end_angles, ATTACK_TOOTH_ROTATE_TIME);
- iprintlnbold("golpeado");
- return;
- }
- }
- function AttackToothTries()
- {
- self endon("attack_tooth_end");
- self._at_impact_time = 0;
- self._at_impact = false;
- tries = ATTACK_TOOTH_TRIES;
- total = GetEntArray("tooth", "targetname").size;
- while(1)
- {
- self waittill("grenade_fire", grenade, weapon);
- if( !self HasWeapon( weapon ) )
- {
- self GiveWeapon( weapon );
- self SetWeaponAmmoClip( weapon, 4 );
- }
- /*if(weapon != ATTACK_TOOTH_WEAPON)
- continue;*/
- wait 2.5;
- grenade delete();
- if(GetTime() - self._at_impact_time <= 2500 && self._at_impact)
- {
- self._minigames_score["attack_tooth"]++;
- thread show_score(self._minigames_score["attack_tooth"], false, "at_score");
- iprintlnbold("tocado con granada");
- }
- else
- {
- tries--;
- iprintlnbold("fallo con granada");
- }
- if(tries == 0)
- {
- self SetMiniGameScore("attack_tooth", self._minigames_score["attack_tooth"]);
- self notify("attack_tooth_end");
- }
- if(total == self._minigames_score["attack_tooth"])
- {
- self._minigames_score["attack_tooth"] = 0;
- self SetMiniGameScore("attack_tooth", total);
- self [[self.func_init]]();
- }
- self._at_impact_time = 0;
- self._at_impact = false;
- }
- }
- function water_gun_init()
- {
- }
- function water_gun_think()
- {
- }
- function teleport_set_ignoreme( b_ignoreme )
- {
- //DEFAULT(self.teleport_ignore,false);
- if ( b_ignoreme != self.teleport_ignore )
- {
- self.teleport_ignore = b_ignoreme;
- if ( b_ignoreme )
- self zm_utility::increment_ignoreme();
- else
- self zm_utility::decrement_ignoreme();
- }
- }
- function teleportToStartPos(name)
- {
- new_player_pos = struct::get(name, "targetname");
- if(!IsDefined(self._mgames_pos))
- {
- self._mgames_pos = util::spawn_model( "tag_origin", new_player_pos.origin, new_player_pos.angles );
- self._mgames_pos hide();
- }
- else
- {
- self._mgames_pos.origin = new_player_pos.origin;
- self._mgames_pos.angles = new_player_pos.angles;
- }
- self PlayerLinkToDelta(self._mgames_pos, "tag_origin", 0, 70,70,70,70);
- self.origin = self.origin;
- }
- function stringToAngles(str, sep = " ")
- {
- a = strTok(str, sep);
- return (int(a[0]), int(a[1]), int(a[2]));
- }
- function show_score(score, record, name)
- {
- ns1 = struct::get(name + "1", "targetname");
- ns2 = struct::get(name + "2", "targetname");
- decenas = int(score/10);
- unidades = score - decenas*10;
- if(!IsDefined(ns1.decenas))
- {
- ns1.decenas = spawn("script_model", ns1.origin);
- ns1.decenas.angles = ns1.angles;
- }
- if(!IsDefined(ns2.unidades))
- {
- ns2.unidades = spawn("script_model", ns2.origin);
- ns2.unidades.angles = ns2.angles;
- }
- ns1.decenas SetModel("n_"+decenas);
- ns2.unidades SetModel("n_"+unidades);
- if(record)
- {
- for(i=0;i<5;i++)
- {
- wait 0.33;
- ns1.decenas hide();
- ns2.unidades hide();
- wait 0.33;
- ns1.decenas show();
- ns2.unidades show();
- }
- }
- }
- function SetMiniGameScore(name, score)
- {
- if(!IsDefined(self._minigames_total_score))
- self._minigames_total_score = [];
- if(!IsDefined(self._minigames_total_score[name]))
- self._minigames_total_score[name] = 0;
- self._minigames_total_score[name] += score;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement