Scripts / Problem with ammo script that doesn't destroy the pickup

Author
Message
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 14th Feb 2014 14:51 Edited at: 19th Feb 2014 06:57
Hey all working on another script at the moment and have tried many things over the last 4 hours to try and solve this myself but have come up short, basically what i want to do is have the player purchase some ammo, ammo gets added but stays there so it can be purchased again. The problem i am having however is that upon pressing the E key to purchase unless it is a very quick tap on the key you will purchase the ammo multiple times over, i tried adding a wait function but native LUA doesn't support this. Anyway here's the script in progress and if anyone can get this working i would be very thankfull.









EDIT: Final working script below

Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 14th Feb 2014 14:53
oh and for those who are looking for random scripts to learn from here's one for the shotgun that requires to player to level up to level 3 to unlock it.





Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 14th Feb 2014 19:50
for now i think the best way to do it is to set is so the player needs to move away from the ammo and then back again - as like u said there is no standard 'wait' command



although u could use my breath system to make a timer too it is easier and quicker to just move away and back.



i havent tested these but here's an example



(i may have got the end statements in the wrong place there but basically u need a variable that changes based on distance)



for this one i think you will need to set puchased = 1 as a global





or timerbased



for this one i think you will need to set timer = 1 as a global





hope they work for u

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 14th Feb 2014 22:05
Didn't even think of that cheers, I'll try that when I get a get a chance to get back on the com. Should even be able to make that a local variable instead of running another global too.



Thnx

Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 17th Feb 2014 23:16
Hi AuShadow

I think you have fallen in to the trap when you removed the key entry check code used in the door script.



if g_KeyPressE == 1 and door_pressed == 0 then

-- do some thing

door_pressed = 1;

end



and then we have the code at the bottom of the script..



if g_KeyPressE == 0 then

door_pressed = 0;

end



I think this is the way it works.. When you press the E key the keyboard has a buffer that fills... so if you linger on the E key then you get your multiple entries.. The code at the bottom empties this key buffer. So you can't get back into the [do some thing ] part until the buffer is empty and door_pressed is reset to 0...
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 18th Feb 2014 09:19
Thanks will try this tomorrow

Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 19th Feb 2014 06:55
Script is now fully operational here's the final script:

allows ammo to be purchased multiple times without being destroyed as long as the player has the correct amount of cash







enjoy

Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Feb 2014 21:39 Edited at: 19th Feb 2014 21:41
nicely done, see u are really getting the hang of basic scripting so now maybe you'd like to have a look at arrays (not an expert myself as they can be difficult to figure out sometimes)

they will greatly decrease the amount of typing needed for such code



this code does almost exactly the same as yours (slight difference in discounts but that could be adjusted with the correct formula, i merely used £50 per level as an example)



other than the obvious variables that need setting (i.e. level, discount etc... which u would already have for such a script) you will need to set
Quote: "price = {}"
under the
Quote: "Globals (built-in)"






and a video to show it working

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 20th Feb 2014 09:57
Yep formula for different discounts shouldn't be a problem for me but yeah I am new to coding so arrays are very new to me but looking at your code I am very intrigued and definitely going to do a bit research into this, thank you

Feel free to visit and edit the public FPSCR resource wiki page



http://fpscrresource.wikispaces.com/home
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 20th Feb 2014 19:35
i realised after that i didnt explain very well what u would use the array for seeing as u could just use the formula and ignore the array completely (seeing as u will only be using 1 price at any 1 level)

but basically an array is a way of storing a list and then being able to easily recall or modify such list without having to write loads of code again



it's not very easy to show in FPSC-R right now as we can't really display multiple prompts at once but if you wrote in something like



Quote: "Prompt("price at level 1 = £" .. price[1] .. "price at level 2 = £" .. price[2])"




etc, it would display every price correctly (basically saves u needing to rewrite the formula everytime)



this makes it very useful for displaying inventories (shops etc)

but as i say, it's not very user-friendly in FPSC-R as it stands but hopefully in future they will be and are definitely worth looking into.



hope that makes sense

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11

Login to post a reply

Server time is: 2024-12-22 01:08:35
Your offset time is: 2024-12-22 01:08:35