Also, double slashes are for ini comments, double hyphens are for lua comments.
Oh wow, embarrassing, my mind is all filled with java at the moment.
And sorry about that Xavier (also, sorry for the sloppiness of this, I made way too many errors for something so simple), change the line that says MovableMan:AddInventoryItem(self.pistol) to MovableMan:AddInventoryItem(CreateHDFirearm(self.pistol));
You mean self.parent.AddInventoryItem(self.pistol)? If so, it doesn't work.
I'm trying something now, so hold on for a moment.
EDIT: I just replaced the self.parent.AddInventoryItem line with MovableMan:AddInventoryItem and it doesn't work. It spits out a 'no match for function call '' with the parameters (HDFirearm).'
function Create(self) //This part finds the parent actor if there is one self.parent = nil; self.parentpickingdone = false; local actor = MovableMan:GetMOFromID(self.RootID); if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentpickingdone = true; end
//This part makes the weapon list and picks the weapon self.randPistol = {"","",""} -- Pistol preset names here self.pistol = self.randomPistol[math.random(#self.randomPistol)]
end function Update(self) //Check again for parents due to CC's weirdness when dropping troops in or spawning them in edit mode. May not be necessary for this, I'm not sure if self.parentpickingdone == false then if self.parent == nil then local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentpickingdone = true; end end end if self.parent ~= nil then //If we have a parent then add the gun to his inventory self.parent.AddInventoryItem(CreateHDFirearm(self.pistol)); self.ToDelete = true elseif self.parent == nil and self.Age > 1000 //Otherwise, after a second delay to double check if we have a parent, just add the pistol to the map. self.pistol.Pos = self.Pos MovableMan:AddParticle(CreateHDFirearm(self.pistol)) self.ToDelete = true end end
If this doesn't work, can you upload the rte? That way I can look at it properly and give you a working solution.
Wed Apr 24, 2013 3:20 pm
XavierStudios
Joined: Tue Feb 08, 2011 4:14 am Posts: 59
Re: Randomized Weapon upon Buying
Bad Boy wrote:
If this doesn't work, can you upload the rte? That way I can look at it properly and give you a working solution.
It gave me another error involving 'Actor:AddInventoryItem' not matching the HDFirearm argument.
Last edited by XavierStudios on Thu Apr 25, 2013 2:51 am, edited 1 time in total.
Alright, all fixed. Sorry it took so many attempts on here, I made so many little mistakes due to rustiness:
Code:
function Create(self) --This part finds the parent actor if there is one self.parent = nil; self.parentpickingdone = false; local actor = MovableMan:GetMOFromID(self.RootID); if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentpickingdone = true; end
--This part makes the weapon list and picks the weapon self.randPistol = {"Ballester-Molina","Ballester-Molina","Ballester-Molina"} -- Pistol preset names here self.pistol = self.randPistol[math.random(#self.randPistol)] end function Update(self) --Check again for parents due to CC's weirdness when dropping troops in or spawning them in edit mode. May not be necessary for this, I'm not sure if self.parentpickingdone == false then if self.parent == nil then local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentpickingdone = true; end end end if self.parent ~= nil then --If we have a parent then add the gun to his inventory print (self.pistol) self.parent:AddInventoryItem(CreateHDFirearm(self.pistol, "UMA.rte")); self.ToDelete = true self.parent:GetController():SetControlState(Controller.WEAPON_CHANGE_NEXT , true); else if self.Age > 1000 then --Otherwise, after a second delay to double check if we have a parent, just add the pistol to the map. local pistol = CreateHDFirearm(self.pistol, "UMA.rte") pistol.Pos = self.Pos MovableMan:AddParticle(pistol) self.ToDelete = true end end end
One thing to note, you can only use guns from this rte so right now they're all the same gun. While it's not necessary to add the rte to run from, not doing this can cause the wrong weapon to spawn when two mods have identically named weapons. Also, you have some dependencies on Unitec. Don't forget to remove them before releasing the mod.
Thu Apr 25, 2013 2:05 am
XavierStudios
Joined: Tue Feb 08, 2011 4:14 am Posts: 59
Re: Randomized Weapon upon Buying
Bad Boy wrote:
Also, you have some dependencies on Unitec. Don't forget to remove them before releasing the mod.
Thank you kindly. This is perfect for what I have in store, so all of my thanks go to you.
On the UniTec dependency, this mod is literally just getting started, so that won't be a problem in the future. I just needed a proper platform to start from and UniTec is reliable on that front.
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