Jump to content

[HELP] Check if map has custom vehicle model in it.


koragg

Recommended Posts

I've seen it been done at one server but even though it's resoures are open-source I found it hard to make it work. Basically I'm looking for a way to see if the currently played map has a custom vehicle model into it. I need this check because I want to disable custom paintjobs/vehicle lights if the player's current vehicle is a modded one (with txd and dff files). Also if the map starts with the modded vehicle but then switches to a normal gtasa vehicle I need paintjobs/lights to work normally. So I'm looking for a way to keep checking if the vehicle is a modded one or not and I'll make it with a setTimer of 50ms. Hope you can help. Merry Christmas to everyone btw :)

Edited by koragg
Link to comment
  • Moderators

How about starting with the map meta.xml itself?

 

https://wiki.multitheftauto.com/wiki/Resource:Mapmanager

onGamemodeMapStart

 

function loadMap(startedMap)

https://wiki.multitheftauto.com/wiki/GetResourceName

https://wiki.multitheftauto.com/wiki/XmlLoadFile

https://wiki.multitheftauto.com/wiki/XmlNodeGetChildren

https://wiki.multitheftauto.com/wiki/XmlNodeGetName

Node name: file

Attribute: src

 

And check for extensions.

 

 

 

 

Link to comment
2 hours ago, IIYAMA said:

How about starting with the map meta.xml itself?

 

https://wiki.multitheftauto.com/wiki/Resource:Mapmanager


 
  1.  
  1.  
  1. onGamemodeMapStart

 


 
  1.  
  1.  
  1. function loadMap(startedMap)

https://wiki.multitheftauto.com/wiki/GetResourceName

https://wiki.multitheftauto.com/wiki/XmlLoadFile

https://wiki.multitheftauto.com/wiki/XmlNodeGetChildren

https://wiki.multitheftauto.com/wiki/XmlNodeGetName

Node name: file

Attribute: src

 

And check for extensions.

 

 

 

 

Not sure how to check for extentions but also what if the vehicle changes from a pickup or on checkpoint hit? Let's say map starts with a modded Sultan, then there is a pickup or checkpoint and it changes to a not modded Infernus, can I somehow know at any point during the race if the current vehicle is a mod or not?

Edited by koragg
Link to comment
  • Moderators

Option 1.

You will have to inject wrapper code in to the map. The meta can identify if it needs the injection yes and no. This could be applied directly after the gamemode has started and before the gamemode map has been loaded.

 

 


 

(Option 2)

Maybe it helps, maybe it doesn't. (not sure if there are changes in this, when different textures are applied. It might also only return the replacement names, not sure.) I have never used it before.

https://wiki.multitheftauto.com/wiki/EngineGetModelTextureNames

 

 

 

Link to comment

If you used MGM, (custom downloader)
You could detect this in the map loader with enough experience.
Another method would be modding the original infernus.DFF and adding a tag component, for example: (IsModded)
Use a script to retrieve all vehicle components, and if the component doesn't exist, it didn't load your tagged model.
But depending on what you need this script to do, it would maybe require tagging all vehicle DFF, not only the infernus, which would be a rather large download.

Quote

onClientRender

Clientside event

This event is triggered every time GTA renders a new frame. It is required for the DirectX drawing functions, and also useful for other clientside operations that have to be applied repeatedly with very short time differences between them.

You could use OnClientRender to constantly check.
https://wiki.multitheftauto.com/wiki/SetVehicleComponentVisible

Edited by Justin|X5|
Link to comment

Sorry for the double post it won't let me edit anymore.

Another way you could pull this off would be to modify .DFF and .TXD for which ever cars you're allowing a custom paint job.
(I'm assuming only the Infernus will have custom paintjobs because all other vehicles have bad UV mapping, and to fix the UV mapping for all vehicles would be a giant download)
So long story short, what I'm saying is just change the texture name from vehiclegrunge256, to something like koragmap instead.
So if ANY other vehicle is loaded instead of your custom paint job models, the texture name won't be the same, therefor it won't apply the paint job.
I actually did this in my server earlier this year, even with the tail lights, I just forgotxD

Another way get a true/false return, you could even use @IIYAMA's method, and if your custom koragmap texture doesn't exist, your tagged model isn't loaded.
You need some experience in zModeler though to change the texture name from vehiclegrunge256 to koragmap, it's not hard, add me to Skype I'll do it for you.
[email protected]

Edited by Justin|X5|
It auto corrected my naughty language xD
Link to comment

This became way too hard xD Well my paintjobs script works on all vehicles, literally all so editing the dff would be a huge download and i have no Idea how to do this since I've never used zModeler before. I guess I'll just detect if there are .txd and .dff files in the map's folder when a map starts (as @IIYAMA suggested). I can live with no paintjob on default cars if there is a modded one in the map. It's not like there are a lot of maps with custom vehicles which actually contain a switch to another non-modded one. :)

 

Edit: line 435 here does that for another server but i still need to figure it out - https://github.com/JarnoVgr/Mr.Green-MTA-Resources/blob/master/resources/[gameplay]/gcshop/modshop/modshop_s.lua

Edited by koragg
Link to comment

Fixed!! With below code:

addEvent("onMapStarting", true)
function onMapStarting()
	canUsePJsAndLights = true
	setElementData(resourceRoot, "canUsePJsAndLights", true)
	for k, s in pairs(getElementsByType("spawnpoint")) do 
		if getElementData(s, "upgrades") or getElementData(s, "paintjob") then
			canUsePJsAndLights = false
			setElementData(resourceRoot, "canUsePJsAndLights", false)
		end
	end
	for k, s in pairs(getElementsByType("checkpoint")) do 
		if getElementData(s, "upgrades") or getElementData(s, "paintjob") then
			canUsePJsAndLights = false
			setElementData(resourceRoot, "canUsePJsAndLights", false)
		end
	end
	for k, s in pairs(getElementsByType("pickup")) do 
		if getElementData(s, "upgrades") or getElementData(s, "paintjob") then
			canUsePJsAndLights = false
			setElementData(resourceRoot, "canUsePJsAndLights", false)
		end
	end
	if canUsePJsAndLights == false then
		local customLightsRes = getResourceFromName("cr_vehiclelights")
		if customLightsRes then
			if getResourceState(customLightsRes) == "running" then
				return
			end
		end
		setTimer(outputChatBox, 1500, 1, "This map has it's own custom upgrades, paintjobs and vehicle lights are disabled!")
	end
end
addEventHandler("onMapStarting", root, onMapStarting)

And whenever I don't want paintjobs (and vehicle lights) to load I just use

if canUsePJsAndLights == false then
  return
end

And for client-side I use the resource's element data which I've set above^.

The problem before was that I didn't know from where that "upgrades" and "paintjob" element data came for checkpoints, spawnpoints and pickups but now I found out that it's there by default in MTA. This made my work super easy :) Thanks for all the help guys.

  • Like 2
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...