Jump to content

gamemode help and MTA


Recommended Posts

Ok i want to try to make a game mode for my mta server to bring more ppl to mta and stuff. I tried making a gm but it was too hard and i asked for help in irc and said my scripting was written wrong and stuff. I looked on the wikis on the tutorials and everything so i was wondering if some on can make a tutorial for a gamemode here. As this will help mta out hopefully,so if some just give advice on a gm how to make one please :idea::?

Link to comment

A free roam can be as simple as this :

1. Create a new resource folder in your MTA DM game folder (mines D:\MTA San Andreas\server\mods\deathmatch\resources)

2. Create "meta.xml" and put this in it :

  

    "Dumb Freeroam" description="Dumb Freeroam" author="TMA" type="gamemode" version="0.1" /> 
  
    "scoreboard" /> 
    "helpmanager" /> 
  
    

3. Create "dumb_server.lua" and put this in :

  
addEventHandler('onPlayerJoin',getRootElement(), 
    function() 
        joinHandler(source) 
    end 
) 
  
addEventHandler('onPlayerWasted',getRootElement(), 
    function() 
        setTimer(joinHandler,5000,1,source) 
    end 
) 
         
addEventHandler("onResourceStart",getRootElement(),  
    function(res) 
        if res == getThisResource() then 
            for _,player in pairs(getElementsByType("player")) do 
                joinHandler(player) 
            end 
        end 
    end 
) 
  
function joinHandler(player) 
    fadeCamera(player,true) 
    spawnPlayer(player,math.random(10) * 3,math.random(10) * 3,5) 
end 
  

4. Refresh / start the resource (the folder name you specified) and that's it - instant freeroam. Admittedly there's nothing in it but then there's no real feature code. What there is are the basics you need to handle :

a. onPlayerJoin() : fired when someone connects. I've just called joinHandler() to fade up their camera (so it's not black to them) and spawn them in the middle of the world.

b. onPlayerWasted() : fired when a player dies. Simply re-call the joinHandler() in 5 seconds using a timer. The delay allows the floaty camera above your dead body.

c. onResourceStart() : fired when resources start. I check it's "mine" (the res == getThisResource()) and if so, again call the joinHandler() function for each player connected. You don't even need to trap this event - I'm only doing so that when the game mode is started and people are connected, the mode does something with them. You don't need to do this - you could just leave them where they are in the world. Edit : scrap that. You DO need this function (in some fashion) for the cases where someone may be dead on mode switch - if you didn't call joinHandler() on mode start for a dead player, they'd never spawn with just the other two event handlers.

This is to show you that you don't need much to create a working game mode - what you add is up to you. You can write more code or just start using more 3rd party resources for more features.

Link to comment

OK ive already created a resource or mode as you can say,but the problem is it dont load and i think i have map file I tried doing it like that too but i couldnt get that. I used to do it almost the same way in samp a little simpler. Do you got msn or something else so i can show you? Also ill try to do this and see what happens. pm you email

Link to comment
OK ive already created a resource or mode as you can say,but the problem is it dont load and i think i have map file I tried doing it like that too but i couldnt get that. I used to do it almost the same way in samp a little simpler. Do you got msn or something else so i can show you? Also ill try to do this and see what happens. pm you email

I have to go out shortly - maybe tomorrow. If you;re OK with it, post it somewhere I can download and stick the link in this thread.

tma the element for the "onResourceStart" event has to be: getResourceRootElement (getThisResource())

if you attach the handler to the root element it will also be triggered if other resources are started

You're missing the check I make :

  
... 
if res == getThisResource() then 
... 
  

I could do it as you suggest though but I do one or two things in the mod I'm writing when/if other resources start so that's why I'm using "root".

Link to comment

I've had a look at your code and your basically missing everything to do with spawning the player i.e. putting him into the game world. I added these three functions that make your mode work :

  
function joinHandler(player) 
    fadeCamera(player,true) 
    spawnPlayer(player,0,0,5) 
end 
  
addEventHandler("onPlayerJoin", getRootElement(),  
    function() 
        joinHandler(source) 
    end 
) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
    function(res) 
        for _,p in ipairs(getElementsByType("player")) do 
            joinHandler(p) 
        end 
    end 
) 
  

So now onPlayerJoin() spawns the player and the onResourceStart() code also spawns the player for when people are connected to your server when your game mode starts. I haven't done anything fancy with where they spawn - I've just dumped them in the middle of the world (0,0,5).

Link to comment

Ok i think that right but i thought you put the spawn and other stuff like that in the .map file. and how do you make it combatible with my mode the syntax and stuff which i dont get,kind of so ill show you the map and thanks for the help tma.

Also like ive defined and put player spawn and cars skins etc... in the .map file

Link to comment

If you're map file is included correctly in the meta.xml then the spawnpoints defined in it will exist in the MTA world. You could randomly pick one and spawn the player at it's location.

Alternatively : I haven't used it, but I think the spawnmanager resource would be handy for you, especially this. Seems you can change the code from spawnPlayer() to a correct call to this resource function. It'd be something like :

  
    call(getResourceFromName("spawnmanager"),"spawnPlayerAtSpawnpoint",player) 
  

Link to comment

ok so what do you mean by that? Do i put that in my lua game mode file and also how do i add teams and add the skin or player to the team when they suppose to spawn i looked on the wiki for creating teams and spawns and i have them in my gm too. I made two teams in the lua file.

Link to comment

I mean use the three chuncks of code I said were missing and then ...

1. Include you map file in the NEW format i.e. not the old race format. I tried a test quickly using this in my meta.xml

  
    ... 
    "ojsf2" /> 
    ... 
  

You won't have that resource/map probably but anything will do.

2. Swap the line in the code above from :

  
    spawnPlayer(player,math.random(10) * 3,math.random(10) * 3,5) 
  

to

  
    call(getResourceFromName("spawnmanager"),"spawnPlayerAtSpawnpoint",player) 
  

I just tried it and it works fine. All you need to do is get your .map file into the meta and you're away.

Link to comment
Ok i guess the mode work,when i start it i spawn as cj skin in the middle of the map with an m4. So if i created a team how do i add players to it and skins guns color..etc...

heres my [email protected]

or if not come in irc :arrowup:

Dude, have you ever done something yourself? Wiki waits "with hands wide open", if this is your first programming language then I'd suggest read documentation first: http://www.lua.org/

When you don't understand anything from that (just like my first time), take a rest, eat something (prefere sweets) and come back to it, that should help since sugar raise your concentration, you'll "pull" knowledge easier.

Take a look here and then here, what do you think setPlayerTeam or setTeamColor does? Isn't it self-explained? I think so.

Link to comment
Ok i guess the mode work,when i start it i spawn as cj skin in the middle of the map with an m4. So if i created a team how do i add players to it and skins guns color..etc...

heres my [email protected]

or if not come in irc :arrowup:

Dude, have you ever done something yourself? Wiki waits "with hands wide open", if this is your first programming language then I'd suggest read documentation first: http://www.lua.org/

When you don't understand anything from that (just like my first time), take a rest, eat something (prefere sweets) and come back to it, that should help since sugar raise your concentration, you'll "pull" knowledge easier.

Take a look here and then here, what do you think setPlayerTeam or setTeamColor does? Isn't it self-explained? I think so.

Duuuudeeee i have done something my self as a matter of fact ive done the lua file. he just tellin me whats wrong in it and ye i looked at the wiki,and im still looking thru it now. I been reading on the lua website to and i asked him cuase i dont know how or what format them functions go in to. So i think you go eat some candy or sweets and chill out. Go eat a bigazz cake or something. Tma is helping me out with this im trying to understand how to make a gm. :idea:

Link to comment

Riiiight, so let me refer to this part of your post:

i asked him cuase i dont know how or what format them functions go in to

Wiki tells you that.

eg.:

bool setPlayerTeam ( player thePlayer, team theTeam )

These bold pieces are the things that you have to pass as the arguments.

player - you can get player element using handlers or other functions (eg. getPlayerFromNickname)

team - team element which is returned from createTeam or getPlayerTeam functions.

What's the first "bool"? That's what function returns.

[b]team[/b] createTeam ( string teamName, [int colorR = 255, int colorG = 255, int colorB = 255] ) 

see this team? That's what's needed in setPlayerTeam.

If you create team, assign what's returned to a variable

team1 = createTeam( "Robbers" ) 

now team1 is a team element which can be passed to setPlayerTeam function as a param.

Link to comment

Like i said ive already created two teams 50p but now i want to know how to add players,sking and stuff color etc.. when i start the mode and i press tab it shows my team but the problem is it dont assign players to the teams or color. So i added spawns like player and skin spawn in the map file and cars.

Link to comment

Hey. I think there's not much more I can help you with, without spoon-feeding you the answers - no offence. You do now have a working game mode - where you go forward is up to you. If you can program OK then read the API and just use it - the MTA team have created a very easy and flexible system and you can just expand your code.

Link to comment
Hey. I think there's not much more I can help you with, without spoon-feeding you the answers - no offence. You do now have a working game mode - where you go forward is up to you. If you can program OK then read the API and just use it - the MTA team have created a very easy and flexible system and you can just expand your code.

lol I shouldnt even have tried.Nvm just forget it. i wont get the scripting

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