Raised This Month: $ Target: $400
 0% 

Solved Spawn players with weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Koremai
Junior Member
Join Date: Sep 2016
Old 09-26-2016 , 05:31   Spawn players with weapons
Reply With Quote #1

I'm trying to come up with a simple script that will give people weapons whenever they respawn. GivePlayerItem works, the only problem is that NMRH uses a custom inventory system and auto pickup on touch is disabled. So the weapons just stay on the ground. I need to force players to pick them up somehow. AcceptEntityInput with "use" should work but I can't quite grasp its syntax. Current code:

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

public Plugin:myinfo 

    
name "Weapons On Spawn"
    
author " "
    
description "Gives weapons on spawn"
    
version "0.1"
    
url "http://www.sourcemod.net" 
}; 

public 
OnPluginStart() 

    
HookEvent("player_spawn"Event_Spawn); 


public 
Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast

    new 
GetClientOfUserId(GetEventInt(event"userid")); 
    if (
IsClientInGame(i) && !IsFakeClient(i)) 
    { 
        
GivePlayerItem (i"fa_cz858");
        
GivePlayerItem (i"me_machete");
        
GivePlayerItem (i"exp_grenade");
        
GivePlayerItem (i"item_first_aid");
    } 

How to add AcceptEntityInput to make the players pick up the fa_cz858, me_machete, exp_grenade and item_first_aid?

Also since this script spams weapons it would be cool to have something that deletes dropped items whenever a player dies. This is just a bonus though and not really a priority. Roughly, the plugin should:

- spawn set of items on spawn event [done]
- make player pick up the items
- remove dropped items when the player dies

Any tips/help would be greatly appreciated!

Last edited by Koremai; 10-01-2016 at 01:05.
Koremai is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-26-2016 , 08:22   Re: [NMRiH] Spawn players with weapons
Reply With Quote #2

Have you try game entity called
https://developer.valvesoftware.com/...e_player_equip
__________________
Do not Private Message @me
Bacardi is offline
Koremai
Junior Member
Join Date: Sep 2016
Old 09-26-2016 , 09:44   Re: [NMRiH] Spawn players with weapons
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
Yes. It doesn't work in NMRiH because of the custom inventory thing. Besides, I would like this to be done through a plugin and without having to edit the maps.

I found a plugin that uses a similar approach to mine, but with menus:

Code:
-snip-

switch (action)
	{
		case MenuAction_End: { CloseHandle(hHandle); }

		case MenuAction_Select:
		{
			new String:sInfo[32];
			GetMenuItem(hHandle, param2, sInfo, sizeof(sInfo));
			
			new iWeapon = GivePlayerItem(param1, g_sWeaponEntityNames[StringToInt(sInfo)]);
			AcceptEntityInput(iWeapon, "use", param1, param1);
			PrintToChat2(param1, "%s You have chosen a \x04%s\x01.", sNotice, g_sWeaponDisplayNames[StringToInt(sInfo)]);
		}

-snip-
I just can't quite understand how to adapt it to my plugin

Last edited by Koremai; 09-26-2016 at 10:02.
Koremai is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 09-26-2016 , 11:08   Re: [NMRiH] Spawn players with weapons
Reply With Quote #4

try this:
PHP Code:
#include <sourcemod> 
#include <sdktools> 

static String:weapons[][] = {
    
"fa_cz858",
    
"me_machete",
    
"exp_grenade",
    
"item_first_aid"
}

public 
Plugin:myinfo 

    
name "Weapons On Spawn"
    
author " "
    
description "Gives weapons on spawn"
    
version "0.1"
    
url "http://www.sourcemod.net" 
}; 

public 
OnPluginStart() 

    
HookEvent("player_spawn"Event_Spawn); 


public 
Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast

    new 
client GetClientOfUserId(GetEventInt(event"userid")); 
    if (
IsClientInGame(client) && !IsFakeClient(client)) 
    {
        new 
item;
        for (new 
ii<4i++)
        {
            
item GivePlayerItem(clientweapons[i]);
            if(
item != -1)
            {
                if(!
AcceptEntityInput(item"use"clientclient)) LogError("Can't AcceptEntityInput 'use' for item '%s'"weapons[i]);
            }
            else 
LogError("Can't give item '%s' to the player"weapons[i]);
        }
    } 

__________________

Last edited by Grey83; 09-26-2016 at 17:08.
Grey83 is offline
Koremai
Junior Member
Join Date: Sep 2016
Old 09-26-2016 , 14:09   Re: [NMRiH] Spawn players with weapons
Reply With Quote #5

Hmm, doesn't seem to work , player spawns without weapons every time.

Code:
L 09/26/2016 - 15:05:21: [weaponspawn.smx] Can't give item 'fa_cz858' to the player
L 09/26/2016 - 15:05:21: [weaponspawn.smx] Can't give item 'me_machete' to the player
L 09/26/2016 - 15:05:21: [weaponspawn.smx] Can't give item 'exp_grenade' to the player
L 09/26/2016 - 15:05:21: [weaponspawn.smx] Can't give item 'item_first_aid' to the player
Thanks for the help so far!
Koremai is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 09-26-2016 , 16:00   Re: [NMRiH] Spawn players with weapons
Reply With Quote #6

It was necessary to add a timer to make it work
PHP Code:
#include <sourcemod> 
#include <sdktools> 

static String:weapons[][] = {
    
"fa_cz858",
    
"me_machete",
    
"exp_grenade",
    
"item_first_aid"
}

public 
Plugin:myinfo 

    
name "Weapons On Spawn"
    
author " "
    
description "Gives weapons on spawn"
    
version "0.1"
    
url "https://forums.alliedmods.net/showthread.php?t=288290" 
}; 

public 
OnPluginStart() 

    
HookEvent("player_spawn"Event_Spawn); 


public 
Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast

    
CreateTimer(1.0GiveItemsToPlayerGetClientOfUserId(GetEventInt(event"userid")));
}

public 
Action:GiveItemsToPlayer(Handle:timerany:client)

    if (
IsClientInGame(client) && IsPlayerAlive(client)) 
    {
        new 
item;
        for (new 
ii<4i++)
        {
            
item GivePlayerItem(clientweapons[i]);
            if(
item == -1LogError("Can't give item '%s' to '%N'"weapons[i], client);
            else if(!
AcceptEntityInput(item"use"clientclient)) LogError("Can't AcceptEntityInput 'use' for item '%s'"weapons[i]);
        }
    } 

__________________

Last edited by Grey83; 09-26-2016 at 17:09.
Grey83 is offline
Koremai
Junior Member
Join Date: Sep 2016
Old 09-26-2016 , 23:52   Re: [NMRiH] Spawn players with weapons
Reply With Quote #7

That did the trick, thanks a lot man, it will come in real handy for my server!
Koremai is offline
gavei
New Member
Join Date: Sep 2023
Old 09-08-2023 , 04:32   Re: [NMRiH] Spawn players with weapons
Reply With Quote #8

Quote:
Originally Posted by Grey83 View Post
PHP Code:
#include <sourcemod> 
#include <sdktools> 

static String:weapons[][] = {
    
"fa_cz858",
    
"me_machete",
    
"exp_grenade",
    
"item_first_aid"
}

public 
Plugin:myinfo 

    
name "Weapons On Spawn"
    
author " "
    
description "Gives weapons on spawn"
    
version "0.1"
    
url "https://forums.alliedmods.net/showthread.php?t=288290" 
}; 

public 
OnPluginStart() 

    
HookEvent("player_spawn"Event_Spawn); 


public 
Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast

    
CreateTimer(1.0GiveItemsToPlayerGetClientOfUserId(GetEventInt(event"userid")));
}

public 
Action:GiveItemsToPlayer(Handle:timerany:client)

    if (
IsClientInGame(client) && IsPlayerAlive(client)) 
    {
        new 
item;
        for (new 
ii<4i++)
        {
            
item GivePlayerItem(clientweapons[i]);
            if(
item == -1LogError("Can't give item '%s' to '%N'"weapons[i], client);
            else if(!
AcceptEntityInput(item"use"clientclient)) LogError("Can't AcceptEntityInput 'use' for item '%s'"weapons[i]);
        }
    } 



Hello, Grey83. I want to use this because I don't want to use a give weapons mod or use a hotkey to give myself weapons. I just want to immediately have those weapons in my inventory on spawn.

But how do I use this? Do I just save this as a text file and then change the extension to .sp? Or do I save it as a text file and then change the extension to .smx? Do I need both a .sp and a .smx and if so how do I get both? I used to use AlliedMods plugins around 5-8 years ago, but I completely forgot everything and I'm clueless on what to do now. So I could really use your help on telling me what to do.

These are the three weapons/items that I want:
item_maglite
fa_glock17
tool_welder

If by any chance I need to convert something, could you please refer me to a website that will let me convert online without downloading anything? I think I was able to do that at one time. Hopefully I won't need to install software on my computer.

Anyway, I hope you will help me out. I haven't played NMRiH in over five years and I am thinking about playing it again, but I would like to make some changes first.
gavei is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 09-08-2023 , 07:52   Re: [NMRiH] Spawn players with weapons
Reply With Quote #9

Quote:
Originally Posted by gavei View Post
These are the three weapons/items that I want:
item_maglite
fa_glock17
tool_welder
Attached Files
File Type: sp Get Plugin or Get Source (nmrih_equip_on_spawn.sp - 105 views - 966 Bytes)
__________________
Grey83 is offline
gavei
New Member
Join Date: Sep 2023
Old 09-08-2023 , 23:10   Re: [NMRiH] Spawn players with weapons
Reply With Quote #10

Thank you, Grey83!
gavei 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 03:11.


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