SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/06/2018, 09:35 AM   #1
Dreandor
Little Clucker
 
Join Date: Dec 2017
Posts: 15
Reputation: 0
Default key pressed

Hey,
i have a problem. Everytime I press FIRE, it goes only through the first if.

Code:
new iMaterial[][Material] = {
    {657, -1609.61829, -2692.89697, 47.30786, "Baum \n 'Schlagen' zum abbauen"},
    {747, -1627.54919, -2705.54858, 47.59386, "Stein \n 'Schlagen' zum abbauen"}
};
Code:
	
else if(PRESSED(KEY_FIRE))
	{
		if(GetPlayerVehicleID(playerid) == 0)
 		{
			for(new i=0; i<sizeof(iMaterial); i++)
			{
				if(!IsPlayerInRangeOfPoint(playerid, 2, iMaterial[i][m_x], iMaterial[i][m_y], iMaterial[i][m_z]))continue;
				if(GetObjectModel(iMaterial[i][modelid] == 657))
				{
		 			if(GetPlayerWeapon(playerid) == 4)
				 	{
			 			TextDrawShowForPlayer(playerid, Holz[playerid]);
					 	SetTimerEx("KaputtMaterial", 1500, false, "i", playerid);
			 		  	PlayerInfo[playerid][pHolz] += 5;
				 	}
				}
			 	else if(GetObjectModel(iMaterial[i][modelid] == 747))
			 	{
					if(GetPlayerWeapon(playerid) == 4)
					{
						TextDrawShowForPlayer(playerid, Stein[playerid]);
					 	SetTimerEx("KaputtMaterial", 1500, false, "i", playerid);
					 	PlayerInfo[playerid][pStein] += 5;
				 	}
				}
 			}
 		}
	}
Dreandor is offline   Reply With Quote
Old 13/06/2018, 12:50 PM   #2
JasonRiggs
Gangsta
 
Join Date: Jul 2016
Location: My bedroom.
Posts: 744
Reputation: 39
Default Re: key pressed

What are you trying to do?
__________________


Discord: Riggs #5210
JasonRiggs is offline   Reply With Quote
Old 13/06/2018, 12:59 PM   #3
Dreandor
Little Clucker
 
Join Date: Dec 2017
Posts: 15
Reputation: 0
Default Re: key pressed

When you are near an object and have a knife, you'll get wood or stone. It depends on which object you stand.
Dreandor is offline   Reply With Quote
Old 13/06/2018, 07:56 PM   #4
xMoBi
Big Clucker
 
xMoBi's Avatar
 
Join Date: Jul 2017
Location: Islamic Republic of Pakistan
Posts: 110
Reputation: 26
Default Re: key pressed

here:

PHP Code:
else if (PRESSED(KEY_FIRE))
{
    if (!
GetPlayerVehicleID(playerid))
    {
        new 
objectweaponid GetPlayerWeapon(playerid), i;

        for(; 
sizeof iMateriali++)
        {
            if (!
IsPlayerInRangeOfPoint(playerid2iMaterial[i][m_x], iMaterial[i][m_y], iMaterial[i][m_z])) continue;

            
object GetObjectModel(iMaterial[i][modelid]);
            switch (object)
            {
                case 
657:
                {
                    if (
weaponid == 4)
                    {
                        
TextDrawShowForPlayer(playeridHolz[playerid]);
                        
SetTimerEx("KaputtMaterial"1500false"i"playerid);
                        
PlayerInfo[playerid][pHolz] += 5;
                        return 
1;
                    }
                }
                case 
747:
                {
                    if (
weaponid == 4)
                    {
                        
TextDrawShowForPlayer(playeridStein[playerid]);
                        
SetTimerEx("KaputtMaterial"1500false"i"playerid);
                        
PlayerInfo[playerid][pStein] += 5;
                        return 
1;
                    }
                }
            }
        }
    }

xMoBi is offline   Reply With Quote
Old 13/06/2018, 08:33 PM   #5
Dreandor
Little Clucker
 
Join Date: Dec 2017
Posts: 15
Reputation: 0
Default Re: key pressed

Quote:
Originally Posted by xMoBi View Post
here:

PHP Code:
else if (PRESSED(KEY_FIRE))
{
    if (!
GetPlayerVehicleID(playerid))
    {
        new 
objectweaponid GetPlayerWeapon(playerid), i;

        for(; 
sizeof iMateriali++)
        {
            if (!
IsPlayerInRangeOfPoint(playerid2iMaterial[i][m_x], iMaterial[i][m_y], iMaterial[i][m_z])) continue;

            
object GetObjectModel(iMaterial[i][modelid]);
            switch (object)
            {
                case 
657:
                {
                    if (
weaponid == 4)
                    {
                        
TextDrawShowForPlayer(playeridHolz[playerid]);
                        
SetTimerEx("KaputtMaterial"1500false"i"playerid);
                        
PlayerInfo[playerid][pHolz] += 5;
                        return 
1;
                    }
                }
                case 
747:
                {
                    if (
weaponid == 4)
                    {
                        
TextDrawShowForPlayer(playeridStein[playerid]);
                        
SetTimerEx("KaputtMaterial"1500false"i"playerid);
                        
PlayerInfo[playerid][pStein] += 5;
                        return 
1;
                    }
                }
            }
        }
    }

it doesn't work. I used printf to see which point didn't go.
At
Code:
object = GetObjectModel(iMaterial[i][modelid]);
			switch (object)
			{
				case 657:
				{
					if (weaponid == 4)
					{
						TextDrawShowForPlayer(playerid, Holz[playerid]);
						SetTimerEx("KaputtMaterial", 1500, false, "i", playerid);
						PlayerInfo[playerid][pHolz] += 5;
						return 1;
					}
				}
				case 747:
				{
					if (weaponid == 4)
					{
						TextDrawShowForPlayer(playerid, Stein[playerid]);
						SetTimerEx("KaputtMaterial", 1500, false, "i", playerid);
						PlayerInfo[playerid][pStein] += 5;
						return 1;
					}
				}
			}
it didn't work
Dreandor is offline   Reply With Quote
Old 14/06/2018, 11:53 AM   #6
Dreandor
Little Clucker
 
Join Date: Dec 2017
Posts: 15
Reputation: 0
Default Re: key pressed

I fixed it.
This line was fault.

Code:
object = GetObjectModel(iMaterial[i][modelid]);
The fix is:
Code:
object = iMaterial[i][modelid];
Dreandor is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Key Pressed cyberlord Scripting Help 7 21/12/2014 02:52 PM
when if key pressed gotwarzone Scripting Help 6 10/10/2013 12:14 PM
On Pressed key help NinjahZ Scripting Help 2 18/08/2013 10:10 AM
Key pressed pascallj Help Archive 9 18/01/2010 07:30 PM


All times are GMT. The time now is 11:28 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.