SA-MP Forums Archive
[HELP] OnKeyStateChange with PVars - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] OnKeyStateChange with PVars (/showthread.php?tid=179074)



[HELP] OnKeyStateChange with PVars - Sinner - 25.09.2010

I'm trying to give a person special abilities while being in the "cardm" map. These abilities depend on how long the player has survived in the map, every x minutes the player survives I add +1 to a pvar (RewardCDM). But only when this Pvar is set to 1 it seems to work, all other values (2, 3, 4, ...) dont work in-game. I can see the messages RewardCDM() returns but it won't work when I press the fire key.

Help?

OnPlayerKeyStateChange()
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
	if(PRESSED(KEY_FIRE))
	{
		new Float:x, Float:y, Float:z;
		new Float:xx, Float:yy;
		new Float:vx, Float:vy, Float:vz;
		GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
		GetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
		GetXYInFrontOfVehicle(GetPlayerVehicleID(playerid), xx, yy, 12);

	    if ((GetPVarInt(playerid, "isincdm") >= 5) && (GetPVarInt(playerid, "cdmPvehicle")) && (GetPVarInt(playerid, "RewardCDM") == 5)) //Shoot with car
		{
			CreateExplosion(xx, yy, z, 11, 5);
			return 1;
		}
		if ((GetPVarInt(playerid, "isincdm") >= 4) && (GetPVarInt(playerid, "cdmPvehicle")) && (GetPVarInt(playerid, "RewardCDM") == 4)) //Build wall with car
		{
			SendClientMessage(playerid, COLOR_PURPLE, "nothing yet ere");
			return 1;
		}
		if ((GetPVarInt(playerid, "isincdm") >= 3) && (GetPVarInt(playerid, "cdmPvehicle")) && (GetPVarInt(playerid, "RewardCDM") == 3)) //Teleport With Car
		{
			SetVehiclePos(GetPlayerVehicleID(playerid), xx, yy, z+1);
			SetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
			return 1;
		}
		if ((GetPVarInt(playerid, "isincdm") >= 2) && (GetPVarInt(playerid, "cdmPvehicle")) && (GetPVarInt(playerid, "RewardCDM") == 2)) //Jump Higher With Car
		{
			SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z+10);
			SetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
			return 1;
		}
 		if ((GetPVarInt(playerid, "isincdm") >= 1) && (GetPVarInt(playerid, "cdmPvehicle")) && (GetPVarInt(playerid, "RewardCDM") == 1)) //Jump With Car
		{
			SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z+5);
			SetVehicleVelocity(GetPVarInt(playerid, "cdmPvehicle"), vx, vy, vz);
			return 1;
		}
	}
	return 1;
}
RewardCDM() (called when a player joins the dmzone, killed when he leaves)
Код:
public RewardCDM(playerid){
	if (!GetPVarInt(playerid, "RewardCDM"))
	{
		SetPVarInt(playerid, "RewardCDM", 1);
		SendClientMessage(playerid, COLOR_YELLOW, "[CARDM] You can now jump with your car (Key: LMB)");
		return 1;
	}
	SetPVarInt(playerid, "RewardCDM", (GetPVarInt(playerid, "RewardCDM")+1));
	if (GetPVarInt(playerid, "RewardCDM") == 2) return SendClientMessage(playerid, COLOR_YELLOW, "[CARDM] You can now jump higher with your car (Key: LMB)");
	if (GetPVarInt(playerid, "RewardCDM") == 3) return SendClientMessage(playerid, COLOR_YELLOW, "[CARDM] You can now teleport with your car (Key: LMB)");
	if (GetPVarInt(playerid, "RewardCDM") == 4) return SendClientMessage(playerid, COLOR_YELLOW, "[CARDM] You can now build an obstruction (Key: LMB)");
	if (GetPVarInt(playerid, "RewardCDM") == 5)
	{
		SendClientMessage(playerid, COLOR_YELLOW, "[CARDM] You can now shoot with your car (Key: LMB)");
		KillTimer(RewardCDMTimer);
		return 1;
	}
	return 1;
}