SetPVarInt issues
#1

Hey.

I have been attempting to use SetPVarInt to share information between my gamemode and a filterscript. Obviously the weapons should be serversided so I made use of an include I found that looks like this:

Код:
stock ResetWeapons(playerid)
{

	SetPVarInt(playerid, "Brass Knuckles", 0);
	SetPVarInt(playerid, "Golf Club", 0);
	SetPVarInt(playerid, "Nite Stick", 0);
	SetPVarInt(playerid, "Knife", 0);
	SetPVarInt(playerid, "Baseball Bat", 0);
	SetPVarInt(playerid, "Shovel", 0);
	SetPVarInt(playerid, "Pool Cue", 0);
	SetPVarInt(playerid, "Katana", 0);
	SetPVarInt(playerid, "Chainsaw", 0);
	SetPVarInt(playerid, "Heat Seaker", 0);
	SetPVarInt(playerid, "Dildo", 0);
	SetPVarInt(playerid, "Vibrator", 0);
	SetPVarInt(playerid, "Flowers", 0);
	SetPVarInt(playerid, "Cane", 0);
	SetPVarInt(playerid, "Teargas", 0);
	SetPVarInt(playerid, "Bomb", 0);
	SetPVarInt(playerid, "HS Rocket", 0);
	SetPVarInt(playerid, "Flamethrower", 0);
	SetPVarInt(playerid, "Satchel Explosives", 0);
	SetPVarInt(playerid, "Spray Can", 0);
	SetPVarInt(playerid, "Fire Extinguisher", 0);
	SetPVarInt(playerid, "Camera", 0);
	SetPVarInt(playerid, "Night Vis Goggles", 0);
	SetPVarInt(playerid, "Thermal Goggles", 0);
 	SetPVarInt(playerid, "Grenade", 0);
	SetPVarInt(playerid, "Molotov Cocktail", 0);
	SetPVarInt(playerid, "Colt 45", 0);
	SetPVarInt(playerid, "Silenced Pistol", 0);
	SetPVarInt(playerid, "Desert Eagle", 0);
	SetPVarInt(playerid, "Shotgun", 0);
	SetPVarInt(playerid, "Sawn-off Shotgun", 0);
	SetPVarInt(playerid, "Combat Shotgun", 0);
	SetPVarInt(playerid, "UZI", 0);
	SetPVarInt(playerid, "MP5", 0);
	SetPVarInt(playerid, "AK47", 0);
	SetPVarInt(playerid, "M4", 0);
	SetPVarInt(playerid, "Tec9", 0);
	SetPVarInt(playerid, "Rifle", 0);
	SetPVarInt(playerid, "Sniper Rifle", 0);
 	SetPVarInt(playerid, "Rocket Launcher", 0);
  	SetPVarInt(playerid, "Minigun", 0);
	ResetPlayerWeapons(playerid);
}

stock GivePlayerServerWeapon(playerid, weapid, ammo)
{
	new gunname[32];
	GivePlayerWeapon(playerid, weapid, ammo);
	GetWeaponName(weapid, gunname, sizeof(gunname));
	SetPVarInt(playerid, gunname, GetPVarInt(playerid, gunname) +ammo);
}
I then made a quick test by doing this:

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE)
    {
               if(IsPlayerConnected(playerid))
                {
                        new weaponid = GetPlayerWeapon(playerid);
                        new weapname[32];
			GetWeaponName(weaponid, weapname, sizeof(weapname));
			if(GetPVarInt(playerid, weapname) < 1) return SendClientMessage(playerid, -1, "Hack");
			SetPVarInt(playerid, weapname, GetPVarInt(playerid, weapname) -1);

                }
        }
        return 1;
}
When I first tested it there were no issues, but that was because I didn't try hard enough. After playing around for a while with some weapons I realised that after clicking a bit too many times it would start returning the message "Hack" with weapons that weren't spawned in. It seems that after a while the setpvarint goes to 0 or something goes wrong. I'm just not sure what it is.
Reply
#2

Using PVars are not recommended since they become buggy on the long run... Replace them with variables... Or you can delete the PVars and Reset using them.
Reply
#3

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
Using PVars are not recommended since they become buggy on the long run... Replace them with variables... Or you can delete the PVars and Reset using them.
Using variables won't allow me to use the feature across different scripts though, will it? I'm going to move away from pvars now and I suppose I'll have to implement the filterscripts into the GM. A bit annoying but I suppose there is no other way?
Reply
#4

I don't know what you're using these for but I wanna point out that it's pointless and using an array would be better. For example, a player can't hold a Desert Eagle (24) or Colt 45 (22) at the same time because they're in the same weapons slot (2).
Reply
#5

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
I don't know what you're using these for but I wanna point out that it's pointless and using an array would be better. For example, a player can't hold a Desert Eagle (24) or Colt 45 (22) at the same time because they're in the same weapons slot (2).
I'm not sure how to get started, any tutorials around for stuff like this?
Reply
#6

Are there any way I'd be able to use some like pHasDeagle and whenever a player is given a deagle by the server then it sets it to 1 and whenever the player drops that specific weapon it sets it to 0 and then use that cross script? Are there any way I can allow a filterscript to change the pHasDeagle values if it's implemented in the Gamemode?
Reply
#7

I made the FS into an include and make use of enums to tell the server whether or not the player has the weapon. Thanks for the help guys
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)