--
-- Semanatoare De Paioase SUP 29
--
--
-- Script Specializat Pentru SUP 29
--
-- @Autor: Mihai94
-- @Data: 06/06/2015
-- Versiunea: 1.0
--
--
-- A Nu Se Modifica Fara Permisiunea Mea...
--

SUP29 = {};

function SUP29.prerequisitesPresent(specializations)
     print("......INCARCA SCRIPTUL PENTRU SUP 29 DT BY MIHAI94......");
	return true;
end;

function SUP29:load(xmlFile)
	
	--ANIMATIE USI CLIP
	local Capac = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Capac#index"));
	if Capac ~= nil then
		self.Capac = Capac;
	end;	
	
	-- SUNETE ANIMATII CLIP 
	openSoundFile = Utils.getFilename("Scripturi/Inchide.wav", self.baseDirectory);
    self.openSoundId = createSample("LizardHor12nSound");
    loadSample(self.openSoundId, openSoundFile, false);
    self.openPlaying = false;
	
	clouseSoundFile = Utils.getFilename("Scripturi/Deschide.wav", self.baseDirectory);
    self.clouseSoundId = createSample("LizardHor12nSound");
    loadSample(self.clouseSoundId, clouseSoundFile, false);
    self.clousePlaying = false;	

end;

function SUP29:postLoad(xmlFile)
end;

function SUP29:delete()
end;

function SUP29:readStream(streamId, connection)
end;

function SUP29:writeStream(streamId, connection)
end;

function SUP29:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
end;

function SUP29:getSaveAttributesAndNodes(nodeIdent)
end;

function SUP29:mouseEvent(posX, posY, isDown, isUp, button)
end;

function SUP29:keyEvent(unicode, sym, modifier, isDown)
end;

function SUP29:update(dt)

--ANIMATIE USI CLIP
local nearestDistance = 3.0;
    local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
    local px, py, pz = getWorldTranslation(self.Capac);
    local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
		if distance < nearestDistance then
			self.Des_Capac = true;
		else
			self.Des_Capac = false;
		end;
		
	if self.Des_Capac then
		if InputBinding.hasEvent(InputBinding.Set_Capac) then
			if self.animationParts[1].clipEndTime then
				self:setAnimationTime(1, self.animationParts[1].offSet);
				self.sound1 = true;
				self.sound2 = false;
			elseif self.animationParts[1].clipStartTime  then
				self:setAnimationTime(1, self.animationParts[1].animDuration);	
				self.sound1 = false;
				self.sound2 = true;
			end;
		end;
    end;
	
	if self.Des_Capac then
		if self.animationParts[1].clipStartTime then
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Deschide_Capac")), InputBinding.Set_Capac);
		else
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Inchide_Capac")), InputBinding.Set_Capac);
		end;
	end;
	

	--SUNETE USI ANIMATE CLIP
	if self.sound1 then
       if not self.openPlaying then
            playSample(self.openSoundId, 1, 3, 3);
            self.openPlaying = true;
        end;    
    else
        if self.openPlaying then
            stopSample(self.openSoundId);
            self.openPlaying = false;
        end;      
    end;	
		if self.sound2 then
       if not self.clousePlaying then
            playSample(self.clouseSoundId, 1, 3, 3);
            self.clousePlaying = true;
        end;  
    else
        if self.clousePlaying then
            stopSample(self.clouseSoundId);
            self.clousePlaying = false;
        end;     
    end;
	
	
	
end;

function SUP29:updateTick(dt)
end;

function SUP29:draw()	
end;

function SUP29:onEnter()
end;

function SUP29:onLeave()
end;
