SA-MP Forums Archive
how to make repair with 2? - 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: how to make repair with 2? (/showthread.php?tid=296048)



how to make repair with 2? - niels44 - 09.11.2011

hey everyone,
i have a /repair cmd in my server but i want to make it that when u press 2 the car gets fixed... how to make this i know it is something with onplayerkeystatechange or something.. but wut codes do i need to put there and how XD can someone help me?
niels


Re: how to make repair with 2? - Kostas' - 09.11.2011

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
        if(newkeys == KEY_SUBMISSION) {
            if(IsPlayerInAnyVehicle(playerid)) { {
                    RepairVehicle(GetPlayerVehicleID(playerid));
                }
            }
        }
    }
    return 1;
}



Re: how to make repair with 2? - niels44 - 09.11.2011

thnx bro


Re: how to make repair with 2? - Kostas' - 09.11.2011

Quote:
Originally Posted by niels44
Посмотреть сообщение
thnx bro
No Problem


Re : how to make repair with 2? - decondelite - 09.11.2011

Kostas: that's not optimised at all AND it will NOT work correctly.
1) If you test that the player is a driver, then why checking if he's in a vehicle?
2) Use one if inside another if instead of using "&&"
3) newkays==KEY_SUBMISSION will work very bad

Here's something that works faster, that is easier to read and that works better:
Код:
#define KeyPressed(%0) (newkeys & %0) && !(oldkeys & %0)

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if (KeyPressed(KEY_SUBMISSION)) RepairVehicle(GetPlayerVehicleID(playerid));
	}
    return 1;
}



Re: Re : how to make repair with 2? - FireCat - 09.11.2011

Quote:
Originally Posted by decondelite
Посмотреть сообщение
Kostas: that's not optimised at all AND it will NOT work correctly.
1) If you test that the player is a driver, then why checking if he's in a vehicle?
2) Use one if inside another if instead of using "&&"
3) newkays==KEY_SUBMISSION will work very bad

Here's something that works faster, that is easier to read and that works better:
Код:
#define KeyPressed(%0) (newkeys & %0) && !(oldkeys & %0)

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if (KeyPressed(KEY_SUBMISSION)) RepairVehicle(GetPlayerVehicleID(playerid));
	}
    return 1;
}
I'd just do
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
        if (newkeys & KEY_SUBMISSION) RepairVehicle(GetPlayerVehicleID(playerid));
    }
    return 1;
}



Re: Re : how to make repair with 2? - Kostas' - 09.11.2011

Quote:
Originally Posted by FireCat
Посмотреть сообщение
I'd just do
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
        if (newkeys & KEY_SUBMISSION) RepairVehicle(GetPlayerVehicleID(playerid));
    }
    return 1;
}
I just tried it and it's bugged with some of the code
pawn Код:
C:\Documents and Settings\orion\Фб ЭггсбцЬ мпх\AK Server Gamemode\filterscripts\Sp.pwn(280) : error 017: undefined symbol "IsNosVehicle"
C:\Documents and Settings\orion\Фб ЭггсбцЬ мпх\AK Server Gamemode\filterscripts\Sp.pwn(317) : warning 225: unreachable code
C:\Documents and Settings\orion\Фб ЭггсбцЬ мпх\AK Server Gamemode\filterscripts\Sp.pwn(317) : error 017: undefined symbol "IsNosVehicle"
C:\Documents and Settings\orion\Фб ЭггсбцЬ мпх\AK Server Gamemode\filterscripts\Sp.pwn(330) : error 017: undefined symbol "vehicleid"
C:\Documents and Settings\orion\Фб ЭггсбцЬ мпх\AK Server Gamemode\filterscripts\Sp.pwn(338) : error 030: compound statement not closed at the end of file (started at line 265)
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
As I have the code I posted, it works fine and
pawn Код:
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase
As for decondelite's way it compiles fine, but I didn't test it ingame