CS:GO VScript Examples: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added external links.)
(Added a script)
Line 6: Line 6:
player <- Entities.FindByClassnameNearest( "player", buttonReference.GetOrigin(), 512 ); // find the nearest player within 512 hammer units to the button's origin and create a variable.
player <- Entities.FindByClassnameNearest( "player", buttonReference.GetOrigin(), 512 ); // find the nearest player within 512 hammer units to the button's origin and create a variable.
</source>
</source>
===Turn Decoys into Nukes===
<source lang=cpp>//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);
ent.EmitSound(EXPLOSION_SOUND);
exp.SetOrigin(origin);
exp.SetOwner(owner);
EntFireByHandle(exp, "Explode", "", 0.1, owner,owner);
ent.Destroy();
DispatchParticleEffect("explosion_c4_500", origin, origin);
}
}
}</source>


{{todo}}
{{todo}}

Revision as of 04:59, 4 March 2016

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);
					
			ent.EmitSound(EXPLOSION_SOUND);
									
			exp.SetOrigin(origin);
			exp.SetOwner(owner);
									
			EntFireByHandle(exp, "Explode", "", 0.1, owner,owner);						
			ent.Destroy();						
			DispatchParticleEffect("explosion_c4_500", origin, origin);
		}		
	}
}

[Todo]

See also

External links