CS:GO VScript Examples

From Valve Developer Community
Revision as of 04:59, 4 March 2016 by Errur (talk | contribs) (Added a script)
Jump to: navigation, search

Counter-Strike: Global Offensive The following are example vscripts for Counter-Strike: Global Offensive.

Find the closest player to a known entity

buttonReference <- Entities.FindByName( null, "button_01" ); // find the in-game entity "button_01" and store its targetname
		player <- Entities.FindByClassnameNearest( "player", buttonReference.GetOrigin(), 512 ); // find the nearest player within 512 hammer units to the button's origin and create a variable.

Turn Decoys into Nukes

//The following script needs to be attached to something like a logic_script,
//but any other entity would work as the script will function regardless,
//as long as the entity is alive and the think function is set to Think()

EXPLOSION_SOUND <- "c4.Explode"; //This can be found in hammer's sound picker

function Precache() //If this is defined it runs automatically when the script is created
	self.PrecacheScriptSound( EXPLOSION_SOUND );

//Every 0.1 seconds this checks if any decoy_projectiles exist on the map
//When found it compares the velocity of the projectile with a 0,0,0 vector
//If true the decoy stopped moving so we can run the rest of the script.
//An env_explosion is created and configured, it's moved to the decoy's
//position and then triggered. The decoy is then killed.

function Think()
	ent <- null;
	while ((ent = Entities.FindByClassname(ent, "decoy_projectile")) != null)
		if(ent.GetVelocity().Length() == Vector(0,0,0).Length())
			owner <- ent.GetOwner();
			origin <- ent.GetOrigin();	
			exp <- Entities.CreateByClassname("env_explosion");
			exp.__KeyValueFromInt("iMagnitude", 2000);
			EntFireByHandle(exp, "Explode", "", 0.1, owner,owner);						
			DispatchParticleEffect("explosion_c4_500", origin, origin);

To do

See also

External links