gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
11-29-2020
, 02:10
Re: mp5 start weapon
#11
try this
Spoiler
PHP Code:
#pragma semicolon 1 #include <sourcemod> #include <sdktools> //#include <morecolors> char g_sGameModesSelection [ 4 ][ 16 ] = { "coop" , // Coop "realism" , // Realism coop "l4d1coop" , // Left 4 Dead 1 Coop //<< not sure about this "l4d2coop" , // Left 4 Dead 2 Coop //<< but this not exist }; char g_sWeaponSelection [ 3 ][ 48 ] = { "weapon_smg" , "weapon_smg_silenced" , "weapon_smg_mp5" }; bool g_bIsGameSupported = false ; bool g_bIsWeaponGiven [ MAXPLAYERS + 1 ]; public Plugin myinfo = { name = "L4D2StartingWeapon" , author = "Lyric" , description = "L4D2 Starting Weapon" , version = "3.0" , url = "https://github.com/scooderic" }; public void OnPluginStart () { HookEvent ( "player_spawn" , EVENT_PlayerSpawn ); } public void OnMapStart () { g_bIsGameSupported = false ; char g_GameMode [ 24 ]; GetConVarString ( FindConVar ( "mp_gamemode" ), g_GameMode , sizeof ( g_GameMode )); for ( int i = 0 ; i < sizeof ( g_sGameModesSelection ) ; i ++) { if ( StrEqual ( g_GameMode , g_sGameModesSelection [ i ], false )) { g_bIsGameSupported = true ; break; } } } public void OnClientPutInServer ( int client ) { if( client > 0 ) { g_bIsWeaponGiven [ client ] = false ; } } public void EVENT_PlayerSpawn ( Event event , const char [] name , bool dontBroadcast ) { if( ! g_bIsGameSupported ) { PrintToServer ( "[StartingWeapon] Failed to give weapon, not in coop mode, or not in game." ); // if game not supported, this will spam server console. return; } int userid = event . GetInt ( "userid" ); int client = GetClientOfUserId ( userid ); if ( client > 0 && client <= MaxClients && IsClientInGame ( client ) && ! IsClientObserver ( client )) { CreateTimer ( 0.1 , Timer_GiveWeapon , userid ); } } public Action Timer_GiveWeapon ( Handle timer , any userid ) { int client = GetClientOfUserId ( userid ); if ( client > 0 && client <= MaxClients && IsClientInGame ( client ) && ! g_bIsWeaponGiven [ client ]) { g_bIsWeaponGiven [ client ] = true ; int weaponIndex = GetPlayerWeaponSlot ( client , 0 ); if ( weaponIndex == - 1 ) { int rand = GetRandomInt ( 0 , ( sizeof ( g_sWeaponSelection ) - 1 )); QuickCheat ( client , "give" , g_sWeaponSelection [ rand ]); } } } void QuickCheat ( int client , const char [] cmd , const char [] arg ) { int flags = GetCommandFlags ( cmd ); SetCommandFlags ( cmd , flags & ~ FCVAR_CHEAT ); FakeClientCommand ( client , "%s %s" , cmd , arg ); SetCommandFlags ( cmd , flags ); }
Edit:
The create timer can be a problem if everyone spawn and the server refresh and respawn everybody.
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
Last edited by GsiX; 11-29-2020 at 02:26 .