Scripts / Weapon use detection

Author
Message
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 17th Jul 2018 13:56
Is there a LUA command that detects whether you are holding a weapon or not?

For example in my WIP (paranormal investigation), most of the time you will be holding an EMF meter which is a sprite on the screen, but what i want to do is make it so that if you are holding a weapon it hides that sprite, and if you hit 0 to turn off your weapon it will show the sprite again.

Is this possible? If so how would i go about it?
[img]belidos3d.swgrp.co.uk/wp-content/uploads/2016/03/blogo.png[/img]
Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 17th Jul 2018 17:44
Yep! I'm unfortunately at work so i cant think of the name of the commands here while at work. But there is ways to check if the player is armed or even what exact weapon he's/she's holding.
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 17th Jul 2018 17:50
That sounds good to me. It's if they have a weapon at all i need, i don't need to know which weapon, just if they're holding a weapon, so i can set it to show the sprite image when they put their weapons away with 0.
[img]belidos3d.swgrp.co.uk/wp-content/uploads/2016/03/blogo.png[/img]
Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Jul 2018 18:12 Edited at: 17th Jul 2018 18:24
g_PlayerGunID
Not sure if it returns 0 or nil but I believe 0 means no weapon so
if g_PlayerGunID > 0 then
edit
or
if g_PlayerGunName ~= "" then

Will check if the player has a gun in his hand or not
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Jul 2018 08:37
Great thanks smallg.

Just a quick one, would it be better to use the g_PlayerGunID variable directly, or parse it into my own variable for controlling the sprite? I know some of the globals don't like to be called directly for example the get player health one etc. is this the same? or am i safe just checking it directly?
[img]belidos3d.swgrp.co.uk/wp-content/uploads/2016/03/blogo.png[/img]
Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Jul 2018 10:07
Never noticed any issue calling the health?
Either way you're going to need to check the gunid every frame anyway so putting it into another variable is only really needed if you're checking it more than once in your script... But its still mostly preference as it only takes a tiny amount of time for it to do the check with a global anyway for simple stuff like getting a number - maybe a bit different if we're talking about things like GetPlayerDistance or things with a more complicated check involved before it can return the result.

It is good practice to do so but I'd be very surprised if it was ever going to be the reason your game was slowed down.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Jul 2018 11:17
Sorry i meant the distance check one, no idea why i said health lol
[img]belidos3d.swgrp.co.uk/wp-content/uploads/2016/03/blogo.png[/img]
Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Jul 2018 18:58
The distance check is a function call, the player variables are global variables which get updated ever frame by the engine.

Neither need to be used every frame, every 1/10 of a second or so is sufficient.

If you have a huge script with lots of logic based on player distance it will give better performance if you set a local variable to the distance at the beginning of the script and then use that within the rest of the script.

Example:




Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 19:33:35
Your offset time is: 2024-12-22 19:33:35