SA-MP Forums Archive
Problem with command function - 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)
+--- Thread: Problem with command function (/showthread.php?tid=540665)



Problem with command function - semara123 - 06.10.2014

i already wrote script like this
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(newkeys == KEY_ACTION && issliding[playerid] == 0 && notstarted[playerid] == 0)
	{
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 497)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 487)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 488)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 563)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 447)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 469)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 417)
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 548)
		{
		    //OnPlayerStartSliding (use for other conditions)
		    
		    //end
		    for(new p=0; p<howmanyropes; p++)
            {
				if(issliding[p] == 0) { tempplayerid[playerid] = p; }
			}
			if(tempplayerid[playerid] == -1) { return GameTextForPlayer(playerid,"Technical Problem",1000,1); }
		
	        GetVehiclePos(GetPlayerVehicleID(playerid),helix[playerid],heliy[playerid],heliz[playerid]);
	        issliding[playerid] = GetPlayerVehicleID(playerid);
	        issliding[tempplayerid[playerid]] = 1;
	        notstarted[playerid] = 2;
			GetPlayerPos(playerid,tempx[playerid],tempy[playerid],tempz[playerid]); //alte position speichern
			GetPlayerFacingAngle(playerid,tempa[playerid]);
	        SetTimerEx("checkseil",1000,0,"ifff",GetPlayerVehicleID(playerid),helix[playerid],heliy[playerid],heliz[playerid]);
			vworld[playerid] = GetPlayerVirtualWorld(playerid);
			RemovePlayerFromVehicle(playerid); //spieler aus heli raus
			SetPlayerVirtualWorld(playerid,10);
			ApplyAnimation(playerid,"ped","abseil",4.0,0,0,0,1,0); //animation startem
			SetVehiclePos(chopper[playerid],tempx[playerid],tempy[playerid],tempz[playerid]);
			SetPlayerPosFindZ(playerid,tempx[playerid],tempy[playerid],tempz[playerid]);
			SetPlayerCameraPos(playerid,tempx[playerid],tempy[playerid]+10,tempz[playerid]+10);
			SetPlayerCameraLookAt(playerid,helix[playerid],heliy[playerid],heliz[playerid]);
			TextDrawShowForPlayer(playerid,blind);
			SetTimerEx("lowzcatch",zcatchtimer,0,"ifff",playerid,tempx[playerid],tempy[playerid],tempz[playerid]);

			//OnCalculateZ (use for messages or optical things)
			
			//end
            
			for(new i=0; i<ropelength; i++)
			{
				b_SetObjectPos(seile[i][tempplayerid[playerid]],tempx[playerid],tempy[playerid],tempz[playerid] - i);
			}
			return 1;
		}
		return 0;
	}
	if(newkeys == KEY_ACTION && issliding[playerid] != 0 && notstarted[playerid] == 1)
	{
	    //OnPlayerLetFall
	    
	    //end
	    new Float:landex,Float:landey,Float:landez;
	    GetPlayerPos(playerid,landex,landey,landez);
	    SetPlayerPos(playerid,landex,landey,landez);
	    issliding[playerid] = 0;
	    issliding[tempplayerid[playerid]] = 0;
	    notstarted[playerid] = 0;
	    GameTextForPlayer(playerid,"You let yourself falling",1000,1);
	    for(new i=0; i<ropelength; i++)
		{
			b_SetObjectPos(seile[i][tempplayerid[playerid]],tempx[playerid],tempy[playerid],tempz[playerid] - i);
		}
	    return 1;
	}
	return 1;
}
after i run it in my server the filterscript loaded correctly but the command doesnt work please help me
sorry for my bad english


Re: Problem with command function - Vince - 06.10.2014

Yeah, well, you're basically nesting all your if-statements. That's what you get for improper use of braces. It compiles like:
pawn Код:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 497)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 487)
    {
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 488)
        {
            // And so on ....
        }
    }
}
Which means the model has to be ALL of those vehicles. That is of course never the case and thus your code fails. You could fix it by appending the OR operator to each line (||) but the cleanest solution is a simple switch.
pawn Код:
switch(GetVehicleModel(GetPlayerVehicleID(playerid))
{
    case 497, 487 /* etc, etc */:
    {
        // code
    }
}



Re: Problem with command function - semara123 - 09.10.2014

It not working