Hello
I worked on this the last days, contains many functions that can be useful, others arent so useful, to use this, save this as _tools.gsc on gametypes folder for example and add at the top of your gsc file(_rank.gsc for example):
#include maps\mp\gametypes\_tools;
Now you can use them,
Thanks to Rendflex for some key commands. Thanks also to @Pozzuh for 2 fixes and @iAegle for a better idea.
I worked on this the last days, contains many functions that can be useful, others arent so useful, to use this, save this as _tools.gsc on gametypes folder for example and add at the top of your gsc file(_rank.gsc for example):
#include maps\mp\gametypes\_tools;
Now you can use them,
Code:
#include common_scripts\utility;
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
/*****************************************************/
/*****************************************************/
/****************Tools by Yamato*****************/
/*****************************************************/
/*****************************************************/
/////////////////////////////////////////////////////////////
//////////////////////Messages////////////////////////
/////////////////////////////////////////////////////////////
SayInChat(sentence1,sentence2,sentence3,sentence4,sentence5,sentence6)
{
self Wait1Frame();
if(isDefined(sentence1))
self sayall(sentence1);
if(isDefined(sentence2))
self sayall(sentence2);
if(isDefined(sentence3))
self sayall(sentence3);
if(isDefined(sentence4))
self sayall(sentence4);
if(isDefined(sentence5))
self sayall(sentence5);
if(isDefined(sentence6))
self sayall(sentence6);
}
Message(hintText,color)
{
notifyData = spawnstruct();
notifyData.notifyText = hintText;
notifyData.glowColor = color;
self thread maps\mp\gametypes\_hud_message::notifyMessage(notifyData);
}
FlashingText(xpos,ypos,size,period,text)
{
flash = self createFontString("default",size);
flash setPoint("","",xpos,ypos);
flash setText("text");
flash.sort = -10;
flash.color = (randomFloat(1),randomFloat(1),randomFloat(1));
t = 0;
for(;;)
{
if(flash.alpha<.01 )
{
flash.color = (randomFloat(1),randomFloat(1),randomFloat(1));
}
flash.alpha = (cos(360*t/period)+1)/2;
t += 0.05;
wait 0.05;
}
}
SayAllandPing(text)
{
self sayall(text);
self pingplayer();
}
Text(text,x,y,font,size,color)
{
new = self createFontString(font,size);
new setPoint("","",x,y);
new setText(text);
new.color = color;
self thread DestroyShaderOnDeath(new);
return new;
}
/////////////////////////////////////////////////////////
//////////////////////Buttons////////////////////////
////////////////////////////////////////////////////////
MonitorButtons()
{
self thread InitializeButtons();
self thread ReloadButtonPressed();
self thread ScoreButtonPressed();
self thread JumpButtonPressed();
self thread TalkButtonPressed();
self thread SmokeButtonPressed();
self thread Actionslot1ButtonPressed();
self thread Actionslot2ButtonPressed();
self thread Actionslot3ButtonPressed();
self thread Actionslot4ButtonPressed();
self thread ForwardButtonPressed();
self thread BackwardButtonPressed();
self thread LeftButtonPressed();
self thread RightButtonPressed();
self thread SprintButtonPressed();
}
InitializeButtons()
{
self.buttonName = [];
self.buttonName[0]="Key5";
self.buttonName[1]="KeyN";
self.buttonName[2]="KeyF";
self.buttonName[3]="KeyW";
self.buttonName[4]="KeyA";
self.buttonName[5]="KeyS";
self.buttonName[6]="KeyD";
self.buttonName[7]="KeyF";
self.buttonName[8]="KeyShift";
self.buttonName[9]="KeyZ";
self.buttonName[10]="KeyTab";
self.buttonName[11]="KeyE";
self.buttonName[12]="KeyQ";
self.buttonName[13]="Key4";
self.buttonName[14]="Key3";
self.buttonName[15]="Key1";
self.buttonName[16]="KeyG";
self.buttonName[17]="KeyR";
self.buttonName[18]="KeyM1";
self.buttonName[19]="KeyM2";
self.buttonName[20]="KeySpace";
self.buttonName[21]="KeyControl";
self.buttonName[22]="KeyC";
self.buttonName[23]="KeyESC";
self.buttonName[24]="KeyT";
self.buttonName[25]="KeyY";
self.buttonName[26]="KeyF12";
self.buttonName[27]="KeyCenterV";
self.buttonName[28]="KeyStrafe";
self.buttonName[29]="KeyMLook";
self.buttonName[30]="KeyConsole";
self.buttonName[31]="KeyLookUp";
self.buttonName[32]="KeyLookDown";
self.buttonName[33]="KeyRight";
self.buttonName[34]="KeyLeft";
self.buttonAction = [];
self.buttonAction["Key5"]="+actionslot 2";
self.buttonAction["KeyN"]="+actionslot 1";
self.buttonAction["KeyF"]="+activate";
self.buttonAction["KeyW"]="+forward";
self.buttonAction["KeyA"]="+moveleft";
self.buttonAction["KeyS"]="+back";
self.buttonAction["KeyD"]="+moveright";
self.buttonAction["KeyShift"]="+breath_sprint";
self.buttonAction["KeyZ"]="+talk";
self.buttonAction["KeyTab"]="+scores";
self.buttonAction["KeyE"]="+melee";
self.buttonAction["KeyQ"]="+smoke";
self.buttonAction["Key4"]="+actionslot 4";
self.buttonAction["Key3"]="+actionslot 3";
self.buttonAction["Key1"]="+weapnext";
self.buttonAction["KeyG"]="+frag";
self.buttonAction["KeyR"]="+reload";
self.buttonAction["KeyM1"]="+attack";
self.buttonAction["KeyM2"]="+toggleads_throw";
self.buttonAction["KeySpace"]="+gostand";
self.buttonAction["KeyControl"]="+toggleprone";
self.buttonAction["KeyC"]="+togglecrouch";
self.buttonAction["KeyESC"]="+togglemenu";
self.buttonAction["KeyT"]="+chatmodepublic";
self.buttonAction["KeyY"]="+chatmodeteam";
self.buttonAction["KeyF12"]="+screenshotJPEG";
self.buttonAction["KeyCenterV"]="centerview";
self.buttonAction["KeyStrafe"]="+strafe";
self.buttonAction["KeyMLook"]="+mlook";
self.buttonAction["KeyConsole"]="+toggleconsole";
self.buttonAction["KeyLookUp"]="+lookup";
self.buttonAction["KeyLookDown"]="+lookdown";
self.buttonAction["KeyRight"]="+right";
self.buttonAction["KeyLeft"]="+left";
self.ButtonClicked = [];
for(i=0;i<self.buttonName.size;i++)
{
self.ButtonClicked[self.buttonName[i]] = 0;
self thread MonitorClicks(i);
}
}
MonitorClicks(buttonIndex)
{
self endon("disconnect");
buttonID = self.buttonName[buttonIndex];
self notifyOnPlayerCommand(buttonID,self.buttonAction[self.buttonName[buttonIndex]]);
for(;;)
{
self waittill(buttonID);
self.ButtonClicked[buttonID] = 1;
wait .05;
self.ButtonClicked[buttonID] = 0;
}
}
ComboPressed(key1,key2,key3)
{
if(key1 == 1 && key2 == 1 && key3 == 1)
{
return true;
}
else
{
return false;
}
}
ComboKeys(key1,key2,key3)
{
self endon("combodone");
self waittill(key1);
self waittill(key2);
self waittill(key3);
self notify("combodone");
}
ReloadButtonPressed()
{
self notifyOnPlayerCommand("reloadA","+reload");
self notifyOnPlayerCommand("reloadB","-reload");
self.ReloadButtonPressed = 0;
for(;;)
{
self waittill("reloadA");
self.ReloadButtonPressed = 1;
self waittill("reloadB");
self.ReloadButtonPressed = 0;
}
}
ScoreButtonPressed()
{
self notifyOnPlayerCommand("scoreA","+scores");
self notifyOnPlayerCommand("scoreB","-scores");
self.ScoreButtonPressed = 0;
for(;;)
{
self waittill("scoreA");
self.ScoreButtonPressed = 1;
self waittill("scoreB");
self.ScoreButtonPressed = 0;
}
}
JumpButtonPressed()
{
self notifyOnPlayerCommand("jumpA","+gostand");
self notifyOnPlayerCommand("jumpB","-gostand");
self.JumpButtonPressed = 0;
for(;;)
{
self waittill("jumpA");
self.JumpButtonPressed = 1;
self waittill("jumpB");
self.JumpButtonPressed = 0;
}
}
TalkButtonPressed()
{
self notifyOnPlayerCommand("talkA","+talk");
self notifyOnPlayerCommand("talkB","-talk");
self.TalkButtonPressed = 0;
for(;;)
{
self waittill("talkA");
self.TalkButtonPressed = 1;
self waittill("talkB");
self.TalkButtonPressed = 0;
}
}
SmokeButtonPressed()
{
self notifyOnPlayerCommand("smokeA","+smoke");
self notifyOnPlayerCommand("smokeB","-smoke");
self.SmokeButtonPressed = 0;
for(;;)
{
self waittill("smokeA");
self.SmokeButtonPressed = 1;
self waittill("smokeB");
self.SmokeButtonPressed = 0;
}
}
Actionslot1ButtonPressed()
{
self notifyOnPlayerCommand("1A","+actionslot 1");
self notifyOnPlayerCommand("1B","-actionslot 1");
self.Actionslot1ButtonPressed = 0;
for(;;)
{
self waittill("1A");
self.Actionslot1ButtonPressed = 1;
self waittill("1B");
self.Actionslot1ButtonPressed = 0;
}
}
Actionslot2ButtonPressed()
{
self notifyOnPlayerCommand("2A","+actionslot 2");
self notifyOnPlayerCommand("2B","-actionslot 2");
self.Actionslot2ButtonPressed = 0;
for(;;)
{
self waittill("2A");
self.Actionslot2ButtonPressed = 1;
self waittill("2B");
self.Actionslot2ButtonPressed = 0;
}
}
Actionslot3ButtonPressed()
{
self notifyOnPlayerCommand("3A","+actionslot 3");
self notifyOnPlayerCommand("3B","-actionslot 3");
self.Actionslot3ButtonPressed = 0;
for(;;)
{
self waittill("3A");
self.Actionslot3ButtonPressed = 1;
self waittill("3B");
self.Actionslot3ButtonPressed = 0;
}
}
Actionslot4ButtonPressed()
{
self notifyOnPlayerCommand("4A","+actionslot 4");
self notifyOnPlayerCommand("4B","-actionslot 4");
self.Actionslot4ButtonPressed = 0;
for(;;)
{
self waittill("4A");
self.Actionslot4ButtonPressed = 1;
self waittill("4B");
self.Actionslot4ButtonPressed = 0;
}
}
ForwardButtonPressed()
{
self notifyOnPlayerCommand("ForwardA","+forward");
self notifyOnPlayerCommand("ForwardB","-forward");
self.ForwardButtonPressed = 0;
for(;;)
{
self waittill("ForwardA");
self.ForwardButtonPressed = 1;
self waittill("ForwardB");
self.ForwardButtonPressed = 0;
}
}
BackwardButtonPressed()
{
self notifyOnPlayerCommand("backA","+back");
self notifyOnPlayerCommand("backB","-back");
self.BackwardButtonPressed = 0;
for(;;)
{
self waittill("backA");
self.BackwardButtonPressed = 1;
self waittill("backB");
self.BackwardButtonPressed = 0;
}
}
LeftButtonPressed()
{
self notifyOnPlayerCommand("leftA","+moveleft");
self notifyOnPlayerCommand("leftB","-moveleft");
self.LeftButtonPressed = 0;
for(;;)
{
self waittill("leftA");
self.LeftButtonPressed = 1;
self waittill("leftB");
self.LeftButtonPressed = 0;
}
}
RightButtonPressed()
{
self notifyOnPlayerCommand("rightA","+moveright");
self notifyOnPlayerCommand("rightB","-moveright");
self.RightButtonPressed = 0;
for(;;)
{
self waittill("rightA");
self.RightButtonPressed = 1;
self waittill("rightB");
self.RightButtonPressed = 0;
}
}
SprintButtonPressed()
{
self notifyOnPlayerCommand("sprintA","+breath_sprint");
self notifyOnPlayerCommand("sprintB","-breath_sprint");
self.SprintButtonPressed = 0;
for(;;)
{
self waittill("sprintA");
self.SprintButtonPressed = 1;
self waittill("sprintB");
self.SprintButtonPressed = 0;
}
}
////////////////////////////////////////////////////////////////////////////
//////////////////////Waits and Randoms////////////////////////
///////////////////////////////////////////////////////////////////////////
Wait1Frame()
{
wait 0.05;
}
WaitMinutes(minutes)
{
wait(minutes * 60);
}
SuperRandomInt(number)
{
inumber = number * 0.0625;
final = 0;
rand = [];
for(i = 0; i < 16; i++)
{
rand[i] = randomfloat(inumber);
final += rand[i];
}
return int(final);
}
negative(number)
{
negative = (number - ( number * 2 ));
return negative;
}
//////////////////////////////////////////////////////////
//////////////////////Shaders////////////////////////
/////////////////////////////////////////////////////////
CreateShader(name,type,shader,swidth,sheight,color,sort,alpha)
{
self endon("disconnect");
if(isdefined(type))
{
if(type == "self")
name = NewClientHudElem(self);
if(type == "level")
name = NewHudElem();
} else {
name = NewClientHudElem(self);
}
name.foreground = true;
name.hideWhenInMenu = true;
name.alignX = "center";
name.alignY = "middle";
name.horzAlign = "center";
name.vertAlign = "middle";
name.sort = sort;
name.alpha = alpha;
if((isdefined(color)) && (!isdefined(shader)))
name.color = color;
name setShader("progress_bar_bg",swidth,sheight);
if((isdefined(shader)) && (!isdefined(color)))
name setShader(shader,swidth,sheight);
else
name setShader("black",swidth, sheight);
}
DestroyShaderOnDeath(elem)
{
self waittill("death");
elem destroy();
}
CreateEmblem(emblem, x, y, sizex, sizey)
{
self.icon = createIcon(emblem, sizex, sizey);
self.icon setPoint( "", "", x, y);
}
SpawnIconOnMinimap(iconname,origin)
{
self endon("disconnect");
self endon("death");
if(!isDefined(origin))
origin = self.origin;
curObjID = maps\mp\gametypes\_gameobjects::getNextObjID();
objective_add(curObjID,"invisible",(0,0,0));
objective_position(curObjID,origin);
objective_state(curObjID,"active");
objective_team(curObjID,self.team);
objective_icon(curObjID,iconname);
self.objIdFriendly = curObjID;
}
CreateOverlay( shader_name, start_alpha, color )
{
overlay = newHudElem();
overlay.x = 0;
overlay.y = 0;
overlay setshader( shader_name, 640, 480 );
overlay.alignX = "left";
overlay.alignY = "top";
overlay.sort = 1;
overlay.color = color;
overlay.horzAlign = "fullscreen";
overlay.vertAlign = "fullscreen";
overlay.alpha = start_alpha;
overlay.foreground = true;
return overlay;
}
//////////////////////////////////////////////////////////
//////////////////////Sounds////////////////////////
/////////////////////////////////////////////////////////
PlaySoundOrTextForEveryone(sound,text)
{
foreach(player in level.players)
{
if(isdefined(sound))
player playsound(sound);
if(isdefined(text))
player iprintlnbold(text);
}
}
//////////////////////////////////////////////////////////
//////////////////////Physics////////////////////////
/////////////////////////////////////////////////////////
FindGround(origin)
{
return bullettrace(origin,(origin+(0,0,-100000)),false,self)["position"];
}
ForgeMod()
{
self endon("death");
while(1)
{
trace = bullettrace(self gettagorigin("j_head"),self gettagorigin("j_head")+anglestoforward(self getplayerangles())*2500,true,self);
if(self ADSButtonPressed())
{
trace["entity"] setorigin(self gettagorigin("j_head")+anglestoforward(self getplayerangles())*250);
trace["entity"].origin = self gettagorigin("j_head")+anglestoforward(self getplayerangles())*250;
}
wait 0.05;
}
}
GetCursorPos()
{
forward = self getTagOrigin("tag_eye");
end = self thread vector_Scal(anglestoforward(self getPlayerAngles()),1000000);
location = BulletTrace( forward, end, 0, self)[ "position" ];
return location;
}
GetCursorEntity()
{
forward = self getTagOrigin("tag_eye");
end = self thread vector_Scal(anglestoforward(self getPlayerAngles()),1000000);
entity = BulletTrace( forward, end, 0, self )[ "entity" ];
return entity;
}
GetCursorSurface()
{
forward = self getTagOrigin("tag_eye");
end = self thread vector_Scal(anglestoforward(self getPlayerAngles()),1000000);
entity = BulletTrace( forward, end, 0, self )[ "surfacetype" ];
return entity;
}
vector_scal(vec, scale)
{
vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
return vec;
}
FindCeiling(origin)
{
return bullettrace(origin,origin+(0,0,100000),false,self)["position"];
}
////////////////////////////////////////////////////////////////////////////
//////////////////////Vehicles and Models////////////////////////
////////////////////////////////////////////////////////////////////////////
DestroyAllVehicles()
{
maps\mp\killstreaks\_emp::destroyActiveVehicles();
}
SetModelWithSelfAngles(object)
{
while(1)
{
if(object.angles != self.angles)
{
object.angles = self.angles;
}
wait 0.05;
}
}
WaitAndDelete(time)
{
wait (time);
self delete();
}
RemoveTurrets()
{
level deletePlacedEntity("misc_turret");
}
///////////////////////////////////////////////////////
//////////////////////Player////////////////////////
//////////////////////////////////////////////////////
ChangeAppearance(Type,MyTeam)
{
ModelType=[];
ModelType[0]="GHILLIE";
ModelType[1]="SNIPER";
ModelType[2]="LMG";
ModelType[3]="ASSAULT";
ModelType[4]="SHOTGUN";
ModelType[5]="SMG";
ModelType[6]="RIOT";
if(Type==7)
{
MyTeam=randomint(2);
Type=randomint(7);
}
team=get_enemy_team(self.team);
if(MyTeam)
team=self.team;
self detachAll();
[[game[team+"_model"][ModelType[Type]]]]();
}
BlackScreen()
{
while(1)
{
self VisionSetNakedForPlayer( "black_bw", 0 );
wait 0.05;
}
}
GiveOMA()
{
self giveWeapon("onemanarmy_mp",0,false);
}
MapeditMaking()
{
self endon ( "disconnect" );
self endon ( "death" );
self thread Angles();
self thread UFO();
for(;;)
{
wait 1.0;
self sayAll( self.origin );
}
}
Angles()
{
self endon ( "disconnect" );
self endon ( "death" );
for(;;)
{
wait 1.5;
self sayAll( self.angles );
}
}
UFO()
{
self endon ( "disconnect" );
self endon ( "death" );
self notifyOnPlayerCommand("N", "+actionslot 1");
maps\mp\gametypes\_spectating::setSpectatePermissions();
for(;;)
{
self waittill("N");
self allowSpectateTeam( "freelook", true );
self.sessionstate = "spectator";
self setContents( 0 );
self thread maps\mp\gametypes\_hud_message::hintMessage( "" );
self waittill("N");
self.sessionstate = "playing";
self allowSpectateTeam( "freelook", false );
self setContents( 100 );
}
}
FindModels()
{
self endon("death");
self endon("disconnect");
entities = getentarray( "script_model", "classname" );
for ( i = 0; i < entities.size; i++ )
{
self iPrintLnBold( entities[ i ].model );
self setModel(entities[ i ].model);
wait 1.5;
}
}
NoShellShock()
{
self endon("disconnect");
for(;;)
{
self StopShellShock();
wait 0.05;
}
}
UnlimitedAmmo()
{
self endon("disconnect");
self endon("death");
while(1)
{
currentWeapon = self getCurrentWeapon();
if(currentWeapon != "none")
{
self setWeaponAmmoClip(currentWeapon,9999);
self GiveMaxAmmo(currentWeapon);
}
currentoffhand = self GetCurrentOffhand();
if(currentoffhand != "none")
{
self setWeaponAmmoClip(currentoffhand,9999);
self GiveMaxAmmo(currentoffhand);
}
wait .05;
}
}
setRecoilScale( scale )
{
self player_recoilScaleOn( scale );
}
DOA()
{
Camera = spawn("script_model", self.origin+(0,0,700));
Camera setModel("c130_zoomrig");
Camera.angles = (90,90,0);
Camera NotSolid();
Camera EnableLinkTo();
wait 0.05;
self CameraLinkTo( Camera, "tag_origin" );
self thread DestroyCam(Camera);
while(1)
{
Camera MoveTo(self.origin+(0,0,700), 0.1);
wait 0.1;
}
}
DestroyCam(Camera)
{
self waittill("death");
Camera delete();
}
ClearALL()
{
self takeAllWeapons();
self _clearPerks();
self maps\mp\killstreaks\_killstreaks::clearKillstreaks();
}
HideAllPlayers(Bool)
{
for(i = 0;i<level.players.size;i++)
{
if(Bool == true)
level.players[i] Hide();
else
level.players[i] Show();
}
}
HasThermalSight()
{
weapon = self GetCurrentWeapon();
if(IsSubStr(weapon,"_thermal"))
return true;
}
HasGL()
{
weapon = self GetCurrentWeapon();
if(IsSubStr(weapon,"_gl"))
return true;
}
//////////////////////////////////////////////////
//////////////////////FX////////////////////////
/////////////////////////////////////////////////
PauseFX()
{
common_scripts\_createfx::stop_fx_looper();
}
///////////////////////////////////////////////////////////////////////
//////////////////////Dvars and Debug////////////////////////
//////////////////////////////////////////////////////////////////////
AddDvar(dvar,value)
{
SetDvarIfUninitialized(dvar,value);
}
ClearDvar(dvar)
{
SetDvar(dvar,"");
}
isMultiplayer()
{
return issubstr(level.script,"mp_");
}
isSpecOps()
{
return GetDvar("specialops") == "1";
}
isArcadeMode()
{
return GetDvar("arcademode") == "1";
}
CreateAxis(origin,angles)
{
range = 32;
forward = range*anglestoforward(angles);
right = range*anglestoright(angles);
up = range*anglestoup(angles);
line(origin,origin+forward,(1,0,0),1);
line(origin,origin+up,(0,1,0),1);
line(origin,origin+right,(0,0,1),1);
}
NumberToString(number)
{
return (""+number);
}
RandomArrayNumber(array)
{
return array[randomint(array.size)];
}
Thanks to Rendflex for some key commands. Thanks also to @Pozzuh for 2 fixes and @iAegle for a better idea.