VScripts
VScripts can be used in MIGI on hosts to tweak entities. The current implementation offers an entity for your script that never gets reset by rounds.
If you need to edit your script while playing, you'll need to restart the map (not the round) by using changelevel mapname
, otherwise you'll need to setup your code to be reloadable with a function or something.
The main script has to be named main.nut
and be placed in scripts/vscripts/yourfoldername/
, yourfoldername
being your MIGI addon's folder name without its (p_/m_) prefix.
See https://developer.valvesoftware.com/wiki/VScript for more information about VScripts.
Utility Variables
migi_addons
List of all the addons names as strings with their prefix (eg. "p_ak_gold")
migi_weapons
List of all the weapons currently in-game (MIGI and CS:GO). The structure of each item is identical to
items_game.txt
. All values are strings, but you can always parse them with tointeger() tofloat() etc...A few changes have been made to accommodate VScripts:
- Spaces becomes underscores:
in game price
->in_game_price
- Keys starting with numbers have an underscore prefix (mostly stickers):
0
->_0
Also includes additional keys for easier use:
Key Description id Identifier of the item (previously the key of the item's table in items_game.txt) team Simplified used_by_classes
that outputs the team the weapon is supposed to be formigi_addon Name of the addon this item comes from (including m/p prefix), will be "null" (string) if not from an addon translated_name English translated name of the item (if using translation strings)
Utility Functions
Signature | Description |
---|---|
void OnNewRound() | Function executed automatically when a new round is detected |
table migi_getWeaponDataByKV( string key, string value ) | Find a weapon from items_games by keyvalue |
string migi_getValueFromWeaponData( table weapon, string dict, string key ) | Returns the value of the specified key in the dict. If dict is null, the root table will be searched |
table[] migi_getWeaponsByAddon( string addon_name ) | Returns the list of weapon items from an addon |
migi_getWeaponDataByKV
and migi_getValueFromWeaponData
will both return null
if the key or table containing the key couldn't be found.
Example
This script demonstrates every feature above, it prints to the host's console the weapons of each player on new rounds, but also the available addons.
To demonstrate that the entity containing this script is kept between rounds, the round_number
variable here is incremented and printed each round.
round_number <- 0;
function OnNewRound()
{
round_number++;
printl(">> NEW ROUND! current: " + round_number);
printl("\nCurrent Addons:");
foreach( addon in migi_addons )
printl("\t"+addon);
printl("\nWeapons in the players' backpack:")
local w = null;
while(w = Entities.FindByClassname(w, "weapon_*"))
{
// weapons use viewmodels when on players
local wpnData = migi_getWeaponDataByKV("model_player", w.GetModelName());
// couldn't find the weapon data related to the model_player
if(!wpnData)
continue;
// get values from the weapon data
// you can't be certain the item will have the specified key, this function circumvents it for you.
local name = migi_getValueFromWeaponData(wpnData, "", "translated_name");
local type = migi_getValueFromWeaponData(wpnData, "visuals", "weapon_type");
local addon = (wpnData.migi_addon == "null" ? "" : " ("+wpnData.migi_addon+")" );
// again, it could be the knife, which has no price, the function will return null if not found
local price = migi_getValueFromWeaponData(wpnData, "attributes", "in_game_price");
price = price == null ? "" : " $"+price;
// concat and print them
printl("\t- "+w.GetOwner()+"\t: "+type+" | "+name+price+addon);
}
}
for(local i = 0; i<15; i++)
printl(">> This print is only called when the map spawns!");