Raised This Month: $12 Target: $400
 3% 

[EXTENSION][CS:GO] VScript Functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backup
Senior Member
Join Date: Jul 2010
Location: Česká Republika
Old 01-25-2018 , 03:21   [EXTENSION][CS:GO] VScript Functions
Reply With Quote #1

VScript Functions


What is this?
This is a SourceMod extension that exposes VScript functions and methods to be used by modders.


How to build this?
Just as any other AMBuild project:
  1. Install AMBuild
  2. Download Half-Life 2 SDK, Metamod:Source and SourceMod
  3. Code:
    mkdir build && cd build
  4. Code:
    python ../configure.py --hl2sdk-root=??? --mms-path=??? --sm-path=??? --sdks=csgo
  5. Code:
    ambuild


How to use this?

You need to either load this module by creating vscriptfun.autoload file in the extensions folder or use the metamod menu to perform a manual load. After a map is loaded, two files are created:
  • data/vscriptfun/natives - a list of natives that will be registered
  • scripting/include/vscriptfun.inc - a sourcepawn include file, containing all the interesting classes
Now you can simply create a plugin that uses VScript functions.

Example of generated vscriptfun.inc file (January 2018, CS:GO):
PHP Code:
public Extension:__ext_vscriptfun = {
    
name "VScript Functions",
    
file "vscriptfun.ext",
#if defined AUTOLOAD_EXTENSIONS
    
autoload 1,
#else
    
autoload 0,
#endif
#if defined REQUIRE_EXTENSIONS
    
required 1,
#else
    
required 0,
#endif
};

enum HScript {
    
HSCRIPT_NULL 0,
    
HSCRIPT_INVALID = -1
}

methodmap VSF {
    
//Generate a random floating point number within a range, inclusive
    //float RandomFloat(float, float);
    
public static native float RandomFloat(float afloat b);

    
//Generate a random integer within a range, inclusive
    //integer RandomInt(integer, integer);
    
public static native int RandomInt(int aint b);

    
//Print a hud message on all clients
    //void ShowMessage(cstring);
    
public static native void ShowMessage(char[] a);

    
//Send a string to the console as a command
    //void SendToConsole(cstring);
    
public static native void SendToConsole(char[] a);

    
//Send a string that gets executed on the server as a ServerCommand
    //void SendToConsoleServer(cstring);
    
public static native void SendToConsoleServer(char[] a);

    
//Get the name of the map.
    //cstring GetMapName();
    
public static native void GetMapName(char[] retValint maxLength);

    
//Run the single player maps in a continuous loop.
    //boolean LoopSinglePlayerMaps();
    
public static native bool LoopSinglePlayerMaps();

    
//given 2 points & ent to ignore, return fraction along line that hits world or models
    //float TraceLine(vector, vector, hscript);
    
public static native float TraceLine(float[] afloat[] bHScript c);

    
//Get the current server time
    //float Time();
    
public static native float Time();

    
//Get the time spent on the server in the last frame
    //float FrameTime();
    
public static native float FrameTime();

    
//#EntFire:Generate and entity i/o event
    //void DoEntFire(cstring, cstring, cstring, float, hscript, hscript);
    
public static native void DoEntFire(char[] achar[] bchar[] cfloat dHScript eHScript f);

    
//Generate and entity i/o event. First parameter is an entity instance.
    //void EntFireByHandle(hscript, cstring, cstring, float, hscript, hscript);
    
public static native void EntFireByHandle(HScript achar[] bchar[] cfloat dHScript eHScript f);

    
//#UniqueString:Generate a string guaranteed to be unique across the life of the script VM, with an optional root string.
    //Useful for adding data to tables when not sure what keys are already in use in that table.
    //cstring DoUniqueString(cstring);
    
public static native void DoUniqueString(char[] achar[] retValint maxLength);

    
//Create a scene entity to play the specified scene.
    //hscript CreateSceneEntity(cstring);
    
public static native HScript CreateSceneEntity(char[] a);

    
//Draw a debug overlay box
    //void DebugDrawBox(vector, vector, vector, integer, integer, integer, integer, float);
    
public static native void DebugDrawBox(float[] afloat[] bfloat[] cint dint eint fint gfloat h);

    
//Draw a debug overlay box
    //void DebugDrawLine(vector, vector, integer, integer, integer, boolean, float);
    
public static native void DebugDrawLine(float[] afloat[] bint cint dint ebool ffloat g);

    
//Execute a script (internal)
    //boolean DoIncludeScript(cstring, hscript);
    
public static native bool DoIncludeScript(char[] aHScript b);

    
//Create a physics prop
    //hscript CreateProp(cstring, vector, cstring, integer);
    
public static native HScript CreateProp(char[] afloat[] bchar[] cint d);

    
//Records achievement event or progress
    //void RecordAchievementEvent(cstring, integer);
    
public static native void RecordAchievementEvent(char[] aint b);

    
//Gets the level of 'developer'
    //integer GetDeveloperLevel();
    
public static native int GetDeveloperLevel();

    
//Dispatches a one-off particle system
    //void DispatchParticleEffect(cstring, vector, vector);
    
public static native void DispatchParticleEffect(char[] afloat[] bfloat[] c);

    
//Sets whether the player has completed the initial portion of the training map.
    //void ScriptSetPlayerCompletedTraining(boolean);
    
public static native void ScriptSetPlayerCompletedTraining(bool a);

    
//Returns true if the player has completed the initial portion of the training map.
    //boolean ScriptGetPlayerCompletedTraining();
    
public static native bool ScriptGetPlayerCompletedTraining();

    
//Sets the player's best time for completing the timed course.
    //void ScriptSetBestTrainingCourseTime(integer);
    
public static native void ScriptSetBestTrainingCourseTime(int a);

    
//Gets the player's best time for completing the timed course.
    //integer ScriptGetBestTrainingCourseTime();
    
public static native int ScriptGetBestTrainingCourseTime();

    
//Gets Valve's best time for completing the timed course.
    //integer ScriptGetValveTrainingCourseTime();
    
public static native int ScriptGetValveTrainingCourseTime();

    
//Refills ammo to max for all weapons the player has (only works in training).
    //void ScriptTrainingGivePlayerAmmo();
    
public static native void ScriptTrainingGivePlayerAmmo();

    
//Toggles the visibility of the miniscoreboard hud element.
    //void ScriptSetMiniScoreHidden(boolean);
    
public static native void ScriptSetMiniScoreHidden(bool a);

    
//Toggles the visibility of the radar hud element.
    //void ScriptSetRadarHidden(boolean);
    
public static native void ScriptSetRadarHidden(bool a);

    
//Sends an event that is just used by the instructor system to show a hint highlighting the ammo counter.
    //void ScriptHighlightAmmoCounter();
    
public static native void ScriptHighlightAmmoCounter();

    
//Shows a message box to let players know what to do next after finishing the training course.
    //void ScriptShowFinishMsgBox();
    
public static native void ScriptShowFinishMsgBox();

    
//Shows a message box in trainign when the player exits through the exit door
    //void ScriptShowExitDoorMsg();
    
public static native void ScriptShowExitDoorMsg();

    
//Returns whether the player is playing with a controller or not.
    //boolean ScriptIsLocalPlayerUsingController();
    
public static native bool ScriptIsLocalPlayerUsingController();

    
//Prints an alert message in the center print method to all players.
    //void ScriptPrintMessageCenterAll(cstring);
    
public static native void ScriptPrintMessageCenterAll(char[] a);

    
//Prints a message in chat to all players.
    //void ScriptPrintMessageChatAll(cstring);
    
public static native void ScriptPrintMessageChatAll(char[] a);

    
//Prints an alert message in the center print method to the specified team.
    //void ScriptPrintMessageCenterTeam(integer, cstring);
    
public static native void ScriptPrintMessageCenterTeam(int achar[] b);

    
//Prints a message in chat to the specified team.
    //void ScriptPrintMessageChatTeam(integer, cstring);
    
public static native void ScriptPrintMessageChatTeam(int achar[] b);

    
//Gets the current game mode.
    //integer ScriptGetGameMode();
    
public static native int ScriptGetGameMode();

    
//Gets the current game type.
    //integer ScriptGetGameType();
    
public static native int ScriptGetGameType();

    
//Get the number of rounds played so far.
    //integer ScriptGetRoundsPlayed();
    
public static native int ScriptGetRoundsPlayed();

    
//Is it warmup or not.
    //boolean ScriptIsWarmupPeriod();
    
public static native bool ScriptIsWarmupPeriod();

    
//Sets the bot quota considering the # of players connected and refreshes the spawns.
    //void ScriptCoopSetBotQuotaAndRefreshSpawns(integer);
    
public static native void ScriptCoopSetBotQuotaAndRefreshSpawns(int a);

    
//Spawns the first wave of enemies in coop.
    //void ScriptCoopMissionSpawnFirstEnemies(integer);
    
public static native void ScriptCoopMissionSpawnFirstEnemies(int a);

    
//Set the next respawn wave to happen in this many seconds.
    //void ScriptCoopMissionSetNextRespawnIn(float, boolean);
    
public static native void ScriptCoopMissionSetNextRespawnIn(float abool b);

    
//Tells the next wave of enemies to spawn in coop.  Also respawns player.
    //void ScriptCoopMissionSpawnNextWave(integer);
    
public static native void ScriptCoopMissionSpawnNextWave(int a);

    
//Respawns players only.
    //void ScriptCoopMissionRespawnDeadPlayers();
    
public static native void ScriptCoopMissionRespawnDeadPlayers();

    
//Gets the mission number for the current map - maps can have multiple missions on them.
    //integer ScriptCoopMissionGetMissionNumber();
    
public static native int ScriptCoopMissionGetMissionNumber();

    
//Resets the round time and starts the mission.
    //void ScriptCoopResetRoundStartTime();
    
public static native void ScriptCoopResetRoundStartTime();

    
//Will give the number of specified C4s to all alive CT players.
    //void ScriptCoopGiveC4sToCTs(integer);
    
public static native void ScriptCoopGiveC4sToCTs(int a);

    
//Marks one of the bonus coins as collected.
    //void ScriptCoopCollectBonusCoin();
    
public static native void ScriptCoopCollectBonusCoin();

}

//Wrapper class over KeyValues instance
methodmap VSF_CScriptKeyValues {
    public 
VSF_CScriptKeyValues(HScript handle) { return view_as<VSF_CScriptKeyValues>(handle); }

    
//Given a KeyValues object and a key name, find a KeyValues object associated with the key name
    //hscript FindKey(cstring);
    
public native HScript FindKey(char[] a);

    
//Given a KeyValues object, return the first sub key object
    //hscript GetFirstSubKey();
    
public native HScript GetFirstSubKey();

    
//Given a KeyValues object, return the next key object in a sub key group
    //hscript GetNextKey();
    
public native HScript GetNextKey();

    
//Given a KeyValues object and a key name, return associated integer value
    //integer GetKeyInt(cstring);
    
public native int GetKeyInt(char[] a);

    
//Given a KeyValues object and a key name, return associated float value
    //float GetKeyFloat(cstring);
    
public native float GetKeyFloat(char[] a);

    
//Given a KeyValues object and a key name, return associated bool value
    //boolean GetKeyBool(cstring);
    
public native bool GetKeyBool(char[] a);

    
//Given a KeyValues object and a key name, return associated string value
    //cstring GetKeyString(cstring);
    
public native void GetKeyString(char[] achar[] retValint maxLength);

    
//Given a KeyValues object and a key name, return true if key name has no value
    //boolean IsKeyEmpty(cstring);
    
public native bool IsKeyEmpty(char[] a);

    
//Given a root KeyValues object, release its contents
    //void ReleaseKeyValues();
    
public native void ReleaseKeyValues();

}

//!The global list of entities
methodmap VSF_CEntities {
    
//Begin an iteration over the list of entities
    //hscript First();
    
public static native HScript First();

    
//Continue an iteration over the list of entities, providing reference to a previously found entity
    //hscript Next(hscript);
    
public static native HScript Next(HScript a);

    
//Creates an entity by classname
    //hscript CreateByClassname(cstring);
    
public static native HScript CreateByClassname(char[] a);

    
//Find entities by class name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindByClassname(hscript, cstring);
    
public static native HScript FindByClassname(HScript achar[] b);

    
//Find entities by name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindByName(hscript, cstring);
    
public static native HScript FindByName(HScript achar[] b);

    
//Find entities within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindInSphere(hscript, vector, float);
    
public static native HScript FindInSphere(HScript afloat[] bfloat c);

    
//Find entities by targetname. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindByTarget(hscript, cstring);
    
public static native HScript FindByTarget(HScript achar[] b);

    
//Find entities by model name. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindByModel(hscript, cstring);
    
public static native HScript FindByModel(HScript achar[] b);

    
//Find entities by name nearest to a point.
    //hscript FindByNameNearest(cstring, vector, float);
    
public static native HScript FindByNameNearest(char[] afloat[] bfloat c);

    
//Find entities by name within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindByNameWithin(hscript, cstring, vector, float);
    
public static native HScript FindByNameWithin(HScript achar[] bfloat[] cfloat d);

    
//Find entities by class name nearest to a point.
    //hscript FindByClassnameNearest(cstring, vector, float);
    
public static native HScript FindByClassnameNearest(char[] afloat[] bfloat c);

    
//Find entities by class name within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindByClassnameWithin(hscript, cstring, vector, float);
    
public static native HScript FindByClassnameWithin(HScript achar[] bfloat[] cfloat d);

}

//!Player voice listeners
methodmap VSF_CPlayerVoiceListener {
    public 
VSF_CPlayerVoiceListener(HScript handle) { return view_as<VSF_CPlayerVoiceListener>(handle); }

    
//Returns whether the player specified is speaking.
    //boolean IsPlayerSpeaking(integer);
    
public native bool IsPlayerSpeaking(int a);

    
//Returns the number of seconds the player has been continuously speaking.
    //float GetPlayerSpeechDuration(integer);
    
public native float GetPlayerSpeechDuration(int a);

}

//Root class of all server-side entities
methodmap VSF_CBaseEntity {
    public 
VSF_CBaseEntity(HScript handle) { return view_as<VSF_CBaseEntity>(handle); }

    public static 
VSF_CBaseEntity FromEntIndex(int entindex) { return view_as<VSF_CBaseEntity>(GetEntityAddress(entindex)); }

    
//Adds an I/O connection that will call the named function when the specified output fires
    //void ConnectOutput(cstring, cstring);
    
public native void ConnectOutput(char[] achar[] b);

    
//Removes a connected script function from an I/O event.
    //void DisconnectOutput(cstring, cstring);
    
public native void DisconnectOutput(char[] achar[] b);

    
//integer GetHealth();
    
public native int GetHealth();

    
//void SetHealth(integer);
    
public native void SetHealth(int a);

    
//integer GetMaxHealth();
    
public native int GetMaxHealth();

    
//void SetMaxHealth(integer);
    
public native void SetMaxHealth(int a);

    
//void SetModel(cstring);
    
public native void SetModel(char[] a);

    
//Returns the name of the model
    //cstring GetModelName();
    
public native void GetModelName(char[] retValint maxLength);

    
//Plays a sound from this entity.
    //void EmitSound(cstring);
    
public native void EmitSound(char[] a);

    
//Stops a sound on this entity.
    //void StopSound(cstring);
    
public native void StopSound(char[] a);

    
//Precache a sound for later playing.
    //void PrecacheSoundScript(cstring);
    
public native void PrecacheSoundScript(char[] a);

    
//Returns float duration of the sound. Takes soundname and optional actormodelname.
    //float GetSoundDuration(cstring, cstring);
    
public native float GetSoundDuration(char[] achar[] b);

    
//cstring GetClassname();
    
public native void GetClassname(char[] retValint maxLength);

    
//cstring GetName();
    
public native void GetName(char[] retValint maxLength);

    
//Get the entity name stripped of template unique decoration
    //cstring GetPreTemplateName();
    
public native void GetPreTemplateName(char[] retValint maxLength);

    
//vector GetOrigin();
    
public native void GetOrigin(float[] retVal);

    
//SetAbsOrigin
    //void SetAbsOrigin(vector);
    
public native void SetAbsOrigin(float[] a);

    
//void SetOrigin(vector);
    
public native void SetOrigin(float[] a);

    
//Get the forward vector of the entity
    //vector GetForwardVector();
    
public native void GetForwardVector(float[] retVal);

    
//Get the left vector of the entity
    //vector GetLeftVector();
    
public native void GetLeftVector(float[] retVal);

    
//Get the up vector of the entity
    //vector GetUpVector();
    
public native void GetUpVector(float[] retVal);

    
//Set the orientation of the entity to have this forward vector
    //void SetForwardVector(vector);
    
public native void SetForwardVector(float[] a);

    
//vector GetVelocity();
    
public native void GetVelocity(float[] retVal);

    
//void SetVelocity(vector);
    
public native void SetVelocity(float[] a);

    
//Set the local angular velocity - takes float pitch,yaw,roll velocities
    //void SetAngularVelocity(float, float, float);
    
public native void SetAngularVelocity(float afloat bfloat c);

    
//Get the local angular velocity - returns a vector of pitch,yaw,roll
    //vector GetAngularVelocity();
    
public native void GetAngularVelocity(float[] retVal);

    
//Get vector to center of object - absolute coords
    //vector GetCenter();
    
public native void GetCenter(float[] retVal);

    
//Get vector to eye position - absolute coords
    //vector EyePosition();
    
public native void EyePosition(float[] retVal);

    
//Set entity pitch, yaw, roll
    //void SetAngles(float, float, float);
    
public native void SetAngles(float afloat bfloat c);

    
//Get entity pitch, yaw, roll as a vector
    //vector GetAngles();
    
public native void GetAngles(float[] retVal);

    
//void SetSize(vector, vector);
    
public native void SetSize(float[] afloat[] b);

    
//Get a vector containing min bounds, centered on object
    //vector GetBoundingMins();
    
public native void GetBoundingMins(float[] retVal);

    
//Get a vector containing max bounds, centered on object
    //vector GetBoundingMaxs();
    
public native void GetBoundingMaxs(float[] retVal);

    
//void Destroy();
    
public native void Destroy();

    
//Sets this entity's owner
    //void SetOwner(hscript);
    
public native void SetOwner(HScript a);

    
//integer GetTeam();
    
public native int GetTeam();

    
//void SetTeam(integer);
    
public native void SetTeam(int a);

    
//If in hierarchy, retrieves the entity's parent
    //hscript GetMoveParent();
    
public native HScript GetMoveParent();

    
//If in hierarchy, walks up the hierarchy to find the root parent
    //hscript GetRootMoveParent();
    
public native HScript GetRootMoveParent();

    
//hscript FirstMoveChild();
    
public native HScript FirstMoveChild();

    
//hscript NextMovePeer();
    
public native HScript NextMovePeer();

    
//@
    //boolean __KeyValueFromString(cstring, cstring);
    
public native bool __KeyValueFromString(char[] achar[] b);

    
//@
    //boolean __KeyValueFromFloat(cstring, float);
    
public native bool __KeyValueFromFloat(char[] afloat b);

    
//@
    //boolean __KeyValueFromInt(cstring, integer);
    
public native bool __KeyValueFromInt(char[] aint b);

    
//@
    //boolean __KeyValueFromVector(cstring, vector);
    
public native bool __KeyValueFromVector(char[] afloat[] b);

    
//Get a KeyValue class instance on this entity's model
    //hscript GetModelKeyValues();
    
public native HScript GetModelKeyValues();

    
//void PrecacheModel(cstring);
    
public native void PrecacheModel(char[] a);

    
//void PrecacheScriptSound(cstring);
    
public native void PrecacheScriptSound(char[] a);

    
//Ensure that an entity's script scope has been created
    //boolean ValidateScriptScope();
    
public native bool ValidateScriptScope();

    
//Retrieve the script-side data associated with an entity
    //hscript GetScriptScope();
    
public native HScript GetScriptScope();

    
//Retrieve the unique identifier used to refer to the entity within the scripting system
    //cstring GetScriptId();
    
public native void GetScriptId(char[] retValint maxLength);

    
//Gets this entity's owner
    //hscript GetOwner();
    
public native HScript GetOwner();

    
//integer entindex();
    
public native int entindex();

}

//Animating models
methodmap VSF_CBaseAnimating VSF_CBaseEntity {
    public 
VSF_CBaseAnimating(HScript handle) { return view_as<VSF_CBaseAnimating>(handle); }

    public static 
VSF_CBaseAnimating FromEntIndex(int entindex) { return view_as<VSF_CBaseAnimating>(GetEntityAddress(entindex)); }

    
//Get the named attachement id
    //integer LookupAttachment(cstring);
    
public native int LookupAttachment(char[] a);

    
//Get the attachement id's origin vector
    //vector GetAttachmentOrigin(integer);
    
public native void GetAttachmentOrigin(int afloat[] retVal);

    
//Get the attachement id's angles as a p,y,r vector
    //vector GetAttachmentAngles(integer);
    
public native void GetAttachmentAngles(int afloat[] retVal);

    
//Ask whether the main sequence is done playing
    //boolean IsSequenceFinished();
    
public native bool IsSequenceFinished();

    
//Sets a bodygroup
    //void SetBodygroup(integer, integer);
    
public native void SetBodygroup(int aint b);

}

//hostage_carriable_prop
methodmap VSF_CHostage VSF_CBaseEntity {
    public 
VSF_CHostage(HScript handle) { return view_as<VSF_CHostage>(handle); }

    public static 
VSF_CHostage FromEntIndex(int entindex) { return view_as<VSF_CHostage>(GetEntityAddress(entindex)); }

    
//Get whether the hostage is currently being carried or not
    //boolean IsBeingCarried();
    
public native bool IsBeingCarried();

}

//Server-side camera entity
methodmap VSF_CTriggerCamera VSF_CBaseEntity {
    public 
VSF_CTriggerCamera(HScript handle) { return view_as<VSF_CTriggerCamera>(handle); }

    public static 
VSF_CTriggerCamera FromEntIndex(int entindex) { return view_as<VSF_CTriggerCamera>(GetEntityAddress(entindex)); }

    
//get camera's current fov setting as integer
    //integer GetFov();
    
public native int GetFov();

    
//set camera's current fov in integer degrees and fov change rate as float
    //void SetFov(integer, float);
    
public native void SetFov(int afloat b);

}

//func_train
methodmap VSF_CFuncTrackTrain VSF_CBaseEntity {
    public 
VSF_CFuncTrackTrain(HScript handle) { return view_as<VSF_CFuncTrackTrain>(handle); }

    public static 
VSF_CFuncTrackTrain FromEntIndex(int entindex) { return view_as<VSF_CFuncTrackTrain>(GetEntityAddress(entindex)); }

    
//Get a position on the track x seconds in the future
    //vector GetFuturePosition(float, float);
    
public native void GetFuturePosition(float afloat bfloat[] retVal);

}

//Choreographed scene which controls animation and/or dialog on one or more actors.
methodmap VSF_CSceneEntity VSF_CBaseEntity {
    public 
VSF_CSceneEntity(HScript handle) { return view_as<VSF_CSceneEntity>(handle); }

    public static 
VSF_CSceneEntity FromEntIndex(int entindex) { return view_as<VSF_CSceneEntity>(GetEntityAddress(entindex)); }

    
//Returns length of this scene in seconds.
    //float EstimateLength();
    
public native float EstimateLength();

    
//If this scene is currently playing.
    //boolean IsPlayingBack();
    
public native bool IsPlayingBack();

    
//If this scene is currently paused.
    //boolean IsPaused();
    
public native bool IsPaused();

    
//Adds a team (by index) to the broadcast list
    //void AddBroadcastTeamTarget(integer);
    
public native void AddBroadcastTeamTarget(int a);

    
//Removes a team (by index) from the broadcast list
    //void RemoveBroadcastTeamTarget(integer);
    
public native void RemoveBroadcastTeamTarget(int a);

    
//given an entity reference, such as !target, get actual entity from scene object
    //hscript FindNamedEntity(cstring);
    
public native HScript FindNamedEntity(char[] a);

    
//given a dummy scene name and a vcd string, load the scene
    //boolean LoadSceneFromString(cstring, cstring);
    
public native bool LoadSceneFromString(char[] achar[] b);

}

//The player entity.
methodmap VSF_CBasePlayer VSF_CBaseAnimating {
    public 
VSF_CBasePlayer(HScript handle) { return view_as<VSF_CBasePlayer>(handle); }

    public static 
VSF_CBasePlayer FromEntIndex(int entindex) { return view_as<VSF_CBasePlayer>(GetEntityAddress(entindex)); }

    
//Returns true if the player is in noclip mode.
    //boolean IsNoclipping();
    
public native bool IsNoclipping();

}

//game_coopmission_manager
methodmap VSF_CGameCoopMissionManager VSF_CBaseEntity {
    public 
VSF_CGameCoopMissionManager(HScript handle) { return view_as<VSF_CGameCoopMissionManager>(handle); }

    public static 
VSF_CGameCoopMissionManager FromEntIndex(int entindex) { return view_as<VSF_CGameCoopMissionManager>(GetEntityAddress(entindex)); }

    
//Get the number of waves the players have completed
    //integer GetWaveNumber();
    
public native int GetWaveNumber();

}

//env_entity_maker
methodmap VSF_CEnvEntityMaker VSF_CBaseEntity {
    public 
VSF_CEnvEntityMaker(HScript handle) { return view_as<VSF_CEnvEntityMaker>(handle); }

    public static 
VSF_CEnvEntityMaker FromEntIndex(int entindex) { return view_as<VSF_CEnvEntityMaker>(GetEntityAddress(entindex)); }

    
//Create an entity at the location of the maker
    //void SpawnEntity();
    
public native void SpawnEntity();

    
//Create an entity at the location of a specified entity instance
    //void SpawnEntityAtEntityOrigin(hscript);
    
public native void SpawnEntityAtEntityOrigin(HScript a);

    
//Create an entity at the location of a named entity
    //void SpawnEntityAtNamedEntityOrigin(cstring);
    
public native void SpawnEntityAtNamedEntityOrigin(char[] a);

    
//Create an entity at a specified location and orientaton, orientation is Euler angle in degrees (pitch, yaw, roll)
    //void SpawnEntityAtLocation(vector, vector);
    
public native void SpawnEntityAtLocation(float[] afloat[] b);

}

//Player
methodmap VSF_CBaseMultiplayerPlayer VSF_CBasePlayer {
    public 
VSF_CBaseMultiplayerPlayer(HScript handle) { return view_as<VSF_CBaseMultiplayerPlayer>(handle); }

    public static 
VSF_CBaseMultiplayerPlayer FromEntIndex(int entindex) { return view_as<VSF_CBaseMultiplayerPlayer>(GetEntityAddress(entindex)); }

}

//Animated characters who have vertex flex capability.
methodmap VSF_CBaseFlex VSF_CBaseAnimating {
    public 
VSF_CBaseFlex(HScript handle) { return view_as<VSF_CBaseFlex>(handle); }

    public static 
VSF_CBaseFlex FromEntIndex(int entindex) { return view_as<VSF_CBaseFlex>(GetEntityAddress(entindex)); }

    
//Returns the instance of the oldest active scene entity (if any).
    //hscript GetCurrentScene();
    
public native HScript GetCurrentScene();

    
//Returns the instance of the scene entity at the specified index.
    //hscript GetSceneByIndex(integer);
    
public native HScript GetSceneByIndex(int a);


Sample script
PHP Code:
#include <sourcemod>
#include <vscriptfun>

public Plugin myinfo =
{
    
name "My First Plugin",
    
author "Me",
    
description "My first plugin ever",
    
version "1.0",
    
url "http://www.sourcemod.net/"
};

public 
void OnPluginStart()
{
    
RegAdminCmd("vsf_slap"SlapADMFLAG_GENERIC);
}

public 
Action Slap(int clientint args)
{
    if(!
client)
        return 
Plugin_Handled;
    
VSF_CBaseEntity player VSF_CBaseEntity.FromEntIndex(client);
    
    
float velocity[3];
    
player.GetVelocity(velocity);
    
velocity[0] += VSF.RandomFloat(-512.0512.0);
    
velocity[1] += VSF.RandomFloat(-512.0512.0);
    
velocity[2] += VSF.RandomFloat(0.0512.0);
    
player.SetVelocity(velocity);
    
    
player.SetHealth(player.GetHealth() - 1);
    
    
char sound[64];
    
Format(sound64"physics/flesh/flesh_impact_bullet%d.wav"VSF.RandomInt(15));
    
player.PrecacheScriptSound(sound);
    
player.EmitSound(sound);
    
    
VSF.ScriptPrintMessageChatAll("Player slapped himself with a large trout.");
    return 
Plugin_Handled;

Additional information
  • This was tested only in CS:GO, but any modern VScript-using Source game (like Dota 2) should be ok.
  • You can use CEntities class to search and browse through entities. You can use the returned handle to construct CBaseEntity or any other derived class, but don't pass it into constructors of non-entity classes like CScriptKeyValues! (unless you want to crash your server)
  • This extension used to be a part of the Gorme project.

Sources and binaries
Latest sources are availabe at github:
https://github.com/jonatan1024/vscriptfun
Binaries for windows and linux should be availabe at the github releases page:
https://github.com/jonatan1024/vscriptfun/releases

Last edited by Backup; 02-06-2018 at 18:06. Reason: added tags into the title
Backup is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 01-25-2018 , 04:03   Re: VScript Functions
Reply With Quote #2

Wow cool stuff. Especially the debug drawing stuff seems cool. I'm guessing thats what you used to draw the cross in your gorme project?
EDIT: just tested out the debugdraw stuff myself and it doesn't seem to work (unless I went wrong somewhere)

Last edited by hmmmmm; 01-25-2018 at 05:31.
hmmmmm is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 01-25-2018 , 06:32   Re: VScript Functions
Reply With Quote #3

First of all, nice release!

My question is, with this extension we could make something like in your video (map edit)? if yes then how? Its related with "DebugDrawBox"?

Quote:
Originally Posted by hmmmmm View Post
just tested out the debugdraw stuff myself and it doesn't seem to work (unless I went wrong somewhere)
Show your code (?)
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.


Last edited by Franc1sco; 01-25-2018 at 06:33.
Franc1sco is offline
Send a message via MSN to Franc1sco
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 01-25-2018 , 06:36   Re: VScript Functions
Reply With Quote #4

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <vscriptfun>

public void OnMapStart()
{
    
CreateTimer0.1Timer_DebugDraw_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE );
}

public 
Action Timer_DebugDrawHandle timer )
{
    for( 
int i 1<= MaxClientsi++ )
    {
        if( 
IsClientInGame) && !IsFakeClient) )
        {
            
PrintToServer"Drawing axis" );
            
float pos[3];
            
GetClientEyePositionipos );
            
float angles[3];
            
GetClientEyeAnglesiangles );
            
            
TR_TraceRayposanglesMASK_ALLRayType_Infinite );
            if( 
TR_DidHit() )
            {
                
TR_GetEndPositionpos );
                
DrawAxispos );
            }
        }
    }
}

void DrawAxis( const float pos[3], float s 5.0 )
{
    
float pos1[3], pos2[3];
    
    
pos1 pos;
    
pos2 pos;
    
pos1[0] -= s;
    
pos2[0] += s;
    
VSF.DebugDrawLinepos1pos225500true0.1 );
    
    
pos1 pos;
    
pos2 pos;
    
pos1[1] -= s;
    
pos2[1] += s;
    
VSF.DebugDrawLinepos1pos202550false0.1 );
    
    
pos1 pos;
    
pos2 pos;
    
pos1[2] -= s;
    
pos2[2] += s;
    
VSF.DebugDrawLinepos1pos200255false0.1 );

Also I wanted to mention that in the include file, the extension filename is specified as vsfun.ext but it builds to vscriptfun.ext, which is a bit confusing.

Last edited by hmmmmm; 01-25-2018 at 06:54.
hmmmmm is offline
Backup
Senior Member
Join Date: Jul 2010
Location: Česká Republika
Old 01-25-2018 , 07:36   Re: VScript Functions
Reply With Quote #5

Quote:
Originally Posted by hmmmmm View Post
Wow cool stuff. Especially the debug drawing stuff seems cool. I'm guessing thats what you used to draw the cross in your gorme project?
EDIT: just tested out the debugdraw stuff myself and it doesn't seem to work (unless I went wrong somewhere)
I'm not sure what I used since I lost the original script that was used in the video. But I guess it was some kind of beam tempent.

The debug stuff didn't work for me either, probably doesn't work on dedicated server at all:
https://github.com/alliedmodders/hl2...rface.cpp#L831

Quote:
Originally Posted by Franc1sco View Post
My question is, with this extension we could make something like in your video (map edit)? if yes then how? Its related with "DebugDrawBox"?
Nope, sorry. This was used only as a utility for specific entity manipulation, especially correct entity deletion.

Quote:
Originally Posted by hmmmmm View Post
Also I wanted to mention that in the include file, the extension filename is specified as vsfun.ext but it builds to vscriptfun.ext, which is a bit confusing.
Thanks! Fixed it right now. Please download the fixed version and delete the data/vscriptfun/natives file to trigger a re-generation of the include file.
__________________
Sorry for my english.
Backup is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-29-2018 , 00:42   Re: VScript Functions
Reply With Quote #6

Wow! Nice !
What about Left 4 Dead 2 VScripts ?
Vit_amin is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 01-29-2018 , 01:09   Re: VScript Functions
Reply With Quote #7

Quote:
Originally Posted by Vit_amin View Post
Wow! Nice !
What about Left 4 Dead 2 VScripts ?
You can call vscript functions in l4d2 with this stock.
however it should work in just about anygame.

Found in timocop's plugin director unlocker
https://forums.alliedmods.net/showthread.php?p=2535972

PHP Code:
/**
* Runs a single line of vscript code.
* NOTE: Dont use the "script" console command, it startes a new instance and leaks memory. Use this instead!
*
* @param sCode        The code to run.
* @noreturn
*/
stock L4D2_RunScript(const String:sCode[], any:...)
{
    static 
iScriptLogic INVALID_ENT_REFERENCE;
    if(
iScriptLogic == INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic)) {
        
iScriptLogic EntIndexToEntRef(CreateEntityByName("logic_script"));
        if(
iScriptLogic == INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic))
            
SetFailState("Could not create 'logic_script'");
        
        
DispatchSpawn(iScriptLogic);
    }
    
    static 
String:sBuffer[512];
    
VFormat(sBuffersizeof(sBuffer), sCode2);
    
    
SetVariantString(sBuffer);
    
AcceptEntityInput(iScriptLogic"RunScriptCode");

__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
Backup
Senior Member
Join Date: Jul 2010
Location: Česká Republika
Old 01-29-2018 , 15:03   Re: VScript Functions
Reply With Quote #8

Quote:
Originally Posted by Vit_amin View Post
Wow! Nice !
What about Left 4 Dead 2 VScripts ?
It should work for L4D2 too, in theory. The problem is there are no vscript headers in the L4D2 branch of HL2SDK:
https://github.com/alliedmodders/hl2sdk/tree/l4d2/
So you would need to fix the sdk first.
__________________
Sorry for my english.
Backup is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-29-2018 , 16:20   Re: VScript Functions
Reply With Quote #9

Quote:
Originally Posted by Backup View Post
It should work for L4D2 too, in theory. The problem is there are no vscript headers in the L4D2 branch of HL2SDK:
https://github.com/alliedmodders/hl2sdk/tree/l4d2/
So you would need to fix the sdk first.
If someone files an issue, I'll take a look. Should be able to backport the swarm ones with minor adjustments.

I'm impressed with this. I had an idea for something similar, but was far too lazy to execute.
psychonic is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-29-2018 , 16:25   Re: VScript Functions
Reply With Quote #10

Whenever Backup releases something it's like Christmas. Everyone's happy.
Good job, you always come up with something awesome.
__________________
klippy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode