Scripts / how to add a display image or sprite to a zone or trigger (eg. hurt zone or heal zone or plain trigger zone)

Author
Message
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 28th Dec 2016 23:03 Edited at: 2nd Jan 2017 23:08
yessss............. edited to say "Solved" finally figured it out.

This is the code if anyone can use it



Updated: This version also loops a sound while you are in the zone. (sound slot 0)
its like deja-vu, but all over again

Attachments

Login to view attachments
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 00:07
Nice! I'm going to give it a try! Thank you!
PM
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 2nd Jan 2017 16:54 Edited at: 2nd Jan 2017 17:01
@unspokenbond I've added a second version in the first post, adding a looped sound in the zone. (eg in a radiation zone it could play a Geiger counter wav for example.)
If you don't assign an image it will just loop a sound, if one is assigned in slot 0. So its like a combined image in zone/sound in zone script
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 17:12
That's cool! Thank you!!
Still learning LUA but 'attempting' to build my first game
PM
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 19:01
Looks like the new attachment doesn't have the LUA script. Could you please post that?
Still learning LUA but 'attempting' to build my first game
PM
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 2nd Jan 2017 20:12 Edited at: 2nd Jan 2017 20:50
Quote: "Looks like the new attachment doesn't have the LUA script. Could you please post that?"

that was just an image, i've deleted that and updated it to download the updated code (script) for you, the one which shows image and plays the sound.
You can use the same script to do either one or both.

I had left it open in the "code" tabs so you can copy/paste it without having to be logged in and didn't upload the script itself, but it's there now. (you have to be logged in to download files, some people like me find that inconvenient when they are at work or shared computers)
[http://www.particle50.com]Particle 50[/url]

Attachments

Login to view attachments
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 20:53
Ah makes sense lol thank you!
Still learning LUA but 'attempting' to build my first game
PM
Freakon
GameGuru TGC Backer
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: UK
Posted: 2nd Jan 2017 20:55
One too many end at the end!
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 2nd Jan 2017 21:28
Quote: "One too many end at the end! "

it's a spare

I'm still getting the hang of the end commands
its like deja-vu, but all over again
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 21:50
Shoot I'm clearly doing some wrong :/

I've created my trigger zone and attached the pic1.lua script to it. I've placed an image called pic1 in the scriptbank folder but it never loads. Did I miss a step? lol
Still learning LUA but 'attempting' to build my first game
PM
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 2nd Jan 2017 22:07 Edited at: 2nd Jan 2017 22:16
you just have to put images for this script into a folder called pic1. the script looks for the folder called pic1, then loads the image(s) in that folder that the script calls for.

they have to be png format and the images must be called 000, 001, 002 etc. I have attached a sample folder with some images for you, they are named 000,001.png etc so you can see how it works.

Unzip it, then put the whole pic1 folder with the png images into this place: scriptbank/images. and it will work.

this is the full path if you need it for putting the folder in C:\Program Files (x86)\Steam\steamapps\common\Game Guru\Files\scriptbank<your folder goes here>\ (unzip the folderfirst or it won't work. whole folder goes in with the images inside it. you can change the images to suit yourself but they must always be .PNG format, the ones I included have transparent backgrounds but they don't have to have transparency)
its like deja-vu, but all over again

Attachments

Login to view attachments
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 22:15
Ahh thank you!! Works perfect and is very cool
Still learning LUA but 'attempting' to build my first game
PM
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 2nd Jan 2017 22:25
^^^ sweet
I was using this to make some huds that activate automatically in zones, and player taking a cellphone message, stuff like that, and "hints" that pop up here and there in the first tutorial part of a level rather than text prompts.
it took me ages trying, months on and off and giving up frustrated by it, and looking at other scripts to see how they worked like everybody advised, but eventually something clicked and I'm beginning to understand the beginnings of scripting in Lua now. But as you can see, the <end> commands are the embuggerence some of the time.
its like deja-vu, but all over again
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 2nd Jan 2017 22:43
I agree this has TONS of use for so many options

final question my friend - how do you get the image to disappear after you walk away and out of the 'zone' mine just stays on the screen for good after its loaded.
Still learning LUA but 'attempting' to build my first game
PM
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 2nd Jan 2017 22:44
Quote: "you just have to put images for this script into a folder called pic1. the script looks for the folder called pic1, then loads the image(s) in that folder that the script calls for.

they have to be png format and the images must be called 000, 001, 002 etc. I have attached a sample folder with some images for you, they are named 000,001.png etc so you can see how it works.

Unzip it, then put the whole pic1 folder with the png images into this place: scriptbank/images. and it will work.

this is the full path if you need it for putting the folder in C:\Program Files (x86)\Steam\steamapps\common\Game Guru\Files\scriptbank<your folder goes here>\ (unzip the folderfirst or it won't work. whole folder goes in with the images inside it. you can change the images to suit yourself but they must always be .PNG format, the ones I included have transparent backgrounds but they don't have to have transparency)"


This is why hardly anybody uses images in scripts now, we generally use sprites instead because you have much more control over them, you can name them whatever you like, position them wherever you like, scale them however you like, and layer them however you like.

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
Freakon
GameGuru TGC Backer
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: UK
Posted: 2nd Jan 2017 22:53
Quote: "we generally use sprites instead"


And here's a nod in the right direct for sprites: Credit to smallg.

https://forum.game-guru.com/thread/207801?page=12#msg2541219
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 2nd Jan 2017 23:07 Edited at: 2nd Jan 2017 23:11
images staying:
it needs this on the end of the script
else
HideImage(1)
StopSound(e,0)

I think that was maybe what the extra <end> might have been for.... maybe.

I updated it and here it is to view or copy/paste

-- displays an image in zone
-- loops a sound in zone
-- persistent script

function pic1_init(e)
LoadImages("pic1",0)

function pic1_main(e)


if g_Entity[e]['plrinzone']==1 then

ActivateIfUsed(e)
LoadImages("pic1",0)
SetImagePosition(50,10)
ShowImage(1)
LoopSound(e,0)
else
HideImage(1)
StopSound(e,0)
end
end
end


re sprites:
yes once i get into the swing of it I'll do these type of things using sprites. they are far more versatile. I started out trying this script with sprites but kept losing the plot lol.

and while we're here - Happy new year to all
its like deja-vu, but all over again

Attachments

Login to view attachments
Unspokenbond
7
Years of Service
User Offline
Joined: 28th Nov 2016
Playing: GameGuru
Posted: 3rd Jan 2017 00:52
Awesome thank you for your script, time, and help!!

Happy New Years to you as well my friend!!
Still learning LUA but 'attempting' to build my first game
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Jan 2017 01:09
a couple small things,
1. the init(e) function should end before the main(e) function is called (your main is inside the init)
2. is a bad idea to repeatedly call LoadImages like that, you should add a variable toggle or do it outside the main(e), you will run out of memory eventually if you stay inside the zone otherwise.
3. you load an image in the slot you set when calling LoadImages (in your case 0) and so any reference to it should use that slot (in your example you would need 2 images - one for slot 0 and one for slot 1)
4. as said above, sprites are much better and an extra bonus not mentioned is that they also keep size compared to the direct image commands (your code would, for example, load the same image tiny on a large resolution but huge on a small resolution, whereas sprites stay the same ratio as they are % based).

for 'end' statements i recommend getting notepad++ and getting used to indenting your code (tab), it will help you keep track of everything much easier - general rule is to indent everything every time you have an 'if' or similar statement.. i.e.

now when you view it in notepad++ it's easy to see which end matches which and makes error checking much much faster.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AceRimmer
Reviewed GameGuru on Steam
9
Years of Service
User Offline
Joined: 28th Feb 2015
Playing: classic British heavy metal mostly
Posted: 3rd Jan 2017 18:08 Edited at: 3rd Jan 2017 18:42
Big thanks very much smallg appreciate the tips. Also big thanks Belidos and Freakon for the help and encouragement
Duly noted all about the important memory issue, and sprites, and the general rules of thumb about indenting etc. it all makes so much more sense when someone points it out.

the only scripting I have done before is fairly basic, as little as possible and work-related Java/ zend and php, just for basic website stuff, but i'm beginning to spot where there are some transferable skills. I might even begin to enjoy this scripting lark

i use notepad ++ for work related stuff, on a chromebook, I can't think why I never used it at home. Some mental disconnect between work and leisure computing probably!
Lua is the first non-work scripting I have tried since Amos back in the days of the Amiga. Somehow Lua wasn't clicking at all with me until I looked in the smallg Generator scripts, and then something began to sink in. some new glasses will help too lol. It's an old age thing

Here is a variation on the theme, better written, with a timer by Freakon (thanks mate!) It displays the image for 3 seconds.

I've commented the bits you can change, eg. timer. (for other learners like me it's well worth a look to see how these things work).

I think is a bit more like the "read note" script but without all the pressing of E, and without freezing the player, which is nice.

I have renamed it to avoid conflict/confusion with the other script, but it still uses the images folder pic1

its like deja-vu, but all over again

Attachments

Login to view attachments
Freakon
GameGuru TGC Backer
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: UK
Posted: 3rd Jan 2017 18:48
Quote: "--credit Freakon"
-- Really no need for credit bud! Pretty sure it's frankenstein's monster code!

Quote: " I've annotated the bits you can change for other learners like me"
-- Me too! by no way the level I want to be.

It really is all about making a copy of an existing script and just seeing what happens! It can be frustrating but you have seen what you can achieve now

And, as a bonus, you managed to get 10 end statements in
My God, it's full of stars
Mipastu
GameGuru TGC Backer
9
Years of Service
User Offline
Joined: 16th Feb 2015
Location: Finland
Posted: 20th Jan 2017 12:24
I didnt really understand.. how can you make the same script use different images? by changing name or something. i didnt really understand that from the script
Intel Core i5 6600K @ 3.50GHz ¨ 16,0Gt dual channel RAM @ 1334MHz ¨¨ 2048MtNVIDIA GeForce GTX 1060 6GB ¨¨ 465GB Samsung SSD 750 EVO 500GB (SSD) ¨¨ Windows 10 Home 64-bit
Freakon
GameGuru TGC Backer
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: UK
Posted: 22nd Jan 2017 04:50
Quote: "I didnt really understand.. how can you make the same script use different images? by changing name or something. i didnt really understand that from the script"


Smallg makes for a better explaination of sprites with multiples in the link below:

https://forum.game-guru.com/thread/207801?page=12#msg2541219

My God, it's full of stars
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 27th Feb 2017 23:14 Edited at: 27th Feb 2017 23:18
smallg wrote: "for 'end' statements i recommend getting notepad++ and getting used to indenting your code (tab), it will help you keep track of everything much easier - general rule is to indent everything every time you have an 'if' or similar statement.. i.e."


I agree. Although, I use LuaEditor. It also is free. It has an indent of four spaces which I like and all of us old programmers used that amount of spacing back in the seventies. At least that was how I was taught. Here is my code snippet of a script created by Mr. VIP, smallg:



I would like to take the opportunity to thank smallg for what he does for the community. It has helped me get a really fast start with GG. Lua is a far cry from Assembly and COBOL that I started out learning and were the languages I used for several years. I finally learned BASIC and then Visual BASIC and then 'C' for use with the PCs. Lua seems to be similar to 'C' so my learning curve won't be very steep.

BTW, here are two places that whoever wants LuaEditor can download it. They both are Virus free:

CNET, and

SourceForge
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Feb 2017 00:03
I use notepad++, it seems to handle all the languages not just Lua.


Been there, done that, got all the T-Shirts!
PM
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 28th Feb 2017 22:46
AmenMoses wrote: "I use notepad++, it seems to handle all the languages not just Lua."


Actually, I no longer program as I'm retired. However, I am, of course, going to program Lua. Although, I didn't bring that up to debate what is a better editor. I just brought it up as another alternative as it is also free. What is to be stressed is that no matter what "Editor" is used, one should indent to keep the programming easy to read and where the <ends> should be.

BTW, AmenMoses, I loved what you have been doing with the train. Just like programming you need to keep it on track or "on the" track.
Another Old Man.
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 28th Feb 2017 23:18 Edited at: 28th Feb 2017 23:18
Quote: "I use notepad++, it seems to handle all the languages not just Lua."

I use sublimetext for the same reason And zeroBrane for small scripts. Use the IDE which is most fitting for you, there is no ideal solution

@F l a t l a n d e r
Nice to see that some old wise members still watching us little teens
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM

Login to post a reply

Server time is: 2024-05-17 15:33:31
Your offset time is: 2024-05-17 15:33:31