Liberty Unleashed

Scripting => Script Snippets => Topic started by: theasl99 on June 25, 2020, 05:51:49 am

Title: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 25, 2020, 05:51:49 am
Surprise! What is theasl99 doing here? This is my first post

I do not know if someone has already made a post of this, but I who have been reading the wiki and this page to make my roleplay server have not seen any script that allows the possibility of pointing while firing a sniper rifle

this is a small fix for users who shoot with sniper, since when you shoot with sniper, the player does not generate any animation and in my opinion it is quite annoying

I am just starting out in scripting and I saw this piece of useful script, if you have ideas to improve it with pleasure I accept them, I am an old user of the community as of 2011, some should already know me, greetings to all.  8)

:::THE SCRIPT:::



local sniper = 0;
local snipershoot = 0;

function onPlayerWeaponChange( player, oldwep, newwep, ammo )
{
if ( newwep == WEP_SNIPER ) {
sniper = 1;
//MessagePlayer ( "You have a SniperRifle! (sniper=1)", player );
} else {
sniper = 0;
}
}

function onPlayerKeyStateChange ( pPlayer, key, down ) {

if ( ( key == KEY_ONFOOT_AIM ) && ( down ) ) {



if (sniper == 1) {

snipershoot = 1;
//MessagePlayer ( "You has shooted the SniperRifle (snipershoot=1)", pPlayer );

if (snipershoot == 1){
//MessagePlayer ( "Generate the SniperRifle Animation", pPlayer );
pPlayer.SetAnim (50);

}
}
}
}


COPY AND PASTE, THIS IS A CLIENT SCRIPT!
Title: Re: Aiming with Sniper Rifle (Script)
Post by: Eclipse2G on June 25, 2020, 10:22:54 am
first of all

SetAnim doesnt exist on client side
second of all

It wont work at  all because the anim will play ONCE the shot has been fired, it makes this script useless
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 25, 2020, 12:01:02 pm
first of all

SetAnim doesnt exist on client side
second of all

It wont work at  all because the anim will play ONCE the shot has been fired, it makes this script useless

This script works, I test this script it before uploading it, although it has some deficiencies, it only generates the animation if I changed my weapon before for a Sniper.

Also when I play sniper with other players the animation appears but not every time.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: Eclipse2G on June 25, 2020, 12:04:27 pm
SetAnim doesn't exist in CLIENT SCRIPTS.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 25, 2020, 12:06:34 pm
SetAnim doesn't exist in CLIENT SCRIPTS.

SetAnim is a "function" of player, it should serve the same way
Title: Re: Aiming with Sniper Rifle (Script)
Post by: Eclipse2G on June 25, 2020, 12:08:43 pm
http://liberty-unleashed.co.uk/LUWiki/Squirrel/Client/Functions (http://liberty-unleashed.co.uk/LUWiki/Squirrel/Client/Functions)

Show me where you see SetAnim there.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 25, 2020, 12:14:01 pm
[url]http://liberty-unleashed.co.uk/LUWiki/Squirrel/Client/Functions[/url] ([url]http://liberty-unleashed.co.uk/LUWiki/Squirrel/Client/Functions[/url])

Show me where you see SetAnim there.


I test the script on a client and it worked without problems, well, with the ones I specified before, I will try to test it without a client to see how it is.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: Eclipse2G on June 25, 2020, 12:26:17 pm
The script is Server Side, not Client Side.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 25, 2020, 12:32:17 pm
The script is Server Side, not Client Side.

Okay, although it is rare that it works without problems on the client side.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 25, 2020, 12:45:57 pm
The script is Server Side, not Client Side.

Okay, I just test it on the server side and it doesn't work, it stays on the client.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: Eclipse2G on June 25, 2020, 01:58:23 pm
client="0" in xml means its Server Side, client="1" means its client side. I dont get it how does this work for you while its on client side. It shouldnt.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: Eclipse2G on June 25, 2020, 02:02:28 pm
Code: [Select]
sniper_shot <- array(128,false);
function ClearShot(plr) { if ( plr ) { sniper_shot[plr.ID] = false; } }
function onPlayerKeyStateChange( player, key, down )
{
    if (  key == KEY_ONFOOT_AIM && down  )
    {
        if (player.Weapon==7  && !sniper_shot[player.ID])
        {
            sniper_shot[player.ID] = true;
            player.SetAnim(50);
            NewTimer(ClearShot,800,1,player); // prevent anim spam
        }
    }
}

Saved it as script.nut, <script file="script.nut" client="0" /> in Script.xml
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 27, 2020, 01:13:09 am
Code: [Select]
sniper_shot <- array(128,false);
function ClearShot(plr) { if ( plr ) { sniper_shot[plr.ID] = false; } }
function onPlayerKeyStateChange( player, key, down )
{
    if (  key == KEY_ONFOOT_AIM && down  )
    {
        if (player.Weapon==7  && !sniper_shot[player.ID])
        {
            sniper_shot[player.ID] = true;
            player.SetAnim(50);
            NewTimer(ClearShot,800,1,player); // prevent anim spam
        }
    }
}

Saved it as script.nut, <script file="script.nut" client="0" /> in Script.xml

PERFECT, I like when they improve what is done, and not only do they criticize, now I try that piece of script, there is a bug in the piece that I put.
when you grab the sniper pickup, and you shoot the animation doesn't work, but when you change weapons if it works.
Title: Re: Aiming with Sniper Rifle (Script)
Post by: theasl99 on June 27, 2020, 01:25:44 am
Code: [Select]
sniper_shot <- array(128,false);
function ClearShot(plr) { if ( plr ) { sniper_shot[plr.ID] = false; } }
function onPlayerKeyStateChange( player, key, down )
{
    if (  key == KEY_ONFOOT_AIM && down  )
    {
        if (player.Weapon==7  && !sniper_shot[player.ID])
        {
            sniper_shot[player.ID] = true;
            player.SetAnim(50);
            NewTimer(ClearShot,800,1,player); // prevent anim spam
        }
    }
}

Saved it as script.nut, <script file="script.nut" client="0" /> in Script.xml

Nice, the script works better than my piece of script on server side, congratulations, Close topic