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

Trying to save weapons and load them.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Aae
Junior Member
Join Date: Jun 2016
Old 03-20-2017 , 09:54   Trying to save weapons and load them.
Reply With Quote #1

Hi

I have made some code to store all players weapons and be able to load these weapons at a later time, however this is not working. It prints out the weapon_name as the same ID (not weapon_m4a1 for example) for primary and secondary and it gives me an m4a4 instead of an m4a1-s as a primary - it doesn't even give me a weapon for secondary.

Thanks!

Code:
saveItems()
{
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && (GetClientTeam(i) == 2 || GetClientTeam(i) == 3))
		{
			priWeap[i] = ""; //reset weapon items
			secWeap[i] = "";
			new weapon = GetPlayerWeaponSlot(i, CS_SLOT_PRIMARY);
			if(weapon != -1)
			{
				if (IsValidEntity(weapon))
				{
					decl String:weapon_name[32];
					GetEntityClassname(weapon, weapon_name, 32);
					priWeap[i] = weapon_name;
					PrintToChatAll("%d", weapon_name);
				}
			}
			
			
			weapon = GetPlayerWeaponSlot(i, CS_SLOT_SECONDARY);
			if(weapon != -1)
			{
				if (IsValidEntity(weapon))
				{
					decl String:weapon_name[32];
					GetEntityClassname(weapon, weapon_name, 32);
					secWeap[i] = weapon_name;
					PrintToChatAll("%d", weapon_name);
				}
			}
		}
	}
}

loadItems()
{
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && (GetClientTeam(i) == 2 || GetClientTeam(i) == 3))
		{
			if(GetPlayerWeaponSlot(i, CS_SLOT_PRIMARY) != -1)
			{
				RemovePlayerItem(i, CS_SLOT_PRIMARY);
			}
			
			if(GetPlayerWeaponSlot(i, CS_SLOT_SECONDARY) != -1)
			{
				RemovePlayerItem(i, CS_SLOT_SECONDARY);
			}
			
			if(!StrEqual(priWeap[i], "", false))
			{
				GivePlayerItem(i, priWeap[i]);
			}
			
			if(!StrEqual(secWeap[i], "", false))
			{
				GivePlayerItem(i, secWeap[i]);
			}
		}
	}
}

Last edited by Aae; 03-20-2017 at 09:55.
Aae is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 03-20-2017 , 15:21   Re: Trying to save weapons and load them.
Reply With Quote #2

Check this out! Yeah!
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Aae
Junior Member
Join Date: Jun 2016
Old 03-21-2017 , 10:12   Re: Trying to save weapons and load them.
Reply With Quote #3

Quote:
Originally Posted by KissLick View Post
Check this out! Yeah!
Thanks for this, however I am slightly confused with the offset, could you explain this to me and how I calculate it for the primary and secondary weapon?
Aae is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 03-22-2017 , 08:54   Re: Trying to save weapons and load them.
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?p=2499989
__________________
ambn 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 22:57.


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