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

Give shield to player on maps like de_mirage, de_dust2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eSTu
Junior Member
Join Date: Nov 2021
Old 11-27-2021 , 15:47   Give shield to player on maps like de_mirage, de_dust2
Reply With Quote #1

Hi, I'm trying to make plugin that will give all players that are connected to server and are alive a shield.
I can do that part with checking if player is connected.
Problem is on maps like de_mirage you can't use shields. On maps with hostages everything is working correctly.

I checked if the shield that is created has prop CanBePickUp set to 1 and it has.
Code:
void ShieldsMode(){
	for (int i = 1; i <= MaxClients; i++){
		if(IsClientInGame(i) && !IsFakeClient(i) && IsPlayerAlive(i)){
			int shield = GivePlayerItem(i, "weapon_shield");
			PrintToServer("Shield: %d", GetEntData(shield, 2732, 1)); //prints 1
		}
	}
}
On https://developer.valvesoftware.com/wiki/Weapon_shield there's said that:
Quote:
For this weapon to be purchasable and being able to pick it up, at least one func_hostage_rescue needs to be present in the map.
So I tried to create that entity when map starts
Code:
public void OnMapStart(){
	int hostageIndex = CreateEntityByName("func_hostage_rescue");
	
	if(hostageIndex != -1 && IsValidEntity(hostageIndex)){
		DispatchKeyValue(hostageIndex, "m_iName", "hostage");
		bool checkSpawn = DispatchSpawn(hostageIndex);
		if(!checkSpawn){
			PrintToServer("Can't spawn entity");
		} else {
			PrintToServer("Entity spawned");
			ActivateEntity(hostageIndex);
		}
	}
}
It doesn't work.

My last try was giving shield to player active slot but it bugged out.

Maybe i'm doing something wrong with creating entity or maybe I should use timings. I never used them before and don't know how they work. I'm out of ideas.
eSTu is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-27-2021 , 17:42   Re: Give shield to player on maps like de_mirage, de_dust2
Reply With Quote #2

Hope this not break bomb game mode. I have not tested much.
PHP Code:
// buy unused 25

#include <cstrike>
#include <sdkhooks>
#include <sdktools>

char maplist[][] = {
    
"de_dust2",
    
"de_nuke",
    
"de_mirage"
}



public 
void OnPluginStart()
{
    
HookEvent("round_start"round_startEventHookMode_PostNoCopy);
}


public 
void round_start(Event event, const char[] namebool dontBroadcast)
{
    
char mapname[MAX_NAME_LENGTH];

    if(
GetCurrentMap(mapnamesizeof(mapname)) > 1)
    {
        for(
int x 0sizeof(maplist); x++)
        {
            
// map name match with maplist and we not find entity func_hostage_rescue
            
if(StrEqual(mapnamemaplist[x], false) &&
              
FindEntityByClassname(-1"func_hostage_rescue") == -1)
            {
                
// create func_hostage_rescue
                
CreateEntityByName("func_hostage_rescue");
            }
        }
    }

__________________
Do not Private Message @me
Bacardi is offline
eSTu
Junior Member
Join Date: Nov 2021
Old 11-27-2021 , 18:30   Re: Give shield to player on maps like de_mirage, de_dust2
Reply With Quote #3

All I had to do was move code that create entity
Code:
if(FindEntityByClassname(-1, "func_hostage_rescue") == -1){
	CreateEntityByName("func_hostage_rescue");
}
from OnMapStart to round_start event. Idk if csgo removes all entities at end of round and recreate them again.

There's code that's working fine.

Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = 
{
	name = "test",
	author = "eSTu",
	description = "test properties",
	version = "0.01",
	url = ""
};

public void OnPluginStart()
{
	HookEvent("round_start", Event_Start);
}

public Action Event_Start(Event event, const char[] name, bool dontBroadcast){
	if(FindEntityByClassname(-1, "func_hostage_rescue") == -1){
		CreateEntityByName("func_hostage_rescue");
	}

	return Plugin_Handled;
}
Thanks Bacardi
eSTu is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-29-2021 , 11:08   Re: Give shield to player on maps like de_mirage, de_dust2
Reply With Quote #4

Quote:
Originally Posted by eSTu View Post
Hi, I'm trying to make plugin that will give all players that are connected to server and are alive a shield.
I can do that part with checking if player is connected.
Problem is on maps like de_mirage you can't use shields. On maps with hostages everything is working correctly.

I checked if the shield that is created has prop CanBePickUp set to 1 and it has.
Code:
void ShieldsMode(){
	for (int i = 1; i <= MaxClients; i++){
		if(IsClientInGame(i) && !IsFakeClient(i) && IsPlayerAlive(i)){
			int shield = GivePlayerItem(i, "weapon_shield");
			PrintToServer("Shield: %d", GetEntData(shield, 2732, 1)); //prints 1
		}
	}
}
On https://developer.valvesoftware.com/wiki/Weapon_shield there's said that:

So I tried to create that entity when map starts
Code:
public void OnMapStart(){
	int hostageIndex = CreateEntityByName("func_hostage_rescue");
	
	if(hostageIndex != -1 && IsValidEntity(hostageIndex)){
		DispatchKeyValue(hostageIndex, "m_iName", "hostage");
		bool checkSpawn = DispatchSpawn(hostageIndex);
		if(!checkSpawn){
			PrintToServer("Can't spawn entity");
		} else {
			PrintToServer("Entity spawned");
			ActivateEntity(hostageIndex);
		}
	}
}
It doesn't work.

My last try was giving shield to player active slot but it bugged out.

Maybe i'm doing something wrong with creating entity or maybe I should use timings. I never used them before and don't know how they work. I'm out of ideas.
Just hook touch into deleting the shield from the ground, and summon it to the player with GivePlayerItem, no?
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
eSTu
Junior Member
Join Date: Nov 2021
Old 12-01-2021 , 17:25   Re: Give shield to player on maps like de_mirage, de_dust2
Reply With Quote #5

I found another problem. Everything is working on game_mode set to 0 (casual) but all is ruined if game_mode is set to 1 (competitive). I found one way around it, if I start the game with game_mode set to 1 (competitive) and change game_mode to 0 during match, player can pick up shields and match is being played like competitive.

I'm looking for another way around, that I don't have to change game modes during game.
eSTu 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 02:47.


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