Scripts / help with script: vending machine

Author
Message
warlock12
8
Years of Service
User Offline
Joined: 12th Sep 2016
Location: Argentina
Posted: 12th Dec 2017 14:06
I have started to make scripts with relative success, but this one is breaking my schemes !!! Hahaha! I do not pretend something very complex, I have humbly come here ...

function pagadrink_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
Prompt ("Presione [E] para tomar una");
if g_KeyPressE == 1 and currentcash >= 100 then
Thirst = Thirst + 1000;
currentcash = currentcash - 100
end
else Prompt ("Lamentablemtente no tienes cash");
end
end

help with script: vending machine
I've been with a script for hours that should let us drink a can if we have money, get rid of thirst and money (100) and if we do not have money to say it ... I have this and I can not make it go ... Any advice Geniuses of Scripting ????

THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
The game is a serious thing (El juego es una cosa seria)
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 12th Dec 2017 14:48 Edited at: 12th Dec 2017 14:56
Firstly -Stop using semi colons at the end of you lines ( ; ), they're not needed, and probably mess up the script.

Secondly -Why are you calculating player distance in your script? That's actually in gobal.lua already using GetPlayerDistance(e).

Replace all of:



With the single line:



so your script would look lke:



EDIT: I might be missing an end somewhere, on my phone so hard to tell

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.
warlock12
8
Years of Service
User Offline
Joined: 12th Sep 2016
Location: Argentina
Posted: 12th Dec 2017 14:56 Edited at: 12th Dec 2017 15:08
Uf Belidos !!!! Thank you very much ... well, errors are a sign that I'm not very good at scripting. I hope some time to understand ... there are many details and a single mistake is chaos ... Thanks again Belidos !!!!!!!! A Big Hug!!!!

--- end is not missing ... the only problem is that the "else" prompt is always present ... do not worry, I'll solve it, now you've cleaned my code a lot: thanks a thousand!
The game is a serious thing (El juego es una cosa seria)
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 12th Dec 2017 15:29 Edited at: 12th Dec 2017 15:33
OK, got to a PC and had a good look at it, your else function is wrong too, it has no variables so will display all the time when you are not right next to the object, you basically need to add an if distance, key, and currency then line to the else and move it to the correct position, like so:



That will make it so that if you walk up to it it prompts you to press E, then if you have cash will add 1000 to your thirst and take 100 cash when you press E, but if you press E without enough cash it will tell "Unfortunately you do not have cash"

I've attached the script with added variable declaration and text display for cash and thirst so you can test it standalone without other scripts, just put it in an always active and not static object.

If you need the variables to interact with the same variables on other scripts it would be best to make them g_currentcash and g_thirst instead.

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.

Attachments

Login to view attachments
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 12th Dec 2017 15:38
Quote: "ell, errors are a sign that I'm not very good at scripting. I hope some time to understand"


I'm terrible at scripting myself, but i keep at it, and i keep a lot of little script reference notes to help me remember. A lot of the time it's just logical progression throughout the script so it's quite easy to guess what should come next

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.
warlock12
8
Years of Service
User Offline
Joined: 12th Sep 2016
Location: Argentina
Posted: 12th Dec 2017 16:13
OKAY! Thanks and I really appreciate the clarity of the explanation ... after all it was a bit more complicated than what I supposed ... I did not understand the variables with g_ (the g is global ... mmm .. .) Now I will change all the references to the variables following your advice.
Wow Beloved ... not just 3dMaker ... now also ScriptMaker! That good!
A big hug!
The game is a serious thing (El juego es una cosa seria)
warlock12
8
Years of Service
User Offline
Joined: 12th Sep 2016
Location: Argentina
Posted: 12th Dec 2017 16:25
It works wonders !!! Well, now that I wanted to have a script, look for a way to put it together and with your proposal that works ... I have a clearer idea of the structure that it should have !!! Thanks again!
The game is a serious thing (El juego es una cosa seria)
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 12th Dec 2017 16:32 Edited at: 12th Dec 2017 16:34
Hi warlock12 you should be able to adapt this to your needs make sure your entity has isimobile on it otherwise it will face you (I left the position lines in incase you want to put it on a character = shop)
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Attachments

Login to view attachments
warlock12
8
Years of Service
User Offline
Joined: 12th Sep 2016
Location: Argentina
Posted: 12th Dec 2017 16:58
Wow ... the original joy is tarnished ... if you do not care how long you press "e" you will run out of money ... I tried with

if g_InKey = "e" == 1 and currentcash> = 100 then

and all the cash is consumed immediately ...
I will look for a function that detects the pulse of the click and not that it is being clicked continuously ... When this is finished I will share it ... it seems to me that there is not something similar and of course with the eternal thanks to belidos!
The game is a serious thing (El juego es una cosa seria)
warlock12
8
Years of Service
User Offline
Joined: 12th Sep 2016
Location: Argentina
Posted: 12th Dec 2017 17:03
Honkey !!!! Thank you, Mil! All help is great when you want to learn about this! As PCKiller said ... this is the best community in an engine ... it already looks like a family ... What started Granada and so many seconded it helping the kids from Africa really brought me a lot of emotion. I already fixed! This script seems to me that it will have many parents and no mother ... the opposite of parthenogenesis for three ... ha ha ha
The game is a serious thing (El juego es una cosa seria)
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 12th Dec 2017 17:24
Yes originally by smallg adapted for galaxies now adapted for you
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Login to post a reply

Server time is: 2024-12-23 00:35:12
Your offset time is: 2024-12-23 00:35:12