Thread: [Solved] Storing user ID's
View Single Post
Author Message
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to know, weather boy
Old 09-03-2017 , 13:30   Storing user ID's
Reply With Quote #1

I'm working on a plugin that would allow the user to buy healing bullets which would return 60% of the damage done to your enemy as health.

Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#define PLUGIN "Healing Bullets"
#define AUTHOR "Dracula Mafioso"
#define VERSION "1.0"
new purchased
new attackerid
new savedattackerid
new damage
new health
new weapon
new clip
new ammocount
public plugin_init()
{
	register_plugin(PLUGIN,VERSION,AUTHOR);
	register_event("Damage", "takedamage","b", "2>1");
	register_clcmd("+attack", "reducebullets", 0);
	register_clcmd("healingbullets", "CmdBuy", 0, "Buys healing bullets");
}
public CmdBuy(id)
{
	weapon = get_user_weapon(id, clip, _);
	switch(weapon)
	{
		case CSW_USP:
		{
			if(purchased == 0)
			{
				client_print(id, print_center, "You already have purchased it!");
				return PLUGIN_HANDLED
			}
			cs_set_weapon_ammo(weapon, 12);
			client_print(id, print_center, "You have purchased 1 clip of healing bullets");
			ammocount = 12;
		}
	}
}
public reducebullets(attackerid)
{
	if(purchased == 0)
	{
		return PLUGIN_HANDLED
	}
	if(ammocount == 0)
	{
		purchased = 0;
		return PLUGIN_HANDLED;
	}
	ammocount--
	savedattackerid = attackerid
}
public takedamage(id)
{
	damage = read_data(2)
	if(damage <= 4)
	{
		return PLUGIN_HANDLED;
	}
	health = get_user_health(savedattackerid);
	set_user_health(savedattackerid, 50);
	client_print(0, print_chat, "Attacker hp: %d", health);
}
Ignore the fact that it's mostly incomplete with most important checks omitted from it, I can't progress on everything else when I can't store the attacker's/ the person who purchased the upgrade ID.

I need to store the person who bought the upgrade's ID so I can make a distinction when setting his health in the takedamage() function.
When I run it and do damage, it displays this:


From what I can tell it's either:
1. Not fetching the ID or
2. Not storing the ID properly


set_user_health is there is to test if the ID is being saved and the client_print is there too for debugging purposes.
What to do?

Last edited by Reel mafioso; 09-04-2017 at 15:04. Reason: Solved issue
Reel mafioso is offline