An attempt at creating a jQuery-like library for CS:GO's Vscript API. Is it really useful? Maybe not... You will have to find out.
Download csQuery.nut from the latest stable release and place it in
csgo/scripts/vscripts.Reference it in a script. Referencing it multiple time will not impact performance. Example:
IncludeScript("csQuery")You can start
thinking about how stupid this idea isusing csQuery!
Just like in the inspiration of this library, in order to do stuff with entities you first need to select these entities. There are 3 selectors:
.: Classname#: Targetname*: Everything
local texts = csQuery.Find(".point_worldtext");
local text_1 = csQuery.Find("#text_1");
local all = csQuery.Find('*');In addition, you can also pass a CBaseEntity instance as the argument.
local player = csQuery.Find(activator);// Calls the callback for every entity. The callback will be pased the CBaseEntity as an argument.QueryArrayEach(functioncallback);// Calls the callback for every entity. The callback will be pased the CBaseEntity and the index of it in the array as an argument.QueryArrayEachWithIndex(functioncallback);// Set the given KeyValue.QueryArraySetKeyValue(stringkey,objectvalue);// Hides the entities by setting their rendermodes to 10 (Don't render) and, if not asked otherwise, solidity to 0 (Not solid).QueryArrayHide(boolremoveCollisions=true);// Shows the entities by setting their rendermodes and collisionmodes to the default/given ones.QueryArrayShow(intrendermode=0,intcollisions=6);// Fires the given input (action) of the entities passing several optional parameters if given.QueryArrayEntFire(stringaction,stringvalue="",floatdelay=0.0,CBaseEntityactivator=null,CBaseEntitycaller=null);// Starts listening for the given output. In case it fires, the callback is called. The id is used to stop listening.QueryArrayOn(stringoutput,functioncallback,stringid);// Stops listening to the given output. The callback removed is the one identified with the id.QueryArrayOff(stringoutput,stringid);// Saves the given value under the given key in the first entity's scope. // NOTE: Data saved will be stored throughout the entire match.QueryArraySaveData(stringkey,objectvalue);// Returns whether data under the given key has already been stored in the first entity's scope.boolHasData(stringkey);// Returns the value under the given key in the first entity's scope. // NOTE: Will throw an exception if SaveData() has not been used at all.objectGetData(stringkey);// Returns a table which contains all data stored in the first entity's scope through SaveData().// NOTE: Will throw an exception if SaveData() has not been used at all.tableGetData();// The passed function is used as a test for each entity in the array. `this` (environment object) is the current entity.QueryArrayFilter(functionfltr);// Precaches each model in the array. // NOTE: Models are only precached once regardless of the length of the array.QueryArrayPrecacheModels(string[]models);// Returns the number of entities in the array.intLength();// Returns the CBaseEntity handle of the entity with the given index.QueryArrayGet(intindex);// Returns a QuerryArray with only the entity with the given index.CBaseEntityEq(intindex);// Returns a QuerryArray with only the first entity in the QuerryArray.CBaseEntityFirst();csQuery.Find(".point_worldtext").SetKeyValue("message", "Hello World");
csQuery.Find("#my_trigger_once").On("OnTrigger", function() {
printl("My trigger has been triggered!")
}, "FooBar");
// Note that you can chain any of the functions together (except the ones which do not return `QueryArray`).
csQuery.Find("#my_prop_dynamic").Hide().SetKeyValue("skin", 1);