how to make repair with 2?
#1

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
Reply
#2

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;
}
Reply
#3

thnx bro
Reply
#4

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

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;
}
Reply
#6

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;
}
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)