What's new

Solved Need help with script

  • Thread starter Charming Fox
  • Start date
  • Views 1,619
C

Charming Fox

Enthusiast
Messages
48
Reaction score
15
I have been missing around with natives and such and I need help with this I cant get it to to turn off.

Code:
#include "natives.h"
#include <natives.h>
#include <common.h>
#include <strings.h>
#include <types.h>
#include <consts.h>
 
#define KEY_K 37
 
void PrintText(char *text)
{
    PRINT_STRING_WITH_LITERAL_STRING_NOW("string", text, 5000, true);
}
 
void CarLock(void)
{
    if ( IS_GAME_KEYBOARD_KEY_JUST_PRESSED(KEY_K) )
    {
                if ( !IS_CAR_DEAD(lock) )
                {
                    SET_CAR_ENGINE_ON(lock, false,);
                    LOCK_CAR_DOORS(lock, true 4);
                    PrintText("Vehicle is now stalled and locked");
                }
        }
        else
        {
            SET_CAR_ENGINE_ON(lock, false,);
            LOCK_CAR_DOORS(lock, false 4);
            PrintText("Vehicle is now unlocked but still stalled");
        }
    }
}
 
void main(void)
{
    THIS_SCRIPT_IS_SAFE_FOR_NETWORK_GAME();
 
    while ( !DOES_CHAR_EXIST(GetPlayerPed()) ) WAIT(0);
 
    while (true)
    {
        CarLock();
        WAIT(0);
    }
}
 
D

DrSpeedy

All these flavors, and you choose to be salty.
Messages
1,065
Reaction score
605
I have been missing around with natives and such and I need help with this I cant get it to to turn off.

Code:
            SET_CAR_ENGINE_ON(lock, false,);
            LOCK_CAR_DOORS(lock, false 4);
            PrintText("Vehicle is now unlocked but still stalled");

So your problem would be that is always executing?
 
D

DrSpeedy

All these flavors, and you choose to be salty.
Messages
1,065
Reaction score
605
I have been missing around with natives and such and I need help with this I cant get it to to turn off.

void CarLock(void)
{
if ( IS_GAME_KEYBOARD_KEY_JUST_PRESSED(KEY_K) )
{
if ( !IS_CAR_DEAD(lock) )
{
SET_CAR_ENGINE_ON(lock, false,);
LOCK_CAR_DOORS(lock, true 4);
PrintText("Vehicle is now stalled and locked");
}
}
else
{
SET_CAR_ENGINE_ON(lock, false,);
LOCK_CAR_DOORS(lock, false 4);
PrintText("Vehicle is now unlocked but still stalled");
}
}
}

See, you have it set up so that when you're not pressing KEY_K it will go off of the pink code.

Also that code in blue will cause you issues.
 
C

Charming Fox

Enthusiast
Messages
48
Reaction score
15
oh so what I would have to do is this
Code:
#define KEY_K 37
#define KEY_U 22
 
void PrintText(char *text)
{
    PRINT_STRING_WITH_LITERAL_STRING_NOW("string", text, 5000, true);
}
 
void CarLock(void)
{
    if ( IS_GAME_KEYBOARD_KEY_JUST_PRESSED(KEY_K) )
    {
                if ( !IS_CAR_DEAD(lock) )
                {
                    SET_CAR_ENGINE_ON(lock, false,);
                    LOCK_CAR_DOORS(lock, true 4);
                    PrintText("Vehicle is now stalled and locked");
                }
{
    if ( IS_GAME_KEYBOARD_KEY_JUST_PRESSED(KEY_U) )
    {
            SET_CAR_ENGINE_ON(lock, false,);
            LOCK_CAR_DOORS(lock, false 4);
            PrintText("Vehicle is now unlocked but still stalled");
        }
    }
}
 
D

DrSpeedy

All these flavors, and you choose to be salty.
Messages
1,065
Reaction score
605
oh so what I would have to do is this
Code:
#define KEY_K 37
#define KEY_U 22
 
void PrintText(char *text)
{
    PRINT_STRING_WITH_LITERAL_STRING_NOW("string", text, 5000, true);
}
 
void CarLock(void)
{
    if ( IS_GAME_KEYBOARD_KEY_JUST_PRESSED(KEY_K) )
    {
                if ( !IS_CAR_DEAD(lock) )
                {
                    SET_CAR_ENGINE_ON(lock, false,);
                    LOCK_CAR_DOORS(lock, true 4);
                    PrintText("Vehicle is now stalled and locked");
                }
{
    if ( IS_GAME_KEYBOARD_KEY_JUST_PRESSED(KEY_U) )
    {
            SET_CAR_ENGINE_ON(lock, false,);
            LOCK_CAR_DOORS(lock, false 4);
            PrintText("Vehicle is now unlocked but still stalled");
        }
    }
}
You could, yeah.
 
D

DrSpeedy

All these flavors, and you choose to be salty.
Messages
1,065
Reaction score
605
Is there any way for me to only have to use K and not any other key or not?
with a boolean toggle.

e.g.
Code:
bool toggle;//declare this as a public var (outside of all functions)
 
if(toggle){
//code
toggle = false;
}
else{
//code
toggle = true;
}
 
Z

NayJames123

Read Art
Messages
4,273
Reaction score
3,475
you need to get the handle of your car aswell using GET_CAR_CHAR_IS_USING(GetPlayerPed(), &vehiclehandle);
 
L

Liquid44

Banned
Messages
1,159
Reaction score
691
Code:
 if ( !IS_CAR_DEAD(lock) )
                {
                    SET_CAR_ENGINE_ON(lock, false,);
                    LOCK_CAR_DOORS(lock, true 4);
                    PrintText("Vehicle is now stalled and locked");
                }


"lock" is not defined anywhere, you need to do what james said and replace lock with the vehiclehandle
 
Top Bottom