View unanswered posts | View active topics It is currently Thu Dec 26, 2024 4:20 am



Reply to topic  [ 13 posts ] 
 Magazine Swapping 
Author Message
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Magazine Swapping
Hey.

I have been trying to write some code that changes the magazines of all the same weapons on a specific team when they have a specific item in their inventory



So the code is suppose to go through all the actors on the map if the item it's attached to is created (adding another if to check it stays team specific?)
It then checks if the actor has a specific weapon.
It saves the weapon the actor is holding into a local variable "gun" then changes the magazine of that weapon.
Problem is if he's not holding the weapon we checked for with the "HasOBject" then the wrong weapons magazine gets swapped

So how would I go about searching for the weapon in his inventory and then swapping the magazine?
How do I keep the swapping team specific

Thanks in Advance


Tue Jun 26, 2012 9:11 am
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Magazine Swapping
Doesn't that first scan for the shotgun in the actors' inventory, then index the variable gun as their held item? It mustn't be certain they're actually holding the weapon.

Swapping the magazine when the weapon is held wouldn't be a problem, I think it could look something like this:

Making the swapping team-specific depends on what swaps the magazines. If it is, for example, something shot by a teammate, you can try adding this:


I haven't tested this though. I hope it helps (works)! :)


Tue Jun 26, 2012 1:35 pm
Profile
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Re: Magazine Swapping
Well it is definitely trying to change the magazine but the problem seems to be that you have to hold the object (a explosive in my case) to run the script but when you hold the object then the object isn't the shotgun and thus does nothing.

When I run the script it gives a error : :6: attempt to index local 'gun' (a nil value)

Is there a way that I can go from actor to actor and then cycle through his inventory until I find the weapon that I'm looking for and then just swap the magazines?


Tue Jun 26, 2012 6:03 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Magazine Swapping
I'm not entirely sure if the magazine can be swapped inside the actor's inventory, but try this.

And can you please tell me what exactly makes the magazines swap? It can be crucial to how the script works.


Tue Jun 26, 2012 6:42 pm
Profile
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Re: Magazine Swapping
4zK wrote:
And can you please tell me what exactly makes the magazines swap? It can be crucial to how the script works.


Oh sorry, you buy a item, a container of sorts that upgrades the weapon, so for instance you buy a bullet container for the shotgun that swaps the magazine of the shotgun for an upgraded magazine with more rounds, it should get applied to all the weapons (that the container works on). Future weapons should also be upgraded if the container is still in one of the actors inventories. There are a few smaller technicalities.

I read on the wiki about SwapNextInventory and SwapPrevInventory except that I don't know how to use them, is there a way that I can use those commands with a loop to go through a actors inventory, checking all the weapons he has and then swap the magazines?


Tue Jun 26, 2012 7:12 pm
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post Re: Magazine Swapping
I believe it takes a moment in-game for the actor to actually switch weapons using one of those two functions; you won't be able to cycle through all of their weapons in one create function.

It's a little more complicated and you'll be able to see the actors rapidly cycling through their inventories, (which will look weird) but it does sound doable.

The only problem about that for which I can imagine no solution is knowing when you've cycled through an actor's inventory once entirely.
I suppose since redundancy of setting the next mag to be used isn't a problem, you could just swap weapons ten or so times, change the mag if it's the right weapon, and you'd probably get all of them.


Tue Jul 03, 2012 3:32 pm
Profile
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Re: Magazine Swapping
I have found a workaround, seeing as I don't know how to even write the code for something that goes through the actors inventory

So plan B:
Code/Example how I would go about removing something from an actors inventory or adding something to an actors inventory?

Also thanks Azzuki one of your older mods gave me the idea ^_^

EDIT: Seriously Azzuki your mod saved my bacon, thank you very much.
I'm going to use a pie slice on the weapon, how do I get thethe actor in a variable so I can check if he has an item?
If you place something in a actors inventory does it go in his hands?


Thu Jul 05, 2012 2:18 pm
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post Re: Magazine Swapping
So in a gun's pie menu script, you're wanting to reference the actor holding the gun?
That's actually easier than referencing the gun itself! It's just "actor" or whatever you have in the parenthesis on the respective function line.

And yes, if you add something to an actor's inventory, it is also equipped, I believe.


Thu Jul 05, 2012 6:04 pm
Profile
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Re: Magazine Swapping
So I created a Pie Slice with my Lua attacked and no error when I run CC but as soon as I use the Pie menu it says there is an error with my Lua

The code:


It says line 3 attemp to index local 'gun' (a nil value)
What did I do wrong?


Fri Jul 06, 2012 9:35 am
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: Magazine Swapping
Your check is a little too simplistic, I think.

Code:
function ChangeMag(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      gun:SetNextMagazineName(New Magazine");
      gun:Reload();
   end
end


Fri Jul 06, 2012 6:43 pm
Profile YIM
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Re: Magazine Swapping
Arcalane I owe you, seriously it took me a week to get the code for this to work
Thank you and thanks to all the help from everyone.

Just one small thing, how do I add and remove items from an actors inventory?
The wiki has a AddInventoryItem but I'm not sure how to use it.


Fri Jul 06, 2012 9:40 pm
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: Magazine Swapping
BrainChild wrote:
Arcalane I owe you, seriously it took me a week to get the code for this to work


:roll: I got that from the Coalition Missile Launcher... it's what I use for all the 40K recomp ammo switching.

Note that the sixth line forces an immediate reload of the weapon, so you may (or may not) want to remove it. Just a heads up.


Fri Jul 06, 2012 10:58 pm
Profile YIM
User avatar

Joined: Sun May 23, 2010 7:11 pm
Posts: 193
Reply with quote
Post Re: Magazine Swapping
Arcalane wrote:
:roll: I got that from the Coalition Missile Launcher... it's what I use for all the 40K recomp ammo switching.


O.O now I feel stupid, didn't even notice it could switch. Thanks anyway


Sat Jul 07, 2012 7:43 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.039s | 13 Queries | GZIP : Off ]