Rather confusing error...
#1

Alright, I am scripting a system to where if I press the KEY_HANDBRAKE, the engine will turn on, along with a GameTextForPlayer will pop up, but everytime I pressed the spacebar, that message came up, so, I editted it to this, and I honestly do not know what is wrong...

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new playerState = GetPlayerState(playerid);
    new veh = GetPlayerVehicleID(playerid);
    if(newkeys & KEY_HANDBRAKE && playerState == PLAYER_STATE_DRIVER)
    {
        GetVehicleParamsEx(veh, engine,  lights, alarm, doors, bonnet, boot, objective);
    }
    if(veh, 1, 0, 0, 0, 0, 0)
    {
        GameTextForPlayer(playerid, "~G~Engine On!", 50000, 3);

        new
            engine,
            lights,
            alarm,
            doors,
            bonnet,
            boot,
            objective;


        GetVehicleParamsEx(veh, engine,  lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(veh, 1, lights, alarm, doors, bonnet, boot, objective);
    }
    return 1;
}
I am getting the following error:
pawn Код:
C:\Documents and Settings\nmader\Desktop\Lost Roleplay\filterscripts\Engine.pwn(408) : error 017: undefined symbol "engine"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Any help will be greatly appreciated, and I am one who +Rep's.

Thanks,
Nmader
Reply
#2

Nevermind, I just found my careless flaw, it was the placing of my defining of the Engine.

--------------------------------------------------------------------------
EDIT:
--------------------------------------------------------------------------
I editted it to this code:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new playerState = GetPlayerState(playerid);
    new veh = GetPlayerVehicleID(playerid);
    new
            engine,
            lights,
            alarm,
            doors,
            bonnet,
            boot,
            objective;
    if(newkeys & KEY_HANDBRAKE && playerState == PLAYER_STATE_DRIVER)
    {
        GetVehicleParamsEx(veh, engine,  lights, alarm, doors, bonnet, boot, objective);
        if(veh, 0, 0, 0, 0, 0, 0)
        {
            GameTextForPlayer(playerid, "~G~Engine On!", 50000, 3);

            new
                engine,
                lights,
                alarm,
                doors,
                bonnet,
                boot,
                objective;

            GetVehicleParamsEx(veh, engine,  lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(veh, 1, lights, alarm, doors, bonnet, boot, objective);
        }
    }
    return 1;
}
It compiled with no errors, I go to test it, and it does not work, I want the engine to go on if the engine is off, along with showing the GameTextForPlayer IF it is JUST turning the engine on, not everytime I press my KEY_HANDBRAKE.
Reply
#3

Anyone willing to help me figure this out? I would rather not progress on my script without knowing my mistake.
Reply
#4

pawn Код:
new engineStatus[MAX_VEHICLES];

public OnVehicleSpawn(vehicleid)
{
    engineStatus[vehicleid] = 0;
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_HANDBRAKE && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new veh = GetPlayerVehicleID(playerid);
        if(!engineStatus[veh])
        {
            GameTextForPlayer(playerid, "~G~Engine On!", 50000, 3);
            engineStatus[veh] = 1;
            SetVehicleParamsEx(veh, 1, -1, -1, -1, -1, -1, -1);
        }
    }
    return 1;
}
Tips
- There's no need to create a variable unless you're going to use it multiple times.
- In SetVehicleParamsEx, -1 doesn't change it.
- Defining variables at the top of OnPlayerKeyStateChange is inefficient because that function is called a large amount of times.
Reply
#5

I edited the script to yours, but is still shows the GameTextForPlayer after it is turned on, everytime I press the KEY_HANDBRAKE.
Reply
#6

You need to check and set 2 cases one is when engine is on and second is when engine is off... so need to check the engine status.. look at ****** it will show you how to make it.. Or in some gf script where is /engine command...
Reply
#7

In SuperViper's it had things to tell if it is on or off included, and I took that script, replacing his old one, so obviously not the issue.
Reply
#8

Not replacing just look how it works.. You don't need to replace anything just look in scripts.. I always do like that.. Because no one will do things for you... You need to learn, the best places are in another scripts... It's my opinion.. use this https://sampforum.blast.hk/showthread.php?tid=306311


Код:
YCMD:engine(playerid, params[], help)
{
    if(help) return SendClientMessage(playerid, COLOR_GREY, "This command is used to turn a vehicles engine on/off.");

    new vehicleid = GetPlayerVehicleID(playerid);
    new string[126];
    new vehiclename[126];
    GetVehicleName(vehicleid, vehiclename, sizeof(vehiclename));
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
   
    if(IsPlayerDriver(playerid))
    {
        if(engine != 1)
        {
            engine = 1;
            SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
            format(string, sizeof(string), "* %s turns the engine of their %s on.", playersname(playerid), vehiclename);
            ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            return 1;
        }
        else
        {
            engine = 0;
            SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
            format(string, sizeof(string), "* %s turns the vehicles engine off.", playersname(playerid));
            ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            return 1;
        }
    }
    return engine;
}
took it form Jack_Leslie In the same tutorial..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)