Scripts / Strange things happening

Author
Message
TazMan
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 20th Jan 2011
Location: Worldwide Web
Posted: 17th Mar 2017 12:05
Please can someone help me with some script. I have this script below.



I have been a programmer for some years and unless I am going potty this code says that if the player is further away than 200 then the animation will play. But it is the opposite, if the player is closer than 200 the animation plays.

Now I want the animation to play when the player is closer than 200 and this was the only way to do it, but it is driving me crazy. I know this is simple bit of code but it just doesn't seem to be right.
HP Pavilion Laptop - AMD A8-4555M APU with Radeon(tm) HD Graphics - 1.6GHz, 8GB Memory, Windows 10 Home, 64-bit Operating System.

I've got something to say - It's better to burn out than fade away.
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 17th Mar 2017 12:50 Edited at: 17th Mar 2017 12:51
PlayerDist > 200 should not be in brackets if i remember right.

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.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 17th Mar 2017 14:11 Edited at: 17th Mar 2017 14:49
@ Taz
Ignore if you want to play anim once or you want to loop anim.

Attached script.



If you want to loop anim, then it should looks like this:




uploading video to yt. I'll post when done.



hth

Quote: "PlayerDist > 200 should not be in brackets if i remember right."

Not exactly. You enclose some statement when there are many condiction, and you want evaluate one firts than the others. IE:



Here you want evaluate firts, "hasKey==1", if true, then evaluate the others one, if does not, not worth bothering..

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

Attachments

Login to view attachments
PM
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 17th Mar 2017 14:18
Quote: "Not exactly. You enclose some statement when there are many condiction, and you want evaluate one firts than the others. IE:"


True, but we aren;'t talking about a script with multiple checks, there was only check, so he didn't need it

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.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 17th Mar 2017 14:35
Certainly, does not.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Mar 2017 15:35
That's a very broken way to fix that problem :p
Not a good idea to call those commands repeatedly like that, it would use up a lot of resources if used in too many scripts.

What you need to do is make sure the command is only called if the animation is not already playing (assuming you wanted it to repeat for the duration the player is close enough) or simply toggle the condition to no longer be true after it has been triggered (even in such a way that it can no longer trigger again maybe?).

The play animation call will repeatedly try to run the animation every time it is called, therefore it is stuck in the first frame and appears not to be animating, once you move away the last call is still active and thus the animation plays... Making it look like the condition is reversed but its simply the way the call works.
An easy example of this is the play sound call. You will notice a weird buzzing if the command is called repeatedly and when you move away the sound is played normally, this is because of the same trait.

So basically you want to enclose the commands inside an extra check - by default GG scripts use
if g_Entity[e]['animating'] == 0 then
Because this automatically gets reset to 0 by the engine once the entity stops animating.
Just remember to also set it to a value once you have called the play animation command (it doesn't change by default I assume because it allows you to set values and easily grab which animation is playing based on those).

On phone so forgive any error but the script will look something like this.
if GetPlayerDistance(e) < 200 then
if g_Entity[e]['animating'] == 0 then
SetAnimation(0)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
end
end
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
TazMan
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 20th Jan 2011
Location: Worldwide Web
Posted: 17th Mar 2017 16:55
Wow that sparked off a bit of a discussion.

Thanks to everyone for all your input. So it looks like all I needed to do was put another condition in checking to see if the entity was animating.
HP Pavilion Laptop - AMD A8-4555M APU with Radeon(tm) HD Graphics - 1.6GHz, 8GB Memory, Windows 10 Home, 64-bit Operating System.

I've got something to say - It's better to burn out than fade away.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 17th Mar 2017 17:32 Edited at: 17th Mar 2017 17:33
Quote: "So it looks like all I needed to do was put another condition in checking to see if the entity was animating."


You already stated it, in your snippe script:
Quote: "g_Entity[e]['animated'] = 1"

Well, not right done but you has the idea. I've notice the typo, but forguet to add as condiction. Sorry, Smallg is right about.
You should add: g_Entity[e]['animating'] = 1 instead.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
TazMan
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 20th Jan 2011
Location: Worldwide Web
Posted: 18th Mar 2017 11:52
You would think after all the years of programming that I would get LUA more easily, but it seems things that might have worked in say C#, VB or many other languages need a bit extra to work in LUA.

Anyway thanks everyone, it is working perfectly now.

Maybe if I concentrated on the language for a while instead of modelling I might get better at it sooner, but I don't want to. I am enjoying the modelling too much.
HP Pavilion Laptop - AMD A8-4555M APU with Radeon(tm) HD Graphics - 1.6GHz, 8GB Memory, Windows 10 Home, 64-bit Operating System.

I've got something to say - It's better to burn out than fade away.

Login to post a reply

Server time is: 2024-12-23 04:57:10
Your offset time is: 2024-12-23 04:57:10