Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Upgrade, Enhancement Items
After detecting the gun and if there exist any corresponding upgrades, you use
Code:
gun:SetNextMagazineName("Magazine Name")
Seeing the code you posted before, you might work the rest of the script with more ease now.
Mon Jun 25, 2012 10:17 pm
BrainChild
Joined: Sun May 23, 2010 7:11 pm Posts: 193
Re: Upgrade, Enhancement Items
This will probably be a very stupid question but the gun in the code gets replaced with the PresetName of the actual gun? and does my above listed code actually work?
Mon Jun 25, 2012 10:22 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Upgrade, Enhancement Items
BrainChild wrote:
This will probably be a very stupid question but the gun in the code gets replaced with the PresetName of the actual gun?
I didn't get the question =P
BrainChild wrote:
and does my above listed code actually work?
It doesn't look wrong at all, so I think it will work. Maybe you'll have to make some small changes, but I'm pretty sure you'll get it right after some tries.
Mon Jun 25, 2012 10:25 pm
BrainChild
Joined: Sun May 23, 2010 7:11 pm Posts: 193
Re: Upgrade, Enhancement Items
Your code snippet
gun:SetNext....
the gun gets replaced with whatever guns mag is going to be replaced?
And for the code working (even with some tweaking) is seriously unexpected, those are some half code bits I stole... it's not suppose to work
Also thanks for all the help, especially staying patient through all my questions and ideas
Mon Jun 25, 2012 10:30 pm
Arcalane
Joined: Sun Jan 28, 2007 10:32 pm Posts: 1609 Location: UK
Re: Upgrade, Enhancement Items
No, the 'gun' in this case is storing the name/ID of the weapon in question, and SetNextMagazineName tells it to change the magazine specified after reloading.
Mon Jun 25, 2012 10:38 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Upgrade, Enhancement Items
Oh yeah, about gun, that is just a variable. Name it as you want, but be sure to define it as local before so it isn't a global variable (local gun = actor.EquippedItem or something like it).
Mon Jun 25, 2012 10:42 pm
BrainChild
Joined: Sun May 23, 2010 7:11 pm Posts: 193
Re: Upgrade, Enhancement Items
I have absolutely no idea what I am doing.
What I have:
Code:
function Create(self)
for actors in MovableMan.Actors do if actor:HasObject("Perioticum Shotgun") then local.gun = actor.ItemEquiped gun:SetNextMagazine("MagSniperRifle") break end end end
What it does: NOTHING.
Some help please. Actual code would be a great help (Especially how the variables get their values). I don't have the slightest clue what to do.
Tue Jun 26, 2012 12:11 am
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Upgrade, Enhancement Items
Code:
function Create(self)
for actor in MovableMan.Actors do if actor:HasObject("Perioticum Shotgun") then local gun = actor.EquippedItem gun:SetNextMagazine("MagSniperRifle") break end end end
That's the code with some things corrected. Now, the thing that I think is complicating this is that if you use actor.EquippedItem it would store the currently held item (which is the upgrade item) in the gun variable, hence, doing nothing but errors.
I think that the item would have to swap to the next inventory item until it finds the gun, and then storing it in gun. Hmm... I haven't got much knowledge about inventories. You should ask about this on the lua scripting sub-forum.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum