Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Ksna on Aug 08, 2015, 02:08 PM

Title: bind keys
Post by: Ksna on Aug 08, 2015, 02:08 PM
I was trying to make a remote car like topfun missions but when i bindkey it works only once even if i hold and it moves when i press continuosly.
Can anyone give a idea how to make it move when i hold a key..
Title: Re: bind keys
Post by: Diego^ on Aug 08, 2015, 02:21 PM
You can use this as an example:
http://forum.vc-mp.org/?topic=668.msg4292#msg4292
Title: Re: bind keys
Post by: Ksna on Aug 08, 2015, 02:41 PM
I have pasted your code as it is in a blank page . when i press h in game nothing happens.
Title: Re: bind keys
Post by: DizzasTeR on Aug 08, 2015, 02:44 PM
This should give you an idea,
pKey <- BindKey( .. ) // Your key bind defined.

function onKeyDown( player, key )
{
    if( key == pKey ) {
        // Move the car for the player who pressed the key.
    }
}

function onKeyUp( player, key )
{
    if( key == pKey ) {
        // Stop moving the car for player who has stopped pressing the key.
    }
}
Title: Re: bind keys
Post by: Ksna on Aug 08, 2015, 02:58 PM
using this as is in a blank page
function onScriptLoad()
{

w <- BindKey(true,0x57,0,0); // Your key bind defined.

}

function onKeyDown( player, key )
{
    if( key == w ) {
        // Move the car for the player who pressed the key.
    }
}

function onKeyUp( player, key )
{
    if( key == w ) {
        // Stop moving the car for player who has stopped pressing the key.
    }
}

gives error at onkeydown , if( key == w)
Title: Re: bind keys
Post by: Thijn on Aug 08, 2015, 03:07 PM
Quote from: Ksna on Aug 08, 2015, 02:58 PMusing this as is in a blank page
function onScriptLoad()
{

w <- BindKey(true,0x57,0,0); // Your key bind defined.

}

function onKeyDown( player, key )
{
    if( key == w ) {
        // Move the car for the player who pressed the key.
    }
}

function onKeyUp( player, key )
{
    if( key == w ) {
        // Stop moving the car for player who has stopped pressing the key.
    }
}

gives error at onkeydown , if( key == w)
No it doesn't. Make sure you actually copy paste correctly. Also, if you do get an error why not post it...
Title: Re: bind keys
Post by: Ksna on Aug 08, 2015, 03:21 PM
I made a video because this needs it
https://youtu.be/lC_VnzBr93g

Once it worked and i got crashes when i pressed 'w'.
Title: Re: bind keys
Post by: KAKAN on Aug 08, 2015, 05:00 PM
But it works on my script
Title: Re: bind keys
Post by: Thijn on Aug 08, 2015, 06:28 PM
Atleast put something between the brackets instead of just a comment. This code works fine:
function onScriptLoad()
{
w <- BindKey(true,0x57,0,0); // Your key bind defined.
}


function onKeyDown( player, key )
{
    if( key == w ) {
        // Move the car for the player who pressed the key.
        print("moo");
    }
}

function onKeyUp( player, key )
{
    if( key == w ) {
        // Stop moving the car for player who has stopped pressing the key.
        print("boo");
    }
}
Title: Re: bind keys
Post by: Ksna on Aug 09, 2015, 02:56 AM
Sorry for late reply , after a restart everything is working fine even the one which gave me an error. Why this happen?

when i paste this code as is http://forum.vc-mp.org/?topic=668.msg4292#msg4292 . this works randomly i mean sometime it works , sometimes it wont . Even if it is working when i press h it shows nothing.
Title: Re: bind keys
Post by: Thijn on Aug 09, 2015, 08:03 AM
The code works fine, so make sure you have all the latest plugins, server and client. Otherwise I wouldn't know what's wrong on your side, it works fine here.