Jump to content

Weapon replace problem


IStarkI

Recommended Posts

I have a problem with this code and I need some help.

So when I am changing the weapon to AK47 the only thing I receive is spam on chat and I have no idea how to fix it.

It's only happening when I add engineImportTXD and engineReplaceModel. Without It everything works perfectly.

Can someone help me or give me some better ideas?

GM - DayZ

function wczytaj()
	txd = engineLoadTXD ( "models/ak47.txd" )
	dff = engineLoadDFF ( "models/ak47.dff" )
	outputChatBox ( "wczytano podmianki" )
end
addEventHandler( "onClientResourceStart", getRootElement(), wczytaj )


function podmiankibronki ()
	local bronka = getPlayerWeapon ( localPlayer )
	if(getElementData(localPlayer,"currentweapon_1") == "AK47" and bronka == 31) then
		engineImportTXD ( txd, 356 )
		engineReplaceModel ( dff, 356 ) 
		outputChatBox ( "wczytano ak47" )
	end
end
addEventHandler( "onClientPlayerWeaponSwitch", localPlayer, podmiankibronki )

 

Link to comment
function wczytaj()
	txd = engineLoadTXD ( "models/ak47.txd" )
	dff = engineLoadDFF ( "models/ak47.dff" )
	outputChatBox ( "wczytano podmianki" )
end
addEventHandler( "onClientResourceStart", getRootElement(), wczytaj )


function podmiankibronki ()
	local bronka = getPlayerWeapon ( localPlayer )
	if(getElementData(localPlayer,"currentweapon_1") == "AK47" and bronka == 30) then
		engineImportTXD ( txd, 355 )
		engineReplaceModel ( dff, 355) 
		outputChatBox ( "wczytano ak47" )
	end
end
addEventHandler( "onClientPlayerWeaponSwitch", localPlayer, podmiankibronki )

 

Edited by Dimos7
Link to comment
function wczytaj()
	txd = engineLoadTXD ( "models/ak47.txd" )
	dff = engineLoadDFF ( "models/ak47.dff" )
  --outputChatBox ( "wczytano podmianki" )
end
addEventHandler( "onClientResourceStart", resourceRoot, wczytaj )


function podmiankibronki ()
	local bronka = getPlayerWeapon ( localPlayer )
	if(getElementData(localPlayer,"currentweapon_1") == "AK47" and bronka == 31) then
		engineImportTXD ( txd, 356 )
		engineReplaceModel ( dff, 356 ) 
		outputChatBox ( "wczytano ak47" )
	end
end
addEventHandler( "onClientPlayerWeaponSwitch", localPlayer, podmiankibronki )

@IStarkI

Link to comment

@Dimos7 Model ID is 356.

@JeViCo The model is replacing correctly but it keep spamming on chat "Wczytano AK47" like the script is repeating over and over. 

When I leave the script like 

function podmiankibronki ()
	local bronka = getPlayerWeapon ( localPlayer )
	if(getElementData(localPlayer,"currentweapon_1") == "AK47" and bronka == 31) then
		--engineImportTXD ( txd, 356 )
		--engineReplaceModel ( dff, 356 ) 
		outputChatBox ( "wczytano ak47" )
	end
end
addEventHandler( "onClientPlayerWeaponSwitch", localPlayer, podmiankibronki )

everything works fine.

I really have no idea whats wrong with this and its possible that there is another script that is bugging it?

Link to comment

@IStarkI every time you switch the any weapon, model will be replaced again and again + message in chat will appear too

removed elementData

function podmiankibronki (_, slot)
	local bronka = getPlayerWeapon ( localPlayer )
	if slot == 5 and getPedWeapon(localPlayer) == 31 then -- 5 - rifle slot, 31 - m4 id (you said your weapon id is 356 and this is an M4
		engineImportTXD ( txd, 356 )
		engineReplaceModel ( dff, 356 ) 
		--outputChatBox ( "wczytano ak47" )
	end
end
addEventHandler( "onClientPlayerWeaponSwitch", localPlayer, podmiankibronki )

Are you trying to make several models per weapon or what?

Edited by JeViCo
Link to comment

@Dimos7 @JeViCo  Im trying to replace several models to m4 (ID: 31 Model: 356) so ak47 is only a name (Like I said DayZ GM so I have many weapons).

The problem is that when I switch the weapon to AK47 I receive a massive spam on chat (Many messages per second), the outputChatBox is only my way to test if it works. 

The way with the slot can work, so I'll try it when I get home and then let you know what happened.

 

Edit:

And the weapon isnt replacing. Only when i change to another weapon (for example ACR) I see the ak replace (and thats obvious because theres only AK instruction).

 

Edited by IStarkI
Link to comment
fuction replaceWeapon()
     txd = engineLoadTXD("models/ak47.txd")
     dff = engineLoadDFF("models/ak47.dff")
     engineImportTXD(txd, 356)
     engineReplaceModel(dff, 356)
end
addEventHandler("onClientResourceStart", resourceRoot, replaceWeapon)

 

Edited by Dimos7
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...