Scripts / Object control in game

Author
Message
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 20th Oct 2014 13:18
I don't know if it is possible with scripts? I want in the game a counting control of several objects you collect. (Global script?)
When not all of the objects are collected you cannot finish or win the game. When collecting objects a prompt message will apear
how much you have to collect of the total collected objects.
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 20th Oct 2014 14:10
Yep its possible. You just have to use various assigned global variables for your objects. Then create a check if all variables equal out to the desired total for each then use:

FinishLevel()

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce 420 GT
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 21st Oct 2014 15:18
just adding something...

Quote: "isObjetive = 1
Specifies the number of the objetive, if this entity is used to complete the level."


via entity>properties panel.

3com
PM
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 21st Oct 2014 17:13
I need a counter for the collected object, I cannot find a counter in the global script.
Is it possible to add this functions to the global script? I don't know if it is permitted to change the global script.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 21st Oct 2014 21:07
I don't though that since all command should run internally pre-build functions within engine, so do not make sense add some command, if their function is not created yet within the engine.
Better so, follow the Teabone's guidelines; write some script, declare global variables, even a counter variable and increase it by 1, each time any item is collected.
Since you know how many colletable items you put in your map, put this quantity into variable, named lets say <nItems>. Well, when variable called <counter> being equal to <nItems>, so game over.
Reloaded automatically advise you about the item collected.
Since I'm really new with LUA, no sure if you can declare a very hight variable, so you can use it to hold values, even increase it, and being acceced for any script in any moment for query/add/modify its value.
Also would be useful be able to declare static variables.

As you can see, I can give the theory, but the LUA script is other history, I've my doubts like you.

3com
PM
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 22nd Oct 2014 09:08
I created this script:


-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Items

function collect_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
if PlayerDist < 80 then
collecting = collecting + 1
prompt(collecting " objects collected")
PlaySound(e,0);
Collected(e);
Destroy(e);
end
end

I put: collecting = 0 in the global

Testing the game will freeze Reloaded while collecting the object.
What is wrong?
Gtox
3D Media Maker
10
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 22nd Oct 2014 10:33
Your Prompt formatting is incorrect. Also, you don't have to add 'collecting=0' to the global script, you can add it to the collect script.

vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 22nd Oct 2014 11:11
Many thanks it is working

I have questions about the script > is the function name_init (e) is only used for global? <
> if an object is using this collecting script the global setting collecting = 0, when second object
is using this script it is not reading collecting = 0 because it will not counting up. Is it true it will
only read the local script?? <
Gtox
3D Media Maker
10
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 22nd Oct 2014 12:13
As far as I know the init(e) part allows you to use multiple custom scripts (initially there was a limit of around 17, I think). I don't understand your second question, sorry.
vrg
10
Years of Service
User Offline
Joined: 27th Aug 2014
Location: Netherlands
Posted: 22nd Oct 2014 12:57 Edited at: 22nd Oct 2014 13:03
This is the final working "collect" code with the support of the forum. Thanks

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-12-21 18:25:08
Your offset time is: 2024-12-21 18:25:08