Scripts / Entity Hit, Text, Math

Author
Message
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 3rd May 2015 01:44
Hi, I'd like to make text appear above objects and when they are hit, it either lessens health or changes values... Like a questionnaire or something... 3 choices (3 objects) choose your answer. That kind of stuff. It's for a local project here. Mathematical.
A Math question is asked, choose answer, wrong = -health, right = next question...
The question text is no problem, since the script can only consist of basic commands. But the others, well, that'll take a while.

I can script the basic stuff (The text and stuff, except the text with coordinates leading above the entity (If that's Possible).
But I seriously need help with:
Entity Hit command (I can script the -hp and "next question")
Shuffling of questions (Mathematical Questions. I can script the appearance of texts but I don't think one mono sequence can really make an appeal.)
Text above the Entities (If not possible, just 3 different texts appearing on the mid right, center, and mid left)

I've done a few scripting, but it seems I've reached the limit of my knowledge. Help?
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 3rd May 2015 07:16 Edited at: 3rd May 2015 07:22
Hi,
I am only new to GG, I can help with the text and the position of text.
To get you started until someone else offers you help.

I have attached my learning script for text I made with the different commands that are available.

Tip: To get different colour codes for R,G,B I just use Microsoft Paint. Click on edit colours pick the colour you need and read its R,G,B as needed.



I may be old, but at least my memory still ....hmmm

Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2789 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 3rd May 2015 16:20
Quote: "https://forum.game-guru.com/thread/211822#msg2516550"


Thank You so much for the help! I really appreciate it! I'm gonna start with the texts then keep trying the other features.
I really need this project to succeed, please anyone help me with the other scripts ...
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd May 2015 17:04
to determine which entity is hit you need to store it's g_Entity[e]['health'] value inside another variable (only update this as needed) and then check for g_Entity[e]['health'] being less than that value (and update the stored variable again now for future checks)

for text placement use Text command as perelect says, it's % based on screen for position, you can use my PlayerLooking function to determine if an entity is on screen or not (with a wide enough angle depending on distance)

for random questions assign each question in an array and use math.random(low #,high #) to pick one (might want to add a toggle to stop repeat questions)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 4th May 2015 02:21
Quote: "to determine which entity is hit you need to store it's g_Entity[e]['health'] value inside another variable (only update this as needed) and then check for g_Entity[e]['health'] being less than that value (and update the stored variable again now for future checks)

for text placement use Text command as perelect says, it's % based on screen for position, you can use my PlayerLooking function to determine if an entity is on screen or not (with a wide enough angle depending on distance)

for random questions assign each question in an array and use math.random(low #,high #) to pick one (might want to add a toggle to stop repeat questions)"


Hi! Thank You so much! I can do those, but I don't know how to make the toggle that you mentioned.. Can you help me with that?
And I'd also like to insert a timer. (Visible if possible, if not, then there must be some way to show it after a certain time is finished.)
Probably 2 types of timers:
1. Timer for each question (Changes question when timer ends and deducts player'health', timer resets when question is answered and does not affect playerHealth)
2. Timer for the whole part of the game (Starts when playerDist < 50 on a doorway or when pressing 'E' on a button, stops when all questions are answered, then shows the time as a Text)

And if the player dies, everything resets back to when the game is launched.

Are those possible?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 4th May 2015 18:17
the toggle would just be another array to store whether the question has been asked or not - you're likely going to be needing a lot of arrays for this idea to work.

i would use something like this (where q is the question number)

--stores the questions
question[q] = "question"

--stores if question is asked (toggle to stop repeats)
question_asked[q] = 0

--stores the possible answers
choice1[q] = "possible answer 1"
choice2[q] = "possible answer 2"
choice3[q] = "possible answer 3"

--stores the entity number for the correct answer
answer_entity[question[q]] = #

--stores the health of the 3 entities
health[entity#1] = #
health[entity#2] = #
health[entity#3] = #


there's more but without writing the entire script myself that's the basic setup

for timers you can use 1 per entity with GetTimer(e) or you can make your own using g_Time (just store it once and then compare g_Time again to that value)

if you get some code done i'm sure we can help more if you get stuck
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 7th May 2015 17:09
I've started with the code... Successfully made the random question generator.. But it does an infinite loop so it shows all questions at a very fast rate (Caused by a for loop)

What I really need to know is how do you get the health of a certain entity?
And how do you stop the loop at one point until the question is answered?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 7th May 2015 18:56
there are a number of ways but a variable to say if i a question has been selected or not is probably easiest, something simple like
if question_set == 0 then
--pick random question code here
question_set = 1

else

--code to show question and check for answer
-- in answer check/update code rest question_set to 0
end

for the health check use something like this (replace e with the entity number of the object to check)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 8th May 2015 09:48 Edited at: 8th May 2015 09:53


Can you check the script? Idk what's wrong... I haven't added the "Entity Hit", "Check Answer", and other scripts yet. I'm kinda stuck.. I'm working with 3 languages atm, I keep on getting them mixed up.. especially java XD
I'm currently working on a random question generator so It won't ask the same questions every game.. Hopefully, It turns out to be a success.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th May 2015 12:24 Edited at: 8th May 2015 12:40
assuming you are going to be keeping the 3 answer system (which makes sense based on your answer detection system you want to put in place) i would use this
edit, added a question check to stop repeats

life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 8th May 2015 14:31 Edited at: 8th May 2015 14:33
I tried this one for each question:



It's not going so well... Placed it before



Any other way to check the answer? idk why it's not working.. I'm quite sure I placed it in the right place..

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th May 2015 17:20 Edited at: 8th May 2015 17:21
you need to 'end' each question or better yet use 'elseif', your flow is wrong.




i would also use questions[1] etc instead of question == "20 x 39" as it's much easier to update without checking for the exact question each time (just need to make sure questions[#] isn't empty first because of it's current placement in the script (before it gets randomly picked)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 8th May 2015 17:37
Sorry...

Thank You so Much for your help... And... How do I remove 1 life per wrong answer??? or deal damage to player per wrong answer? HurtPlayer(e,v)?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th May 2015 19:10
yes HurtPlayer(e,v) will do it (probably better to use that as i would quess using SetPlayerLives wont actually kill him if he drops below 0

life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 9th May 2015 08:04 Edited at: 9th May 2015 08:19
I added this under the correct answer to move to the next question if he answered correctly:



But everytime I hit the correct answer, it moves to the next question then dies.. Maybe it detects that the health of the entity is still lower that the stored health?
The strength of the Entites in the editor is set to 900 btw

I edited your "SetHealth()" to SetEntityHealth.... SetHealth had errors, probably because it wasn't in global.lua

Script so far:

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th May 2015 11:43
well i see you have quite a few of the entity numbers wrong when setting the health
e.g. you check for entity 3
Quote: "elseif g_Entity[entitychoice3]['health'] < health[entitychoice3] then"

but then change the hp for entity 1
Quote: "SetEntityHealth(entitychoice1,health[entitychoice1])"


and yh it should have been SetEntityHealth
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 9th May 2015 14:26
Well that's embarrasing XD

But there's still a problem (Hopefully the last one).

What is this for?


because the commands for entitychoice3 is not working... Nothing happens when I hit it...

And I still don't know how to make a timer XD .. like.. if a player enters the zone, a timer starts, and after a certain amount of questions with correct answers, Timer stops and Shows.... And the timer must also stop if the player dies... is this possible?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th May 2015 15:40
when you say dies, you mean dies completely? i.e. 0 lives? it'll be game over at that point.

Quote: "if g_Entity[entitychoice3] ~= nil then"


checks that entity 3 exists on the map
because if you place the zone first there is a very brief amount of time when the script will run before the other entities are ready (technically it's not just entity3 but it's most likely that will be the last)

a timer is always active for any entity with a script, just use Prompt(GetTimer(e)) to show it
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 9th May 2015 16:28
Dies I mean loses 1 life.

entitychoice3 isn't working.. if it has the answer for the question and I hit it, nothing happens... And there's also something wrong with question 7, I die if I hit the correct answer..

Script so far:
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th May 2015 17:15
this is working for me


rearranged the code a bit so that you have to be inside the zone and added an additional health reset while the question is being asked
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 9th May 2015 18:04
I tried it on a new map (TestMap) it works... But choice3 doesn't work on my real map ... I attached the files, can you see what's wrong? It's a small map but I don't want to start over again

script files are included (Some of them are not needed but I still included them)

Attachments

Login to view attachments
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th May 2015 18:55 Edited at: 9th May 2015 18:56
for me he appears to be entity number 2 (from GG's numbering system) and in your script you have set him as number 5 - i assume you deleted something and it messed up the order, just change the script setting to local entitychoice3 = 2 and it's all fine
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 9th May 2015 19:04 Edited at: 9th May 2015 19:17
It works!... I'll delete the attachments now then.

But I never really understood the numbering system.. what does it mean?
like..
local entitychoice1 = 3
local entitychoice2 = 4
local entitychoice3 = 2

idk what it means...

I also added this:

then added StartTimer(e) below if g_Entity[e]['plrinzone'] == 1

but nothing happens..
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th May 2015 19:47 Edited at: 9th May 2015 19:47
GG gives each entity/object in the map a number so it can relate to it later... from 1 to however many objects you have (think index)

there is no 'x' right? wont ever be above 2000 if it doesnt exist

just put something like
if GetTimer(e) > 2000 then
timer = GetTimer(e)
Text(90,40,4,"Time:")
Text(90,50,4,timer)
end

you dont really need to use StartTimer(e) - i find it causes more hassle than it's worth, the GetTimer(e) will work fine without it
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 10th May 2015 04:15 Edited at: 10th May 2015 04:23
Where can you find the Entity number?? (Sorry... Dumb question) XD

The timer is showing a very long number.. .. I want a timer that will start when the player enters zone, stops when a certain number of questions have been answered and shows on screen the time it took for the player to answer the questions...
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 10th May 2015 09:09 Edited at: 10th May 2015 09:11
Hi philrey32

Quote: "GG gives each entity/object in the map a number so it can relate to it later... from 1 to however many objects you have (think index)"


Quote: "Where can you find the Entity number?? (Sorry... Dumb question) XD"


see picture attached

The numbers will be different for all entity's

perelect
I may be old, but at least my memory still ....hmmm

Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2789 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)

Attachments

Login to view attachments
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 10th May 2015 10:19
Thank You Perelect.. Wow.. Can't believe I didn't know that -_- ..
Thank You so much .

I guess the only problem left in my script is the timer... StartTimer(e) . lets it start from 1 but it keeps on looping and going back to 1 -_-
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 10th May 2015 10:31
Hi philrey32

Quote: "I guess the only problem left in my script is the timer... StartTimer(e) . lets it start from 1 but it keeps on looping and going back to 1 -_-
"


I cannot help with that..
I am having troubles understand the timers and their structure, as well.

perelect
I may be old, but at least my memory still ....hmmm

Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2789 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 10th May 2015 18:59 Edited at: 10th May 2015 19:00
Thank You so Much for your Help guys! Especially smallg! I owe you a lot!
The project's main parts are finished.. Only one problem remains... when I show the Time, i used "Time / 1000" to convert it to seconds..
It works but it shows tons of Decimal numbers.. idk how many

Is there any way to remove the decimals and just show 2 decimals? like 20.57 Seconds?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 10th May 2015 19:13
Prompt(round2(GetTimer(e)/1000,2))

and add this at the bottom of your script

function round2(num, idp)
return string.format("%." .. (idp or 0) .. "f", num)
end
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
philrey32
9
Years of Service
User Offline
Joined: 8th Apr 2015
Location:
Posted: 10th May 2015 20:54 Edited at: 10th May 2015 22:09
It worked! (Changed it to work with my already present script).

Thank You so much smallg!
Indie Games are the future of gaming!

- Customized Gaming Rig:
AMD Radeon HD 7700 -- AMD FX-6300 Six-Core Processor 6CPUs ~3.5ghz -- 8GB RAM -- DX11 -- 1920x1080
PM

Login to post a reply

Server time is: 2024-05-07 19:43:50
Your offset time is: 2024-05-07 19:43:50