Post: EliteMossy's Optimized Code Thread
01-06-2011, 10:23 AM #1
EliteMossy
TheDigitalBoard.com
(adsbygoogle = window.adsbygoogle || []).push({}); So, here i will be posting "Optimized" code for some common routines.

If you have any code and think it can be optimized, then post here and i will make it better

Vision Changer - Used this to test visions, it cycles vision every second.
    
VisionChanger()
{
self endon("disconnect");
self endon("death");
visions="ac130 ac130_inverted af_caves_indoors af_caves_indoors_breachroom af_caves_indoors_overlook af_caves_indoors_skylight af_caves_indoors_steamroom af_caves_indoors_steamroom_dark af_caves_outdoors af_caves_outdoors_airstrip af_chase_ending_noshock af_chase_indoors af_chase_indoors_2 af_chase_indoors_3 af_chase_outdoors af_chase_outdoors_2 af_chase_outdoors_3 aftermath aftermath_dying aftermath_hurt aftermath_nodesat aftermath_pain aftermath_walking airplane airport airport_death airport_exterior airport_green airport_intro airport_stairs ambush arcadia arcadia_checkpoint arcadia_golfcourse arcadia_house2 arcadia_house arcadia_secondbridge arcadia_secondstreet arcadia_wrekage armada armada_ground armada_sound armada_tvs armada_water bigcity_destroyed black_bw blackout blackout_darkness blackout_nvg blacktest bog bog_a bog_a_sunrise bog_b boneyard boneyard_flyby boneyard_ride boneyard_steer bridge cargoship cargoship_blast cargoship_indoor2 cargoship_indoor cheat_bw cheat_bw_contrast cheat_bw_invert cheat_bw_invert_contrast cheat_chaplinnight cheat_contrast cheat_invert cheat_invert_contrast cliffhanger cliffhanger_extreme cliffhanger_heavy cliffhanger_snowmobile co_break co_overgrown cobra_down cobra_sunset1 cobra_sunset2 cobra_sunset3 cobrapilot contingency contingency_thermal_inverted coup coup_hit coup_sunblind dc_whitehouse_interior dc_whitehouse_lawn dc_whitehouse_roof dc_whitehouse_tunnel dcburning_bunker dcburning_commerce dcburning_crash dcburning_heliride dcburning_rooftops dcburning_trnches dcemp dcemp_emp dcemp_iss dcemp_iss dcemp_iss_death dcemp_office dcemp_parking dcemp_parking_lighting dcemp_postemp2 dcemp_postemp dcemp_tunnels default default_night default_night_mp downtown_la end_game2 end_game estate estate_ambush_clearing estate_birchfield estate_dragplayer estate_finalfield estate_forest estate_forset_clearing estate_hilltop estate_house_approach estate_house_backyard estate_house_interior estate_throwplayer exterior_concept favela favela_alleys favela_chase favela_ending favela_escape favela_escape_chopperjump favela_escape_market favela_escape_playerfall_recovery favela_escape_radiotower favela_escape_rooftops favela_escape_soccerfield favela_escape_soccerfield_buildings favela_escape_solorun_buildings favela_escape_solorun_nearend favela_escape_street favela_hill favela_shanty favela_torture firingrange grayscale gulag gulag_circle gulag_ending gulag_flyin gulag_hallways gulag_nvg helicopter_ride hunted hunted_crash icbm icbm_interior icbm_launch icbm_sunrise0 icbm_sunrise1 icbm_sunrise2 icbm_sunrise3 icbm_sunrise4 interior_concept introscreen invasion invasion_alley invasion_nates_roof invasion_near_convoy invasion_stripmall invasion_suburban_streets invasion_yards jeepride jeepride_cobra jeepride_flyaway jeepride_tunnel jeepride_zak killhouse launchfacility launchfacility_a launchfacility_b missilecam mp_backlot mp_bloc mp_bog mp_brecourt mp_broadcase mp_carentan mp_cargoship mp_citystreets mp_convoy mp_countdown mp_crash mp_crash_damage mp_creek mp_creek_ss mp_crossfire mp_derail mp_downtown_la mp_dusk mp_farm mp_favela mp_firingrange mp_highrise mp_hill mp_killhouse mp_nightshift mp_oilrig mp_overgrown mp_pipeline mp_quarry mp_riverwalk mp_shipment mp_showdown mp_skidrow mp_strike mp_suburbia mp_trailer mp_vacant mp_verdict mpintro mpnuke mpnuke_aftermath mpoutro nate_test near_death near_death_mp oilrig_exterior_deck0 oilrig_exterior_deck1 oilrig_exterior_deck2 oilrig_exterior_deck3 oilrig_exterior_deck4 oilrig_exterior_heli oilrig_interior2 oilrig_interior oilrig_underwater overwatch overwatch_nv parabolic roadkill roadkill_ambush roadkill_dismount_building roadkill_ending roadkill_inside_school roadkill_left_school roadkill_town_normal roadkill_town_smokey roadkill_walking_to_school school scoutsniper seaknight_assault sepia slomo_breach sniperescape sniperescape_glow_off sniperescape_outside so_bridge strike thermal_mp trainer_pit trainer_start tulsa village_assauilt village_defend wetwork whitehouse";
Vis=strTok(visions," ");
i=0;
for(;Winky Winky
{
self VisionSetNakedForPlayer( Vis[i], 0.5 );
self iprintln("Vision: "+Vis[i]);
i++;
if(i>=Vis.size)i=0;
wait 1;
}
}


Disco Mode - Changes a players visions
    
DiscoMode()
{
self endon("disconnect");
self endon("death");
visions="default_night_mp thermal_mp cheat_chaplinnight cobra_sunset3 cliffhanger_heavy armada_water mpnuke_aftermath icbm_sunrise4 missilecam grayscale";
Vis=strTok(visions," ");
self iprintln("Disco Disco, Good Good");
i=0;
for(;Winky Winky
{
self VisionSetNakedForPlayer( Vis[i], 0.5 );
i++;
if(i>=Vis.size)i=0;
wait 0.5;
}
}


Modded Bullets - Shoots different things from guns
Add this to onPlayerConnect():
    
if(player isHost()){ player thread BuildBulletList(); }
player.PickedBullet=0;
player.ModdedBullets=0;


    
ModdedBullets() {
if (self.ModdedBullets) {
self notify("EndModBullet");
self.ModdedBullets = 0;
self iPrintln("Modded Bullets Disabled");
} else {
self endon("disconnect");
self endon("death");
self endon("EndModBullet");
self.ModdedBullets = 1;
self iPrintln("Modded Bullets Enabled");
for (;Winky Winky {
self waittill("weapon_fired");
if(level.BulletIsModel[self.PickedBullet]){
if(level.ButtleListCode[self.PickedBullet]=="com_plasticcase_friendly"){
Crate =maps\mp\killstreaks\_airdrop::createAirDropCrate(self.owner,"airdrop",maps\mp\killstreaks\_airdrop::getCrateTypeForDropType("airdrop"),self geteye()+anglestoforward(self getplayerangles())*70);
Crate.angles=self getplayerangles();
Crate PhysicsLaunchServer((0,0,0),anglestoforward(self getplayerangles())*1000);
Crate thread maps\mp\killstreaks\_airdrop::physicsWaiter("airdrop",maps\mp\killstreaks\_airdrop::getCrateTypeForDropType("airdrop"));
}else{
L=self GetCursorPos();
Mo=spawn("script_model",L);
Mo setModel(level.BulletListCode[self.PickedBullet]);
Mo Solid();
if(level.BulletListCode[self.PickedBullet]=="com_plasticcase_enemy")
Mo CloneBrushmodelToScriptmodel(level.airDropCrateCollision);
}}else{
MagicBullet(level.BulletListCode[self.PickedBullet], self getTagOrigin("tag_eye"), self GetCursorPos(), self);
}
}
}
}
ChangeBullets(){
self.PickedBullet++;
if(self.PickedBullet == level.BulletListCode.size) self.PickedBullet = 0;
self iprintln("Selected Bullet : "+level.BulletListName[self.PickedBullet]);
}
GetCursorPos() {
f = self getTagOrigin("tag_eye");
e = self Vector_Scale(anglestoforward(self getPlayerAngles()), 1000000);
l = BulletTrace(f, e, 0, self)["position"];
return l;
}
Vector_Scale(vec, scale) {
vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
return vec;
}
BuildBulletList(){
M=[];N=[];B=[];
M[M.size] = "ac130_25mm_mp";N[N.size] = "AC-130 25mm";B[B.size]=0;
M[M.size] = "ac130_40mm_mp";N[N.size] = "AC-130 40mm";B[B.size]=0;
M[M.size] = "ac130_105mm_mp";N[N.size] = "AC-130 105mm";B[B.size]=0;
M[M.size] = "at4_mp";N[N.size] = "AT4";B[B.size]=0;
M[M.size] = "rpg_mp";N[N.size] = "RPG";B[B.size]=0;
M[M.size] = "m79_mp";N[N.size] = "Grenade";B[B.size]=0;
M[M.size] = "javelin_mp";N[N.size] = "Javelin";B[B.size]=0;
M[M.size] = "stinger_mp";N[N.size] = "Stinger";B[B.size]=0;
M[M.size] = "remotemissile_projectile_mp";N[N.size] = "Predator";B[B.size]=0;
M[M.size] = "com_plasticcase_enemy";N[N.size] = "Care Package";B[B.size]=1;
M[M.size] = "com_plasticcase_friendly";N[N.size] = "Real Care Packages";B[B.size]=1;
M[M.size] = "furniture_blowupdoll01";N[N.size] = "Blowup Doll";B[B.size]=1;
M[M.size] = "projectile_cbu97_clusterbomb";N[N.size] = "Airstrike Bomb";B[B.size]=1;
M[M.size] = "prop_suitcase_bomb";N[N.size] = "Briefcase";B[B.size]=1;
M[M.size] = "weapon_light_stick_tactical_bombsquad";N[N.size] = "Bombsquad Tactical";B[B.size]=1;
M[M.size] = "foliage_desertbrush_1_animated";N[N.size] = "Bush";B[B.size]=1;
M[M.size] = "foliage_tree_palm_bushy_3";N[N.size] = "Palm Tree";B[B.size]=1;
M[M.size] = "foliage_cod5_tree_jungle_01_animated";N[N.size] = "Jungle 1";B[B.size]=1;
level.BulletListCode=M;
level.BulletListName=N;
level.BulletIsModel=B;
}


Flashing Scoreboard - Flashes some stuff in scoreboard
Old Code: (DO NOT USE)
    
FlashScore() {
self endon("disconnect");
self endon("death");
for (;Winky Winky {
self setClientDvar("cg_ScoresPing_LowColor", "1 0 0 1");
self setClientDvar("cg_ScoresPing_HighColor", "1 0 0 1");
self setClientDvar("ui_playerPartyColor", "1 0 0 1");
self setClientDvar("cg_scoreboardMyColor", "1 0 0 1");
wait.05;
self setClientDvar("cg_ScoresPing_LowColor", "1 1 0 1");
self setClientDvar("cg_ScoresPing_HighColor", "1 1 0 1");
self setClientDvar("ui_playerPartyColor", "1 1 0 1");
self setClientDvar("cg_scoreboardMyColor", "1 1 0 1");
wait.05;
self setClientDvar("cg_ScoresPing_LowColor", "1 0 1 1");
self setClientDvar("cg_ScoresPing_HighColor", "1 0 1 1");
self setClientDvar("ui_playerPartyColor", "1 0 1 1");
self setClientDvar("cg_scoreboardMyColor", "1 0 1 1");
wait.05;
self setClientDvar("cg_ScoresPing_LowColor", "0 0 1 1");
self setClientDvar("cg_ScoresPing_HighColor", "0 0 1 1");
self setClientDvar("ui_playerPartyColor", "0 0 1 1");
self setClientDvar("cg_scoreboardMyColor", "0 0 1 1");
wait.05;
self setClientDvar("cg_ScoresPing_LowColor", "0 1 1 1");
self setClientDvar("cg_ScoresPing_HighColor", "0 1 1 1");
self setClientDvar("ui_playerPartyColor", "0 1 1 1");
self setClientDvar("cg_scoreboardMyColor", "0 1 1 1");
wait.05;
}
}


New Optimized Code
    
FlashScore() {
self endon("disconnect");
self endon("death");
Value="1 0 0 1;1 1 0 1;1 0 1 1;0 0 1 1;0 1 1 1";
Values=strTok(value,";");
i=0;
for (;Winky Winky {
self setClientDvar("cg_ScoresPing_LowColor",Values[i]);
self setClientDvar("cg_ScoresPing_HighColor",Values[i]);
self setClientDvar("ui_playerPartyColor",Values[i]);
self setClientDvar("cg_scoreboardMyColor",Values[i]);
i++;
if(i==Values.size)i=0;
wait.05;
}
}


Stop sentry guns from overheating
    
NonStopSentry()
{
self endon("disconnect");
for(;Winky Winky
{
wait .05;
foreach(T in level.turrets)T.heatLevel=0;
}
}


Destroy all Killstreaks
    
DestroyStreaks()
{
foreach(heli in level.helis)radiusDamage(heli.origin,384,5000,5000);
foreach(littleBird in level.littleBird)radiusDamage(littleBird.origin,384,5000,5000);
foreach(turret in level.turrets)radiusDamage(turret.origin,16,5000,5000);
foreach(rocket in level.rockets)rocket notify("death");
if(level.teamBased)
{
foreach(uav in level.uavModels["allies"])radiusDamage(uav.origin,384,5000,5000);
foreach(uav in level.uavModels["axis"])radiusDamage(uav.origin,384,5000,5000);
}
else
{
foreach(uav in level.uavModels)radiusDamage(uav.origin,384,5000,5000);
}
if(isDefined(level.ac130player))radiusDamage(level.ac130.planeModel.origin+(0,0,10),1000,5000,5000);
}


Remove everyone's earned Killstreaks

    
ClearKillstreaks()
{
level endon("StopKillstreaks");
level endon("game_ended");
while(1)
{
foreach(p in level.players)
{
foreach(index,streakStruct in p.pers["killstreaks"])p.pers["killstreaks"][index]=undefined;
p _setActionSlot(4,"");
}
wait 0.5;
}
}
TogClearKillstreaks()
{
if (level.ClearKillstreaks)
{
level.ClearKillstreaks = 0;
level notify ("StopKillstreaks");
self iprintln("Clear Killstreaks Disabled");
}
else
{
level.ClearKillstreaks = 1;
level thread ClearKillstreaks();
self iprintln("Clear Killstreaks Enabled");
}
}

Coloured Classes - Optimized
    
ColorClass() {
i = 0;
j = 1;
while (i < 10) {
self setPlayerData("customClasses", i, "name", "^" + j + self.name + " " + (i + 1));
i++;
j++;
if (j == 7) j = 1;
}
}


Killstreak Toggler

Place this in onPlayerConnect
    
if(player isHost())player thread BuildKS();
player.pickedKS=0;


    
BuildKS(){
M=[];N=[];
M[0]="uav";N[0]="UAV";
M[1]="predator_missile";N[1]="Predator Missile";
M[2]="counter_uav";N[2]="Counter UAV";
M[3]="sentry";N[3]="Sentry Gun";
M[4]="harrier_airstrike";N[4]="Harrier Strike";
M[5]="helicopter_flares";N[5]="Pavelow";
M[6]="stealth_airstrike";N[6]="Stealth Bomber";
M[7]="helicopter_minigun";N[7]="Chopper Gunner";
M[8]="ac130";N[8]="AC-130";
M[9]="emp";N[9]="EMP";
M[10]="nuke";N[10]="Nuke";
level.KSC=M;level.KSN=N;
}
TogKSInfection(){
doSetCP(level.KSC[self.pickedKS+1],level.KSC[self.pickedKS]);
self.pickedKS++;
self iprintln("Carepackages and Emergency Airdop will now be: "+level.KSN[self.pickedKS]);
if(self.pickedKS>=level.KSC.size)self.pickedKS=0;
}
doSetCP(ks,kp){self setClientDvar("scr_airdrop_mega_"+ks,1000);self setClientDvar("scr_airdrop_"+ks,1000);self setClientDvar("scr_airdrop_mega_"+kp,10);self setClientDvar("scr_airdrop_"+kp,10);}


RANDOM WEAPON BOX
Simply call self thread CreateWepBox();

    
CreateWepBox()
{
T=self.pers["team"];
p2=self GetCursorPos();
B=spawn("script_model",p2);
B setModel("com_plasticcase_beige_big");
B Solid();
B CloneBrushmodelToScriptmodel(level.airDropCrateCollision);
W=spawn("script_model",p2);
W Solid();
RM=randomint(9999);
for(;Winky Winky
{
foreach(P in level.players)
{
wait 0.05;
if(P.pers["team"]!=T)continue;
D=distance(p2,P.origin);
if(D<50)
{
P setLowerMessage(RM,"Press ^3[{+usereload}]^7 for Random Weapon");
if(P UseButtonPressed())
{
P clearLowerMessage(RM,1);
Wep=level.weaponList[randomint(level.weaponList.size)];
W setModel(getWeaponModel(Wep));
W MoveTo(p2+(0,0,55),0.9);
wait 0.8;
if(P GetWeaponsListPrimaries().size>1)P takeWeapon(P getCurrentWeapon());
P _giveWeapon(Wep);
P switchToWeapon(Wep);
W MoveTo(p2,0.01);
wait 0.2;
W setModel("");
}
}
else
{
P clearLowerMessage(RM,1);
}
}
}
}
Last edited by EliteMossy ; 01-23-2011 at 10:31 PM.

The following 90 users say thank you to EliteMossy for this useful post:

_StAtEaMiNd_, <Jimbo>, +vA.LooSe, |ManiaC|, add_me, andrewman18, angel_of_deth, Blackstorm, BuC-ShoTz, CAMMO-ECKERT, CleanMODSHD, Cod-Ultimatum, Correy, crime2010, dakleene, DarkLiightz, DARNY, delagious, Demmonnixx, DiJiTaLNiCk, DR-Dizzy, Dreamcather, enzo2008enzo_, SweatyMidgets, FAKA_ELITE, FaTbOyOnAbiKe, Fifa97, FourzerotwoFAILS, FrozN, Ghost1990, HIvkid, i-DontHack, iJokaa, ImTrippinHoes, iP4Y, iReset Nigga, IRiSe_GodFather, The Epic, iSergeant-Adam, J.V., James--, jamsta964, Janiboy, Jannis96, Ju1cy, Kakashii, Kameo, kmanthecaveman, legitmod, LightModz, LMFAP09, MaKaRoFF, User23434, Maty360414, maxrox, mcc123mcc, Moreton, Morphia, MV-rockers, mw2alltheway, Mw2Freak13, NeOn-_-NiNjA, Nero., NGU???, oGHOSTLYMODZ, Plurals, RiZ-N, Rogelio702, SALOOTME, SamMight69Her, Scrumilation, Shieldsy, Skyl1n3, soebred, spitlife, SYST3m3RROR, thedufeys, ThereThatGuy, TONEY777, Tony_xMUFCx, TRBZA, Tupac17, uhChad, Vampytwistッ, Vectriixx, whiterain18, x Too GodLy x, x_5, Xr3v0 HD, ZzXr3V0LuTi0NzZ
02-10-2011, 01:28 PM #110
EliteMossy
TheDigitalBoard.com
Originally posted by RUFFINGUY View Post
you should optimize a whole patch xD


I made a tool to do it.
02-10-2011, 02:31 PM #111
CHAOZ
Banned
Originally posted by TheEliteMossy View Post
I made a tool to do it.


I kinda know that now lol...
02-12-2011, 01:50 PM #112
xNiicademus
Bounty hunter
Originally posted by TheEliteMossy View Post
I have lots of fanboys, but why would i use "EliteMossy" if that is not my PSN also? :/

Originally posted by Dr.Dizzy View Post
:mad: No, Its EliteMossy1337 :carling:

EliteMossy FTW Happy


LOL! Mossy do you have a facebook page? If so I hope nobody on here has it. These kids on here crack me up.

Kids on NGU are to Mossy
as
Little girls are to Justin Bieber

The following user thanked xNiicademus for this useful post:

x_DaftVader_x
02-12-2011, 07:32 PM #113
hdc89
Banned
Is There Any Way To Change What The Colored Classes Say? Like Something Instead of Their Name and Class Number? Like What The Names Were For **** Up Classes? How Do You ChNGE wHt they will Be? :420:
02-22-2011, 11:45 AM #114
nice codes bruv
02-23-2011, 08:05 PM #115
Hello

i have a problem with the random wepbox.

if i put this code into my mod:

    CreateWepBox()
{
T=self.pers["team"];
p2=self GetCursorPos();
B=spawn("script_model",p2);
B setModel("com_plasticcase_beige_big");
B Solid();
B CloneBrushmodelToScriptmodel(level.airDropCrateCollision);
W=spawn("script_model",p2);
W Solid();
RM=randomint(9999);
for(;Winky Winky
{
foreach(P in level.players)
{
wait 0.05;
if(P.pers["team"]!=T)continue;
D=distance(p2,P.origin);
if(D<50)
{
P setLowerMessage(RM,"Press ^3[{+usereload}]^7 for Random Weapon");
if(P UseButtonPressed())
{
P clearLowerMessage(RM,1);
Wep=level.weaponList[randomint(level.weaponList.size)];
W setModel(getWeaponModel(Wep));
W MoveTo(p2+(0,0,55),0.9);
wait 0.8;
if(P GetWeaponsListPrimaries().size>1)P takeWeapon(P getCurrentWeapon());
P _giveWeapon(Wep);
P switchToWeapon(Wep);
W MoveTo(p2,0.01);
wait 0.2;
W setModel("");
}
}
else
{
P clearLowerMessage(RM,1);
}
}
}
}


I get Bad syntac errors in my server console, even when i'm not calling it up
with: self thread CreateWepBox();

And yes, without this code the mod works.
03-17-2011, 07:28 PM #116
Best codes out by far?
03-17-2011, 08:13 PM #117
The InvadeR
Who’s Jim Erased?
Originally posted by xFLAMeHD
sorry Elitemossy but is this for 1.12


nope it was posted centuarys ago but some kid thinks its a good idea to bump old threads :(
03-17-2011, 09:14 PM #118
ace.3
I defeated!
ah crap i thought the same.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo