Scripts / crafting scripting possible yet or in future?

Author
Message
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 9th Apr 2014 20:25
so I have been thinking on the crafting scripting possibilities, and I am wondering if how it could be done.



for example I want to make bullets so I would need gunpowder, casings and some lead or copper. which in itself is not to hard to produce for entities if your a modeller..



but im no scripter so, now for the hard part lol.

im guessing that I would need a base script for each item to be combined to make a 4th item which would not be a model entity, but a value added to the ammo supply counter instead. is it possible to write a script that calls multiple items to give this result? could also be used for health/stamina boosts.



I was thinking of trying avrams scripting tool again but tbh I don't know where to start lol. any advice or thoughts would be appreciated

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 9th Apr 2014 20:45
Not really possible until we can show/hide entities or make new ones really. You can do the base work in readiness, but no real way of displaying the finished article. I thought about it awhile ago while making my R4 unit but didn't bother as I knew I wouldn't be able to get the parts to spawn a new droid, just tell you in text, which rather ruins the effect lol.



SPECS: Q6600 CPU. Nvidia 260GTX. 8 Gig Memory. Win 7.
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 9th Apr 2014 21:26 Edited at: 9th Apr 2014 21:29
oh this I guessed, but im after a script that just adds ammo to the counter and health really for now m8, the sort that checks if a+b+c is met and =d

d=say 50 bullets or 100 health, that sort of thing for now anyways.





edit, for example I used ammo but you could combine your farming script and make hot meals for example. potatoes + redroot + spiced potatoes + 100 health?



edit 2, add a timer cooldown on when you can next eat a meal and away you go lol??

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th Apr 2014 21:31
as DVader says until we know for sure which commands are added (there will be multiple ways to do such a thing) it's all just theory but yes you can definitely write a script for it - and once you get going it'll be pretty easy





i think the best/most efficient way would be to keep a player inventory that you update each time the player collects something (i.e. give each collectable item a variable and then increase the number when one is collected)



then when u get to the crafting bit u can just compare the values (however many is needed of each item to make said recipe) with said inventory and then lower the inventory counts as required (recipe costs) and increase the new numbers (newly crafted item) and done (after u include the spawning of the new item maybe)





hopefully that makes sense

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 9th Apr 2014 21:36
Quote: "i think the best/most efficient way would be to keep a player inventory that you update each time the player collects something (i.e. give each collectable item a variable and then increase the number when one is collected)"




I do want/need a player inventory screen at some point so agree with this



i liked watching dvader script for farming and selling, add a workbench for crafting items that don't need models would be fairly cool and easy i would think? the invent is there sort of in dvaders vid for farming just not a visual 1 yet. just a case of calling all the items somehow and getting the right results.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 9th Apr 2014 22:01
While we can not create new entities (to pick up) such as ammo, we can still call AddPlayerAmmo(e), so if we have the e (or it's value) of our ammo entity (that can be hidden somewhere in the level) we can pass it to the AddPlayerAmmo() function, effectively giving player clip of our (hidden) ammo

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 9th Apr 2014 22:24
im not sure i follow exactly but ok ...lol sorry new to game making and coding/anything else related. can you go into more detail at all?.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th Apr 2014 22:35
he's talking about a work-around for the current coding system



if you simply want to add ammo as the result then you can use the AddPlayerAmmo() function to do so

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 9th Apr 2014 22:38 Edited at: 9th Apr 2014 22:42
^^ What smallg said... a bit explained: Each entity has it's own identifier (a unique number generated by FPSC:R engine) usually referred to as "e" because all our lua scripts are defined as function scriptname_main(e) ... end. When engine calls scriptname_main() function for entity, it passes entities identifier "e" to our function. This allows to use same function (or script file if you wish) on multiple entities. So if you have two entities with identifiers (their "e") 1 and 2, when engine is calling our script for first entity it'll call scriptname_main(1) and "e" your scriptname_main() function will be 1. When it calls same function for second entity, it calls scriptname_main(2) and "e" within our function will be 2. You can test this by making simple function and assign it to multiple entities. Then, in the script, check if the player is near and just call Prompt(e) and you'll see different number as you approach each entity running this script.







Same goes for AddPlayerAmmo(e). If we assign ammo.lua to our ammo entity, the engine will call ammo_main(e) where "e" is identifier of our ammo entity. However, if we know the value of "e", for example if it's 15, we can then call AddPlayerAmmo(15) from our crafting script, and it will assign ammo of the entity with id #15 to our player. Then we just hide ammo entity (with id #15) somewhere in the level so player can't find it and that's it



Hope it's more clear now? If not, I might try to make simple demo but I'll have to use my OOP LUA toolkit in order to get "e" of remote entity.



edit: I wouldn't call it a work-around, it's perfectly "legal" scripting for me.

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 9th Apr 2014 22:51 Edited at: 9th Apr 2014 22:53
Quote: "Then we just hide ammo entity (with id #15) somewhere in the level so player can't find it and that's it "




now i understand lol, so a deep bit of water and hide said entity under it would be good enough for this, or a high enough mountain or something = to hiding it cool gotcha .



so in short basic health and ammo crafting IS potentially doable in away cool cheers guys, i was hoping so .

will have to play with your lua tool avram m8 and try to figure out some things with it but you have given me hope.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th Apr 2014 22:54 Edited at: 9th Apr 2014 22:55
ok done, video here http://youtu.be/OlShmr8kqoY



basically i added 3 items that you need 1 of each of and a crafting table



crafting table script



filename; crafter.lua





the collectable items i did in seperate files just for speed as im a noob coder but they would probably be better in an array in future



file name; craftitem1





craftitem2





craftitem3





also there is a hidden ammo pack under the ground which adds the ammo (just because the current functions require it



craftedammo.lua





if you wanted to change the recipe you would need to edit the line

Quote: "if craftitem1 > 0 and craftitem2 > 0 and craftitem3 > 0 then"


in crafter.lua



(for now it just checks u have at least 1 of each)





have fun playing

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 9th Apr 2014 23:05
WOW smallg the vid show just what i was thinking lol. and i didn't even think about hiding something inside terrain hahaha...



thanks a lot for all the code's amazing to see working so soon tonight lol great stuff and very kind/good of you also.



im going to study them and see what i can learn

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 10th Apr 2014 00:55
ok im confused lol...



I see it working for you but not for me, returns a nil error which I think is a naming issue?, but I named everything what you posted above sowhat did I do wrong please? I have had other scripts work fine that I have added by other people.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 10th Apr 2014 01:00
That's cool, but what if you want multiple types of ammo? You'd need to make separate script for each one of them.



With my toolkit you could place ammo below the crafting table (and below ground), give ammo different script than ammo.lua that will just call aEntity:new() to give it a name, something like this:







And then, the crafting script would be very similar as smallg's, except instead of setting global craftedammo to 1, you'd call something like this:







This way the player will get ammo that is nearest to our crafting table, so you can have as many types of ammo as you want, without having to make separate script for all of them. Just place ammo near to the crafting table and the table will look for nearest ammo entity and give it to the player (once you have enough resources).

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 10th Apr 2014 01:05 Edited at: 10th Apr 2014 01:37
so how would I add the new code's to do this please?.

and just to be clear for me where am I adding all these scripts? im not able to get them to run lol. but thanks a lot for more help and ideas.



edit I think I figured it out lol... was saved as txt not lua have changed that so all should be well now lol..



edit 2, still cant get it to work lol damn my feeble brains hahaha.. smallg can you show or tell me how you set it all up please m8 lol thanks.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 10th Apr 2014 09:50
I guess you don't have some global variables defined which are used in smallg's scripts.



I will try to make demo for multiple ammo types these days. The main problem is that I'm spending 90% of my time on my laptop (like now) which I use for work, and I just can't allow myself to install FPSC:R here because I would probably lose my job so don't expect it before the weekend.

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 10th Apr 2014 14:42
ok, so I may or may not need some extra scripts for global.lua I see thanks avram m8 . and yeah don't get into trouble at work m8...



so before anything else maybe we could expand on the crafting scripts abit?, like aushadow/dvaders scripts for farming lvling up, could it be worked in that you get a small amount of xp (say 5-10xp per harvest) from finding raw mats for crafting ammo and health? and another small amount of xp (say 10-25xp )for crafting both health and ammo please?. also it would need to be adding a variable for random amounts of mats for crafting instead of an infinite amount from any 1 place? that way its more realistic.? also while on the topic of adding to the scripts abit, we could use your idea of making more than 1 type of ammo as a level requirement for each type like what dvader did with farming, so 9mm pistol ammo would be easier than say shotgun ammo or rifle ammo. and also make stronger types of health dependant on which foods you used perhaps? or is this stretching the abilities of reloaded to much you think?. I think I would need different workbenches for the different ammo types though ? what do you think, a lot of work I would imagine?!.

but worth it in the end perhaps

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 10th Apr 2014 17:11
@avram my intention was to show the basic theory working not to write the full script but yes it definitely needs more polish XD

p.s. is it possible for u to write a variable delay that actually pauses the game? like your bomb script but an actual hard
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 10th Apr 2014 17:39
ah, smallg thanks for the reply m8 so avram was right about the global's, cool will add them in and give it a shot.

and thanks if i run into more problems along the way i will stop by here again

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 10th Apr 2014 18:20
ok added your variables to global.lua, crafting ammo works fine now .



tried to add exp to crafting but so far am abit confused and stuck, have added all of aushadows variables and scripts to my global and script bank, but have been getting an error with your scripts when I add aushadows. I know im probably just putting it all together wrong so will play with it some more and see what happens .



thanks again every1 for everything so far.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 10th Apr 2014 19:10
glad that its working now



u just need to add the lines that apply to ur requirements not the entire script.



so for adding exp to the first item u would use





(as i said before u need to define exp as a global too)



as u can see, adding 2 lines only (technically 3 if u include the prompt) now you will gain 10exp each time you pick up craftitem1



then u can add a level up script or exp requirements etc etc

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 10th Apr 2014 22:35
ok after many hours of reading other scripts and the forums I have managed to come up with the following addin's to smallg script above with a lot of help and tips from smallg/avram and aushadow scripts here is a video of them working.







will add the scrips below for you all to view/use if you like



global.lua addins





the exp script (aushadows with slight changes to exp amount)





the show player lvl script (aushadows)





the crafting bench script (smallg script with some slight changes) called "crafter.lua"





the crafted ammo script (smallg script, only pistol ammo at present) called "craftedammo.lua"





this is a gunpowder script (smallg script with slight changes)called "craftitem1.lua"





a script for scrap metal (smallg script with slight changes) called "craftitem2.lua"





this is the script for bullet casings (smallg script with slight changes) called "craftitem3.lua"





ok add the global.lua to your global.lua file in script bank (make a back up)

add the rest as new scripts to your script bank

now to get the scripts to work just pick an object to be the items gunpowder, scrap metal, bullet casings and change the "main" to 1 of those scripts named craftitem1-3 (you could probably change the names of craftitem1-3 and still get it to do the same thing, I just didn't know how and gave up lol), the item can be destroyed but stay on the map if wanted by changing it from a static or dynamic entity. like the bin bags disappeared and some of the boxes stayed behind. (but this is a bit hit and miss in beta 5).

after getting the different items on your map hide the item holding the craftedammo.lua script somewhere under ground or high up on a mountain top, if you bury it in the terrain leave a marker there for remembering it for if you need it again.



if any1 knows of abetter way to do all this or thinks the code can be cleaned up post your changes here please for all to see thanks a lot to all involved with this little test run and enjoy the scripts im sure they can be changed to make food and health and more perhaps?!.. I hope I didn't forget anything here to get them to work lol...

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 10th Apr 2014 22:39 Edited at: 10th Apr 2014 22:40
smallg wrote: "is it possible for u to write a variable delay that actually pauses the game? like your bomb script but an actual hard pause (basically just a way of showing text for say 2 seconds before then showing the next line?)

i would but your timer is kinda confusing for me with all those new symbols

"




I don't think it's possible to pause whole game that way yet. Even if we could, we would probably pause our script also. Old FPSC had FPI command that would turn off player controls, freezing him in place while the dialog (or something else) is happening.



You can, however, display dialog easily, and restart it when player leaves the area. Something like this:







I haven't tested it but it should be something like this. Once whole dialog is seen, it won't repeat if you approach entity again. However, if you want it to repeat, simply remove "and not dialogFinished" from line #6 (and all other references to dialogFinished if you want).



I hope you have read aTimer documentation: https://bitbucket.org/Avram/fpsc-r-toolkit/wiki/aTimer



p.s. We really need [[b][/b]code lang=lua] syntax highlighting

p.s.2. Sorry for off-topic

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 11th Apr 2014 22:02
@hood looks very much like 7days to die... which is a great game so that's no bad thing... glad you got it working how you wanted - it's always much better to do it yourself if possible so you really understand it and thus makes it much easier to edit and
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 11th Apr 2014 22:48
Quote: "@hood looks very much like 7days to die... which is a great game so that's no bad thing... glad you got it working how you wanted - it's always much better to do it yourself if possible so you really understand it and thus makes it much easier to edit and expand, nice job "




i love 7dtd ... they have smoothed the terrain now so it is way better. for a voxel game its very good.

im glad its working also, which it wouldnt if not for you lol so thanks again .

it took be about 2 hours of experimenting to get the names gunpowder scrap metal and bulletcasings in lol, so yeah i need to learn some lua but this was a good way to spend a few days toying with code for reloaded, while we wait on beta6 .



Quote: "i.e. something like what i have now

http://youtu.be/8yQZFiWa608"




i watched this vid, amazing i didnt think of adding a %timer crafting action thingy lol so cool, but i wonder now could this be slightly changed to count down to when you could have another meal? for a health boost say?. something like 15mins waiting timer before eating again?, this would really be cool lol.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 11th Apr 2014 23:11 Edited at: 11th Apr 2014 23:26
yh the basic timer is something like

getting the time twice



Time1 = the base time

Time2 = the comparison time



then u take the first away from the second and work out how much time has passed.

Time2 - Time1 = TimePassed



in my video that's a 4 second delay between prompts



based on your requirements you would set a varibale check when trying to eat a meal



i.e.





then in another script (hidden script would be better i think) u would run a constant check for TimePassed to be over 900 (15mins)

i.e





i didnt test that but i think it should work.

but unfortunately there isnt really a decent way to display that timer for now (it would probably just override any other prompts without some effort) so for testing i would definitely reduce that 900 to a much lower value and / or comment out the "else" section of code.



p.s dont forget to give them function names if you do try them



and yh i saw, i was more happy with the respawning loot though tbh, definitely one of the better indie games

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 12th Apr 2014 01:48
smallg wrote: "i really wish i could get your timer stuff working but i had too many errors with your code snippet (something to do with tables and nil values... had a quick go at fixing it but couldnt figure it out) but i have a fully working custom delay now (albeit not a hard pause as i would like but it works fine and i have tried to code in such a way that i hope to be able to use it for any delay i should require in future - at least until they add a real delay function or i can get my head around your code )"




I have just tested my function from my previous post and it works without any modifications:







Can you tell me exactly what error are you getting (a screenshot will be also useful)? Have you placed my framework in folder scriptbank/Avram/ and have you installed it into global.lua?



There is one bug though, the "dialogFinished" check is not working, and I know why. I will fix this in a couple of days.

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 01:53
ok been playing around with the ammo making scripts, have a working cooking scripts now



not sure though how to add your timer though, i know i'm a pain here lol, but could you maybe guide me through some of it please lol? its the adding variables to global for timer im not so sure on and the timer bit of code being added to my meal scripts .



here are the scripts i have done today.



added these to global (was easy just renamed the ammo scripts and added new names to global





this is the crafter changed to a cooker





this is the cook meal script





this is the fooditem1 script







fooditem2 script





fooditem3 script





it all works and adds 150 health to player for each meal, but no limit on how much you can eat yet, though i have yet to try and add your timer so.. but if i knew what to do to get the
Quote: "yh the basic timer is something like

getting the time twice



Time1 = the base time

Time2 = the comparison time



then u take the first away from the second and work out how much time has passed.

Time2 - Time1 = TimePassed



in my video that's a 4 second delay between prompts



based on your requirements you would set a varibale check when trying to eat a meal



i.e. "
done i might be able to do the rest perhaps over time?!.



thanks for all your advice and help your a star

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 12th Apr 2014 11:13 Edited at: 12th Apr 2014 11:37
almightyhood wrote: "not sure though how to add your timer though, i know i'm a pain here lol, but could you maybe guide me through some of it please lol? its the adding variables to global for timer im not so sure on and the timer bit of code being added to my meal scripts"




It's easy as "local myTimer = aTimer.for_e(e)". This will create global timer for you tied to entity "e" (current entity), there is no need to create any global variables. Just make sure you have installed the framework as explained in wiki. The framework will take care of global (persistent) variables for you.



After adding above line your timer will be in "myTimer", so you can call myTimer:start() to start the timer, myTimer:stop() to stop the timer, myTimer:passed() to see how many seconds have passed since start, and so on...



If you want, I can explain this in more details, but I need to know where to start. How familiar are you with object-oriented programming? Do you know what class is and what object is, what are class fields (or class variables) and class methods (or class functions)? Do you know what are concepts of encapsulation, inheritance and polymorphism? I suggest looking at these two links if you are not familiar with OOP:



http://teknadesigns.com/what-is-object-oriented-programming/

https://www.youtube.com/watch?v=lbXsrHGhBAU



edit: Basically, instead of having loads of global variables and functions, object-oriented programming allows you to have one variable (an object) that encapsulates certain feature or entity (not like fpsc:r entity but entity in real life ), such as entity (like fpsc:r entity), player (like fpsc:r player) or timer (like certain feature... imagine this as our virtual stopwatch). This object then stores other variables (object fields) and functions (object methods) that are related to itself making our code cleaner and easier to maintain. When we call a method of our object, it will in most cases perform action on itself and store all changes (if any) into itself



As I said, imagine "aTimer" as a physical stopwatch. It has it's fields that can store the time when we started it and it has methods to perform actions, such as start(), stop(), reset() or to compute how many seconds have passed() since start (and start is stored as object field. When you instantiate object of a class (local myTimer = aTimer.for_e(e)), all methods you call on myTimer (e.g. myTimer:start()) are going to be applied to myTimer object. In other words you can instantiate as many timers as you want and have all of them running independently, just instantiate them in different variables (myTimer, myTimer2, myNewTimer, ...).



Similar story goes for aEntity class, except it's integrated with the engine more deeply than the aTimer class.



I have updated source of aTimer class so please re-download the framework from bitbucket.

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 12:10
ok, thanks for the help and explanation avram m8 but sadly i know nothing of coding and all of the above was/is over my head lol...

i should probably start with something easier all things considered as i have only done the "hour of code" lesson that was linked somewhere on here.

still thanks for helping me m8

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 12th Apr 2014 13:04 Edited at: 12th Apr 2014 13:05
Ok, can you do this:



1) Download my framework from bitbucket

2) Unpack it into fpscr_folder/scriptbank/ so you have directory structure like this:



NOTE: You will NOT have folder ".git" here, it's used for my version tracking software.



3) Add following code to the BOTTOM of your global.lua:





THAT'S IT FOR INSTALLATION



4) Now create a level with one table and any entity on the table.

5) Save following script as timertest.lua and assign it to the entity on the table.







This script should:



1) display something like "Dist to entity name: 1.4m; timer running: no; passed (s): 0" when you are within 250 units

2) start the timer when you are within 100 units

3) stop the timer when you are farther than 100 units



Let me know if it works, or give me exact error message you are getting (if any). You can also post a screenshot with error message.



Note: My toolkit assumes 50 units is 1 meter. At first I was using 100 units = 1 m but it was unrealistic. This may not be accurate, but it's better than displaying raw distance If anyone knows what is 1 m in FPSC:R distance units, please let me know.

Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 12th Apr 2014 14:48 Edited at: 12th Apr 2014 15:26
Very nice scripts. I can see this being very useful in the future.



I added the lua lines into my global lua this way,

-- Globals (built-in)

g_Entity = {}



-- Globals (passed-in)

g_PlayerPosX = 0

g_PlayerPosY = 0

g_PlayerPosZ = 0

g_KeyPressE = 0

charexp = 0

charlvl = 1

craftitem1 = 0

craftitem2 = 0

craftitem3 = 0

crafteditem = 0

craftedammo = 0



-- Common Updater Functions (called by Engine)



function UpdateEntity(e,x,y,z,act,col,key,zon,ani)

g_Entity[e] = {x=x; y=y; z=z; activated=act; collected=col; haskey=key; plrinzone=zon; animating=ani;}

end



I assigned the crafted item lua's to the items I chose to play with for testing (crates) and I have added the other scripts to my script bank. When running the loaded stalls at physics and the error I get is a nil value with no explanation of that "nil value". Im quite sure I did something wrong. Could some one enlighten me in a step by step on what to add and where exactly that should be added? I have no clue about lua and this would definately help me understand it better if I knew where things should be added.

Case: Antec 900, Mobo: Asus Sabertooth 990FX, CPU: AMD T1100 Thuban 6 core @3300 ghz stock settings, COOLER: Thermaltake Frio, MEM: G Skill Ripjaws X series DDR 3 @ 1866 9-10-9-28, HDD: 2 Western Digital caviar Black 750 Gb set in RAID 0, GPU: Saphire HD 6950 flashed with 6970 bios, PSU: Corsair CX750M, MS: Cyborg Rat 7, KB: Logitec G510, OS: Windows 7 home premium 64 bit.
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 16:07
ok the only thing i can think of is that 1 of the files is not named right, and i have now noticed i didnt give the names to 2 files so.



for the show xp script it should be called "displaylevel.lua"

for the xp itself to be added the script has to be called "exp.lua"



oh and 1 of the things i did wrong was save the files as txt not all files and put .lua at the end. so i was having this issue because my "exp.lua" was shown as follows exp.lua.txt which might be the course for you to?!, no idea though it should all work fine.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 12th Apr 2014 16:24
ok, Ive found the file name error I made, I accidentally hit a wrong button. So, Ive rerun the test, I think i was able to pick up everything but can not craft the ammo. . . . Thoughts on that? I buried a box of ammo under the ground, gave it the craftedammo.lua and placed a crate on it. There is no prompt to do anything when the crate is approached.

Case: Antec 900, Mobo: Asus Sabertooth 990FX, CPU: AMD T1100 Thuban 6 core @3300 ghz stock settings, COOLER: Thermaltake Frio, MEM: G Skill Ripjaws X series DDR 3 @ 1866 9-10-9-28, HDD: 2 Western Digital caviar Black 750 Gb set in RAID 0, GPU: Saphire HD 6950 flashed with 6970 bios, PSU: Corsair CX750M, MS: Cyborg Rat 7, KB: Logitec G510, OS: Windows 7 home premium 64 bit.
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 16:37
did you have a table with the crafter.lua script applied? the table should have this script and the craftedammo.lua script is for the ammo itself, should all work fine, im sorry i cant offer more advice this was 2 days of experimenting for me lol, and im still confused by it tbh so. please show a video of your test.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Imchasinyou
10
Years of Service
User Offline
Joined: 22nd Mar 2014
Location: OH
Posted: 12th Apr 2014 18:09
Just to show how ignorant I am to scripting, I did not assign the crafter to the table. I can build you anything, rapell down buildings, race a car (circuit) but scripting is just like heart surgery to me. . . .



Thanks for your advise. Ill keep poking at it to try to do other things with it. I would love to have an inventory system soon as I can see collecting rocks and then crafting wall parts

Case: Antec 900, Mobo: Asus Sabertooth 990FX, CPU: AMD T1100 Thuban 6 core @3300 ghz stock settings, COOLER: Thermaltake Frio, MEM: G Skill Ripjaws X series DDR 3 @ 1866 9-10-9-28, HDD: 2 Western Digital caviar Black 750 Gb set in RAID 0, GPU: Saphire HD 6950 flashed with 6970 bios, PSU: Corsair CX750M, MS: Cyborg Rat 7, KB: Logitec G510, OS: Windows 7 home premium 64 bit.
PM
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 19:44
so you got it working ok then?,

Quote: "but scripting is just like heart surgery to me. . . "
hahaha same here m8 same here..



@avram will download your tool and give it a try m8 thanks.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Apr 2014 19:51 Edited at: 12th Apr 2014 20:31
@avram thanks yh i thought i was missing files but couldnt find anything except your timer thread, working now so i will definitely be trying to work with ur code



@hood i will try post up some timer code for you when i get avrams working so i shou
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 20:34
im having trouble with avrams codes myself.











get these no idea why or what to really do lol im to feeble minded i think for all this adding changing coding stuff hahaha... never done anything like this before lol.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 12th Apr 2014 20:56 Edited at: 12th Apr 2014 21:06
You need to download my toolkit (oop lua framework) and put it in scriptbank/Avram/ as explained in this post.



@smallg: Great that you've suceeded! Now, when you've installed the framework, you may easily remove all those distance calculations and use framework for that:







As you can see, you can use either this:distance(aPlayer) or aPlayer:distance(this) - it doesn't matter from which side you measure distance. If you pass "true" as second parameter to the :distance() method, it'll format output in human-friendly format (in meters).



You can also use :distance() (and other methods) with other entities to measure their distance, provided that you know their "e" identifier value, and you can get it with my framework (more about that later, if you are interested).



p.s. Instead of aTimer.for_e(e) use aTimer:new(e) - it's the same but :new() is standardized with all other aClasses for_e() will be removed in future.



p.s.2. VERY important: When you build your standalone game, you will need to copy "Avram" folder from FPSCR_FOLDER\scriptbank\ to BUILT_GAME_FOLDER\scriptbank\ as FPSC doesn't know about my scripts (yet)

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Apr 2014 21:06
i think the issue may be that u have placed the entire folder from the download into your scriptbank folder?



i.e. the one called
Quote: "Avram-fpsc-r-toolkit-bbafa5ca13fe"


i went inside that folder and installed the folder named
Quote: "Avram"


into my scriptbank and it works fine



@Avram yh i will definitely be looking into that in more detail in future but i didnt want to change too much of hoods code as that would likely get confusing fast... hopefully this way he can see the timer code and how it works without having to worry about anything else yet.

many thanks

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 21:22
Quote: "i think the issue may be that u have placed the entire folder from the download into your scriptbank folder?



i.e. the one called

Quote: "Avram-fpsc-r-toolkit-bbafa5ca13fe"

i went inside that folder and installed the folder named

Quote: "Avram"

into my scriptbank and it works fine"




i knew it was something i was doing wrong lol, thanks smallg you was right on the money m8 lol.



ok so the timer works it counts upwards .

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 12th Apr 2014 22:30
It can also count backwards:







Note the "aTimer:new(e, 20)" and :left() instead of :passed(). Even if you use it like this (like countdown timer), you can still use :passed() as well as :left(), but you can't use :left() if it's not countdown timer (it'll always return 0). In addition to :left(), you can use :expired() to check whether the countdown timer has reached 0 (it'll return true or false). That's how my timed explosion example works.

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Apr 2014 22:59
right o avram m8, now all i have to do is somehow get it into the right script to work.



have been having some issues with that bit but i will keep trying. thanks again all involved .

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Apr 2014 01:20 Edited at: 13th Apr 2014 01:49
it's not really a case of adding but replacing code if you want to change it to a countdown







Quote: " Prompt("Time until next meal = " .. myTimer:left() .. "s")"


not sure how well that will work in it's current place, would be better to have the prompt in the cooker script but the timer info wont be working there (i believe it's possible if u get this entity number but cant try it atm)

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 13th Apr 2014 12:09
oh, i see ok thanks.



have added the above code inplace of the old 1, the 20s counter is showing but wont let me craft now for whatever reason lol. also having issues with the following code







without any timer code the cooking scripts all worked great, with the 1st lot of timer codes the above snipet didnt work.

i think i narrowed it down to a global.lua issue as it returns nil error, everything else worked but this until your replacement code in above post smallg m8, now with your latest code the crafting of a meal is not possible but harvesting is.



maybe a timer is not the right way to do this, so what about a if health is less than 750 eat else dont eat or something that makes code sense? lol sorry if this is abit noobish lol...

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 13th Apr 2014 12:11
smallg wrote: "not sure how well that will work in it's current place, would be better to have the prompt in the cooker script but the timer info wont be working there (i believe it's possible if u get this entity number but cant try it atm)"




This is where my framework really kicks in. You can access entities not related to the currently running script ("remote entities"), provided that remote entity has a name (atm. name set in FPSC:R is not available in LUA so you need to set it manually) and, of course, you know the name.











local cookmeal = aEntity:new("cookmeal") will get first entity named "cookmeal" it stumbles upon in game memory. More often, you would need to work with nearest entity, so you can make it like this: local cookmeal = this:nearest("cookmeal") - this will return handle for entity named "cookmeal" that is nearest to our (this, "cooker") entity (or nil if it is not found).



By using :nearest() and with clever level design, you can make wonders with not too many scripts

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Apr 2014 20:20 Edited at: 13th Apr 2014 20:29
it doesnt like the line

Quote: "local cmTimer = aTimer:new(cookmeal.e)"




when loading the level i get an error

Quote: "scriptbank\cooker.lua:8:attempt to index a local 'cookmeal' (a nil value)"






why is it .e? should i be changing that to the entity number of cookmeal?





and yh as i thought the issue u have almightyhood is that the new prompt i added is messing the sequence up, remove it and the else and it works fine





as for the other timer i/u posted, it's better just to try use avrams, his has much more control but i guess u are right about it being an issue with variables, maybe u didnt set mealdelay?



and currently you can't really tell what player HP is

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 13th Apr 2014 21:09
i still get a "not enough ingrediants" prompt though everything is set to having 3,5,3 and i have 100's of each lol. so im confused here yet again lol.

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 13th Apr 2014 21:50 Edited at: 13th Apr 2014 22:07
@smallg: You need the line before it so the engine can instantiate cookmeal object! Read below when it can be nil.







Login to post a reply

Server time is: 2024-05-05 23:07:32
Your offset time is: 2024-05-05 23:07:32