Jump to content

EDF :S


12p

Recommended Posts

Well, I'm doing a public script (again :P) and I want to make a editor "extension". The objetive is to create specific elements from the editor. In this case, locked vehicles and PEDs.

MTA Map Editor recognizes my EDF, and creates elements when using it. But when I try to test it (F5), no elements are created in the map :(

Well, this is my LUA coding:

addEvent ("onGamemodeMapStart",true) 
  
addEventHandler ("onGamemodeMapStart",getRootElement(), 
function () 
local thePeds = getElementsByType ("custom_ped") 
local lockedCars = getElementsByType ("locked_vehicle") 
  
for i,thePed in ipairs (thePeds) do 
 local skin = getElementData (thePed,"model") 
 local x,y,z = getElementPosition (thePed) 
 local r = getElementData (thePed,"rotation") 
 local animBlock = getElementData (thePed,"animBlock") 
 local anim = getElementData (thePed,"animation") 
 local int = getElementData (thePed,"rotation") 
 ped = createPed (skin,x,y,z) 
 setPedRotation (ped,r) 
 setPedAnimation (ped,animBlock,anim) 
 setElementInterior (ped,int) 
end 
  
for i,theVehicle in ipairs (lockedVehicles) do 
 local model = getElementData (theVehicle,"model") 
 local x,y,z = getElementPosition (theVehicle) 
 local rx,ry,rz = getElementData (theVehicle,"rotation") 
 vehicle = createVehicle (model,x,y,z) 
 setVehicleLocked (vehicle,true) 
 setVehicleRotation (vehicle,rx,ry,rz) 
end 
end) 

My EDF:

<def name="Extras"> 
    <element name="custom_ped" friendlyname="PED"> 
      <data name="position" type="coord3d" default="0,0,0" /> 
      <data name="skinID" type="skinID" default="49" /> 
      <data name="interior" type="integer" default="0" /> 
      <data name="animblock" type="string" default="nil" /> 
      <data name="animation" type="string" default="nil" /> 
      <ped position="!position!" model="skinID" interior="!interior!" /> 
    </element> 
    <element name="locked_vehicle" friendlyname="Locked Vehicle"> 
      <data name="position" type="coord3d" default="0,0,0" /> 
      <data name="rotation" type="coord3d" default="0,0,0" /> 
      <data name="model" type="vehicleID" default="405" /> 
      <data name="interior" type="integer" default="0" /> 
      <vehicle model="!model!" position="!position!" rotation="!rotation!" interior="!interior!" /> 
    </element> 
</def> 

EDIT: I use mapmanager events. And it is running!

Edited by Guest
Link to comment
[b] 
local thePeds = getElementsByType ("custom_ped") 
local lockedCars = getElementsByType ("locked_vehicle") 
[/b] 

there no such thing like "custom_ped" and "locked_vehicle"..

local thePeds = getElementsByType ("players") 

And for locked cars, its a bit harder..

local lockedCars = getElementsByType ("vehicle") 
for i,v in pairs ( lockedCars ) do 
if ( isVehicleLocked ( lockedCars, true ) then 
end 
end 

( this MUST be inside the code, not like the peds one.)

Enyway, look this too:

local [b]lockedCars[/b] = getElementsByType ("locked_vehicle") 
for i,theVehicle in ipairs ([b]lockedVehicles[/b]) do 

Read this:

https://wiki.multitheftauto.com/wiki/GetElementsByType =/

Link to comment

benxamix2 is right, and I think based on his edit, his code now works.

EDF is designed to make it so you can add custom element types (e.g. custom_ped) and have the editor work with them.

See https://wiki.multitheftauto.com/wiki/EDF

getElementsByType is perfectly valid to use with any element type.

As the wiki says:

"theType: The type of element you want a list of. This is the same as the tag name in the .map file, so this can be used with a custom element type if desired."

Link to comment

there no such thing like "custom_ped" and "locked_vehicle"..

 

My EDF:

 

<def name="Extras"> 
    <element name="custom_ped" friendlyname="PED"> 
      <data name="position" type="coord3d" default="0,0,0" /> 
      <data name="skinID" type="skinID" default="49" /> 
      <data name="interior" type="integer" default="0" /> 
      <data name="animblock" type="string" default="nil" /> 
      <data name="animation" type="string" default="nil" /> 
      <ped position="!position!" model="skinID" interior="!interior!" /> 
    </element> 
    <element name="locked_vehicle" friendlyname="Locked Vehicle"> 
      <data name="position" type="coord3d" default="0,0,0" /> 
      <data name="rotation" type="coord3d" default="0,0,0" /> 
      <data name="model" type="vehicleID" default="405" /> 
      <data name="interior" type="integer" default="0" /> 
      <vehicle model="!model!" position="!position!" rotation="!rotation!" interior="!interior!" /> 
    </element> 
</def> 

benxamix2 is right, and I think based on his edit, his code now works.

EDF is designed to make it so you can add custom element types (e.g. custom_ped) and have the editor work with them.

See https://wiki.multitheftauto.com/wiki/EDF

getElementsByType is perfectly valid to use with any element type.

As the wiki says:

"theType: The type of element you want a list of. This is the same as the tag name in the .map file, so this can be used with a custom element type if desired."

eAi said the same thing ;)

I see you didnt understand my code function. My objetive is to create PEDs from the editor. And create locked cars from the editor too. So anybody can use less time MAPPING them than scripting all that ;)

Link to comment

Yes, it doesn't work as I want. I want to make this like a gamemode; when a map (that has these EDF elements created) starts, the elements are created too. Think in this like race gamemode; when the map with definitions starts, its defined elements gets created

Link to comment

Sorry for the bump.

Still doesn't work. I have made some modifications I thought where was the problem but I was wrong. Even if I leave some of my custom EDF objects in the .map file of a resource, these objects doesn't get created.

CODE:

addEventHandler ("onResourceStart",getRootElement(), 
function () 
 getResourceRootElement(source) 
 local customPeds = getElementsByType ("custom_ped") 
 local lockedVehicles = getElementsByType ("locked_vehicle")  
  
 if table.getn(customPeds) > 0 then 
  for i,thePed in ipairs (customPeds) do 
   local skin = getElementData (thePed,"model") 
   local x,y,z = getElementPosition (thePed) 
   local r = getElementData (thePed,"rotation") 
   local animBlock = getElementData (thePed,"animBlock") 
   local anim = getElementData (thePed,"animation") 
   local int = getElementData (thePed,"rotation") 
   ped = createPed (skin,x,y,z) 
   setPedRotation (ped,r) 
   setPedAnimation (ped,animBlock,anim) 
   setElementInterior (ped,int) 
   setElementDimension (ped,0) 
  end 
 end  
  
 if table.getn(customPeds) > 0 then 
  for i,theVehicle in ipairs (lockedVehicles) do 
   local model = getElementData (theVehicle,"model") 
   local x,y,z = getElementPosition (theVehicle) 
   local rx,ry,rz = getElementData (theVehicle,"rotation") 
   vehicle = createVehicle (model,x,y,z) 
   setVehicleLocked (vehicle,true) 
   setVehicleRotation (vehicle,rx,ry,rz) 
   setElementDimension (vehicle,0) 
  end 
 end 
end) 

EDF:

<def name="Extras"> 
    <element name="custom_ped" friendlyname="PED"> 
      <data name="position" type="coord3d" default="0,0,0" /> 
      <data name="skinID" type="skinID" default="49" /> 
      <data name="interior" type="integer" default="0" /> 
      <data name="animblock" type="string" default="nil" /> 
      <data name="animation" type="string" default="nil" /> 
      <ped position="!position!" model="skinID" interior="!interior!" /> 
    </element> 
    <element name="locked_vehicle" friendlyname="Locked Vehicle"> 
      <data name="position" type="coord3d" default="0,0,0" /> 
      <data name="rotation" type="coord3d" default="0,0,0" /> 
      <data name="model" type="vehicleID" default="405" /> 
      <data name="interior" type="integer" default="0" /> 
      <vehicle model="!model!" position="!position!" rotation="!rotation!" interior="!interior!" /> 
    </element> 
</def> 

What is wrong? Or what must I do?

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...