Raised This Month: $32 Target: $400
 8% 

Try to give certain weapons to all players by using a runloop ,it doesn't work well.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sunen
Member
Join Date: Jul 2020
Old 07-27-2020 , 02:59   Try to give certain weapons to all players by using a runloop ,it doesn't work well.
Reply With Quote #1

I wrote a runloop like this tring to give weapons to every player (include bot).
Code:
for (int playerindex = 2; playerindex <= MaxClients; playerindex++)
	{
		int iCmdFlags = GetCommandFlags("give");
		SetCommandFlags("give", iCmdFlags & ~FCVAR_CHEAT);
		FakeClientCommand(playerindex, "give katana");
		FakeClientCommand(playerindex, "give rifle_ak47");
		SetCommandFlags("give", iCmdFlags);
	}
If i set playerindex=0 ,it doesn't start.If 1,sometimes it works,sometimes not.
I wonder why is this?
Is there other ways to give weapons to everyplayer?
Sunen is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 07-27-2020 , 03:02   Re: Try to give certain weapons to all players by using a runloop ,it doesn't work we
Reply With Quote #2

Code:
for (int i = 1; i <= MaxClients; i++)
{
	if (!IsClientInGame(i) || !IsPlayerAlive(i))
		continue;
	
	GivePlayerItem(i, "katana");
	GivePlayerItem(i, "rifle_ak47");
}
Assuming those entity names are correct, this should give those items to all players that can accept them.
Drixevel is offline
Sunen
Member
Join Date: Jul 2020
Old 07-27-2020 , 04:35   Re: Try to give certain weapons to all players by using a runloop ,it doesn't work we
Reply With Quote #3

Quote:
Originally Posted by Drixevel View Post
Code:
for (int i = 1; i <= MaxClients; i++)
{
	if (!IsClientInGame(i) || !IsPlayerAlive(i))
		continue;
	
	GivePlayerItem(i, "katana");
	GivePlayerItem(i, "rifle_ak47");
}
Assuming those entity names are correct, this should give those items to all players that can accept them.
ty,i will try this.
Sunen is offline
Sunen
Member
Join Date: Jul 2020
Old 07-27-2020 , 05:40   Re: Try to give certain weapons to all players by using a runloop ,it doesn't work we
Reply With Quote #4

Quote:
Originally Posted by Drixevel View Post
Code:
for (int i = 1; i <= MaxClients; i++)
{
	if (!IsClientInGame(i) || !IsPlayerAlive(i))
		continue;
	
	GivePlayerItem(i, "katana");
	GivePlayerItem(i, "rifle_ak47");
}
Assuming those entity names are correct, this should give those items to all players that can accept them.
The compilation went well.
But this doesn't work in game.
Code:
#include <sdktools>
GivePlayerItem(i, "katana");
GivePlayerItem(i, "weapon_ak47");
And these code works well.
Code:
int iCmdFlags = GetCommandFlags("give");
SetCommandFlags("give", iCmdFlags & ~FCVAR_CHEAT);
FakeClientCommand(playerindex, "give katana");
FakeClientCommand(playerindex, "give rifle_ak47");
SetCommandFlags("give", iCmdFlags);
I wonder if "GivePlayerItem" doesn't work in l4d2?
Sunen is offline
Reply



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 23:40.


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