Jump to content

Map Editor can define how much elements in certain gamemode?


DarkLink

Recommended Posts

My question is:

Does map editor can define how much vehicles is possible to put according to the gamemode?

Example:

On my gamemode named "X"

i want to be only possible 4 cars ! so map editor user can only put 4 cars on that map of gamemode X.

did u guys understand?

If map editor user try to put the 5th car map editor says: "gamemode doesnt permit more than 4 cars".

Is it possible?

thanks

Link to comment
  
addEvent("onClientElementCreate",true) 
addEventHandler("onClientElementCreate", root, function() 
  if getElementType(source) == "vehicle" then 
          local vehicles = getElementsByType(vehicle) 
          if table.getn(vehicles) > 4 then 
                     exports.editor_main:destroySelectedElement() -- client only function 
                     outputChatBox("gamemode doesnt permit more than 4 cars") 
           end 
   end       
end) 

not tested, but should work

save it in a file called edf.lua, and add

to your resource edf file

Link to comment

didnt had time yet to test ur code wojak, but I will.

thanks.

Support for this could be added to EDF, if someone wanted to do it...

that would be awesome eAi !! I would be very good function.

So I could use my gamemode better :D

If you guys could do it, I would be grateful

Thanks.

Link to comment
  • 1 month later...

Hey wojak I tryed what you said but doesnt work, tryed with my custom elements that are passage elements. doing this:

  
addEvent("onClientElementCreate",true) 
addEventHandler("onClientElementCreate", root, function() 
  if getElementType(source) == "passage" then 
          local passages = getElementsByType(passage) 
          if table.getn(passages) > 4 then 
                     exports.editor_main:destroySelectedElement() -- client only function 
                     outputChatBox("gamemode doesnt permit more than 4 cars") 
           end 
   end       
end) 
  

But doesnt say nothing, and I can have the element on map editor, its not destroyed.

I add this on my borderpatrol.edf file:

Maybe because you made an event but we are not triggering it ? Its just a client side event, dont u need a triggerClientEvent?

Thanks in advance bro.

Cya.

Link to comment

this is a working script, and a exemple how to debug scripts ;)

local passages = getElementsByType("passage") 
 local npasages = table.getn(passages) 
addEvent("onClientElementCreate",true) 
addEventHandler("onClientElementCreate", root, function() 
  outputChatBox("create: "..tostring(getElementType(source))) 
  if getElementType(source) == "passage" then 
          npasages = npasages + 1 
          outputChatBox(npasages) 
          if npasages > 4 then 
                setTimer(function() 
                    exports.editor_main:destroySelectedElement() 
                 end,100,1) 
                outputChatBox("gamemode doesnt permit more than 4 teleports") 
           end 
   end       
end) 
addEvent("onClientElementDestroyed",true) 
addEventHandler("onClientElementDestroyed", root, function() 
    outputChatBox("destroy: "..tostring(getElementType(source))) 
    if getElementType(source) == "passage" then 
        npasages = npasages - 1 
        outputChatBox(npasages) 
    end 
end) 

note that there still may be a problem when you statr a new map... the table npasages should be reseted when the new map starts but "onNewMap" and "onMapOpened" are server only events (but you may trigger a clientside event from the server)

edit:

btw - you may use events triggered by other resources in youre script, you just need to know if a resource trigger something and what is the name of the event ;)

Link to comment

Thanks for your reply, but I still cant understand where that source cames from?

I mean there that is a custom event right? its not on the wiki. and you are not triggering it, so what will be the source?

Thanks.

Maybe I am doing things wrong? I open map editor at mtasa, then add definitions for the borderpatrol.edf which have this line

on the edf file:

So its everything okay? should it give me messages on the chatbox when I try to make more than 4 passages?

Thanks.

Link to comment
events are triggered by editor_main resouce. You may use events triggered by other resources in youre script (this is a very awesome MTA feature)

As for the script- i tested it and it works

Yes its working now! Thanks alot bro!

By the way, I understand now what you were talking about the events of which resource, that I can use on other resources !

Thats amazing!

And so I did u know about those "onNewMap" and "onMapOpen" ? Is there any documentation about editor_main resource?

I can't find it on mta wiki bro.

And one more question its not possible to put more than 4 passages right? But a mapper can cheat and go right on .map file, and add one more right? this scripts doesnt prevent from that "cheating", right?

What I must do is when I am getting those elements I only get 4 of them not more, right? its the solution?

Thanks alot in advance, you helped me alot!

Link to comment
And so I did u know about those "onNewMap" and "onMapOpen" ? Is there any documentation about editor_main resource?

I can't find it on mta wiki bro.

bad news is, that there is no documentation on the wiki, or anywhere else by that mater...

good news is that the source cod of edf and editor_main is not compiled ;)

this is the edf resource meta.xml, you may find list of exported functiond here:

http://code.google.com/p/mtasa-resource ... f/meta.xml

this is editor_main meta.xml with the list of expotred functions:

http://code.google.com/p/mtasa-resource ... n/meta.xml

you use expotred functions like this:

exports.resource:function

if you not shute how a function works, check it in the lua file...

this is a search result of "edf trigger", pages should contain all events triggered by resource edf:

http://www.google.com/codesearch#search ... -resources\.googlecode\.com

this is a search result of "editor_main trigger", pages should contain all event triggered by resource editor_main:

http://www.google.com/codesearch#search ... -resources\.googlecode\.com

exemple:

triggerClientEvent(rootElement, "onClientElementCreate", self.element) 

this is a 123 line in the editor_main/server/undoredo_action.lua

the file is serverside and the function "triggerClientEvent" is used, so the event will be accessible client side,

rootElement means: "for all clients",

"onClientElementCreate" suggests that event will be triggerd when a element is created and

self.element means that the source will be a element that was created

of course you may check the context in the source code to be shure

And one more question its not possible to put more than 4 passages right? But a mapper can cheat and go right on .map file, and add one more right? this scripts doesnt prevent from that "cheating", right?

What I must do is when I am getting those elements I only get 4 of them not more, right? its the solution?

yes mapers can cheat...

to prevent thet you may start by using this method:

viewtopic.php?p=359450#p359450

in the edf script you must check ow many teleports there are (on edf load and on map load)

if more then 4 you should decrease the number of teleprts by 4 an use the loop break method to destroy aditional teleports...

Link to comment

Ye thanks alot bro, I forgot about those pages on google !

I will read it after when I have some time, thanks!

And yes Jacob teach me how to do it :P

I can prevent map cheating ^^

And I will make those verifications on edf file, I need onMapOpen, onNewMap and .. what is the one for load edf? onLoadEdf ?

Thanks alot mate!

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