Jump to content

RP Game Mode Help/Progress topic "RPG Server (ALPHA STAGE)"


Recommended Posts

Ok, new progress on the "team script".
function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "Cops", 101, 101, 215 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, teamCops ) 
  giveWeapon ( source, 31, 10000 ) 
  giveWeapon ( source, 24, 10000 ) 
  giveWeapon ( source, 25, 10000 ) 
  giveWeapon ( source, 29, 10000 ) 
  giveWeapon ( source, 17, 10000 ) 
  giveWeapon ( source, 42, 10000 ) 
  setPlayerSkin ( source, 283 ) 
  setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
  outputChatBox( "You are now logged in as a Los Santos Police Department officer", player, 0, 255, 0 ) 
end 
addCommandHandler ( "police", assignNewTeam ) 
  
function setCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
  takeAllWeapons ( source ) 
  setPlayerSkin ( source, 0 ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addCommandHandler ( "civilian", setCivilian ) 
  
function assignCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

I will now test if my setElementPosition and the outputChatBox works :)

Hmm the outputChatBox functions works but not setElement position and btw i got ERROR Bad argument @ 'setElementPosition'

And another problem i had since i started, i first used broph's files but i deleted all of them but the map file, and started making my own, but if i don't use "freeroam" it's just black...

Link to comment
  • Replies 142
  • Created
  • Last Reply

Top Posters In This Topic

function fadeInOnStart ( ) 
  fadeCamera ( source, true, 1.0 )  
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), fadeInOnStart  ) 

will this solve the "black" problem?

And what should i do with this

function assignCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  )  -- this setElementPosition doesn't work get "bad argument" on it 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

and this

function setCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
  takeAllWeapons ( source ) 
  setPlayerSkin ( source, 0 ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) -- this setElementPosition doesn't work get "bad argument" on it too 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addCommandHandler ( "civilian", setCivilian ) 

?

Link to comment
But SQL is a bit difficult and MySQL modules were failed for me.

How come? I prefer MySQL because the SQLite implementation is too basic for my likings and XML just sucks for dynamic data management.

+1 :)

Well, the problem was that my MTA doesn't detect the modules. I would actually have agreed that MySQL would have been better! But well, if it doesn't work...

Well back on topic:

function fadeInOnStart ( ) 
  fadeCamera ( source, true, 1.0 )  
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), fadeInOnStart  ) 

will this solve the "black" problem?

Answer: No. The reason for that is that you are fading the camera of the RESOURCE. xD Source means who/what triggered an event. This means you also shouldn't add source as an argument name in function ...().

How to solve this is simple: change addEventHandler into event "onPlayerJoin" and the 2nd parameter to getRootElement().

And what should i do with this
function assignCivilian ( ) 
   setPlayerTeam ( source, teamCivilians ) 
   setElementPosition( player, 2230.8967, -1159.5858, 25.8268  )  -- this setElementPosition doesn't work get "bad argument" on it 
   outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

and this

function setCivilian ( source, commandName ) 
   setPlayerTeam ( source, teamCivilians ) 
   takeAllWeapons ( source ) 
   setPlayerSkin ( source, 0 ) 
   setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) -- this setElementPosition doesn't work get "bad argument" on it too 
   outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addCommandHandler ( "civilian", setCivilian ) 

?

These errors are easy to solve:

For the first script: Both "setElementPosition" and "outputChatBox" contain bad arguments! Which? Player should be source.

For the second one: As I stated earlier: It's NEVER an good idea to do "function ... (source...)". Source is something you should avoid making custom. (made the same mistake in the beginning ;) ) So remove all of the "source" parameters in the entire 2nd script, and replace them all with "player".

Always keep in mind: Source is used by addEventHandler as a variable that shows who/what triggered the event! ALWAYS! ;)

Link to comment

Ok, i'm one step forward on the team.lua :) it works good, no problems right now but there will be problems later on :P

function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "LSPD", 101, 101, 215 ) 
        teamArmy = createTeam ( "Army", 26, 51, 0 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function assignCopTeam ( player, commandName ) 
  setPlayerTeam ( player, teamCops ) 
  giveWeapon ( player, 31, 10000 ) 
  giveWeapon ( player, 24, 10000 ) 
  giveWeapon ( player, 25, 10000 ) 
  giveWeapon ( player, 29, 10000 ) 
  giveWeapon ( player, 17, 10000 ) 
  giveWeapon ( player, 42, 10000 ) 
  setPlayerSkin ( player, 280 ) 
  setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
  outputChatBox( "You are now logged in as a Los Santos Police Department officer", source, 0, 255, 0 ) 
  setPlayerNametagColor ( player, 101, 101, 215 ) 
end 
addCommandHandler ( "loginpolice", assignCopTeam ) 
  
function assignArmyTeam ( player, commandName ) 
  setPlayerTeam ( player, teamArmy ) 
  giveWeapon ( player, 30, 10000 ) 
  giveWeapon ( player, 22, 10000 ) 
  giveWeapon ( player, 27, 10000 ) 
  giveWeapon ( player, 32, 10000 ) 
  giveWeapon ( player, 16, 10000 ) 
  giveWeapon ( player, 44, 10000 ) 
  setPlayerSkin ( player, 287 ) 
  setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
  outputChatBox( "You are now logged in at Los Santos Army", source, 0, 255, 0 ) 
  setPlayerNametagColor ( player, 26, 51, 0 ) 
end 
addCommandHandler ( "loginarmy", assignArmyTeam ) 
  
function assignCivilian ( player, commandName ) 
  setPlayerTeam ( player, teamCivilians ) 
  takeAllWeapons ( player ) 
  setPlayerSkin ( player, 0 ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) 
  outputChatBox( "You are a civilian", source, 0, 255, 0 ) 
  setPlayerNametagColor ( player, 255, 255, 255 ) 
end 
addCommandHandler ( "civilian", assignCivilian ) 
  
function assignNewCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
  outputChatBox( "You are a civilian", source, 0, 255, 0 ) 
  spawnPlayer( source, 2230.8967, -1159.5858, 25.8268 ) 
  fadeCamera ( source, true ) 
  setPlayerNametagColor ( player, 255, 255, 255 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignNewCivilian ) 

54 lines :)

Link to comment

Triple post! Use "Edit" to edit your posts!

function fadeInOnStart ( ) 
  fadeCamera ( source, true, 1.0 )  
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), fadeInOnStart  ) 

will this solve the "black" problem?

And what should i do with this

function assignCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  )  -- this setElementPosition doesn't work get "bad argument" on it 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

and this

function setCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
  takeAllWeapons ( source ) 
  setPlayerSkin ( source, 0 ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) -- this setElementPosition doesn't work get "bad argument" on it too 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addCommandHandler ( "civilian", setCivilian ) 

?

It wouldn't fade camera for all the players when resource start. Source of onResourceStart is resource that started, so you can't fade resource's camera, it must be player. Some functions allow getRootElement() as an argument and it would do something to all the players (like, outputChatBox( "hello", getRootElement(), 200, 200, 200 ), it would output "hello" to all the players)

The most important thing is: Try to avoid naming parameters source!

If you call a function from an event, the "hidden" variable source will be passed to that function, so which source is source?

Eg.

addEventHandler( "onPlayerJoin", getRootElement( ), 
    function( ) 
        greetPlayer( ) 
    end 
) 
  
function greetPlayer( ) 
    outputChatBox( "Welcome to my server ".. getClientName( source ), source ) 
end 

As you can see, I did not pass any variables to greetPlayer function, just because it's not required if you call a function from event. Source will be the same as in the event. So it might be confusing for you and the Lua parser.

With the similar example:

addEventHandler( "onPlayerJoin", getRootElement( ), 
    function( ) 
        greetPlayer( getResourceRootElement( getThisResource( ) ) ) 
    end 
) 
  
function greetPlayer( source ) 
    outputChatBox( "Welcome to my server ".. getClientName( source ), source ) 
end 

Do you know which source is the "hidden" source (player) and resource root element? That's why I recommend naming parameters what they are, like player, vehicle, resource or something else, NOT source!

It's basically what Gamesnert said, but he didn't say (maybe he didn't know that yet), that "hidden" source is passed to a function, even if that function is not attached to the event.

Link to comment

Hmm i got one problem because when someone joins the server everyone gets a "You are a civilian message" i could just delete it i don't think it's so important anyway xD

That has to be because i have when a player joins the message sends to a player and i haven't specified which player it should go to so it sends to all players :P

Link to comment
Ok, i'm one step forward on the team.lua :) it works good, no problems right now but there will be problems later on :P
function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "LSPD", 101, 101, 215 ) 
        teamArmy = createTeam ( "Army", 26, 51, 0 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function assignCopTeam ( player, commandName ) 
  setPlayerTeam ( player, teamCops ) 
  giveWeapon ( player, 31, 10000 ) 
  giveWeapon ( player, 24, 10000 ) 
  giveWeapon ( player, 25, 10000 ) 
  giveWeapon ( player, 29, 10000 ) 
  giveWeapon ( player, 17, 10000 ) 
  giveWeapon ( player, 42, 10000 ) 
  setPlayerSkin ( player, 280 ) 
  setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
  outputChatBox( "You are now logged in as a Los Santos Police Department officer", source, 0, 255, 0 ) 
  setPlayerNametagColor ( player, 101, 101, 215 ) 
end 
addCommandHandler ( "loginpolice", assignCopTeam ) 
  
function assignArmyTeam ( player, commandName ) 
  setPlayerTeam ( player, teamArmy ) 
  giveWeapon ( player, 30, 10000 ) 
  giveWeapon ( player, 22, 10000 ) 
  giveWeapon ( player, 27, 10000 ) 
  giveWeapon ( player, 32, 10000 ) 
  giveWeapon ( player, 16, 10000 ) 
  giveWeapon ( player, 44, 10000 ) 
  setPlayerSkin ( player, 287 ) 
  setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
  outputChatBox( "You are now logged in at Los Santos Army", source, 0, 255, 0 ) 
  setPlayerNametagColor ( player, 26, 51, 0 ) 
end 
addCommandHandler ( "loginarmy", assignArmyTeam ) 
  
function assignCivilian ( player, commandName ) 
  setPlayerTeam ( player, teamCivilians ) 
  takeAllWeapons ( player ) 
  setPlayerSkin ( player, 0 ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) 
  outputChatBox( "You are a civilian", source, 0, 255, 0 ) 
  setPlayerNametagColor ( player, 255, 255, 255 ) 
end 
addCommandHandler ( "civilian", assignCivilian ) 
  
function assignNewCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
  outputChatBox( "You are a civilian", source, 0, 255, 0 ) 
  spawnPlayer( source, 2230.8967, -1159.5858, 25.8268 ) 
  fadeCamera ( source, true ) 
  setPlayerNametagColor ( player, 255, 255, 255 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignNewCivilian ) 

54 lines :)

56 you mean? xD And still 56 is nothing. I have a small mission script of over 84 lines which isn't done yet, and another of 83 (coincidence? xD) which is. :P

And I didn't remember why source didn't work. So I didn't tell him, no. ^^

And to avoid this, I already edited a small part of the introduction for further explanation. (didn't delete anything, only add a few things) So anyone new shouldn't do this, or they proof they didn't read well. ^^

New message in the meantime, so I'll answer immediately:

Well, if you look at your joincode, I'm not surprised. Or do you mean something else?

EDIT: Forgot my even bigger missions, 128 client-side, 125 server-side... ^^

Link to comment

Yea, 60 lines of script code are peanuts. Most game modes have at least 2000 lines (one of my scripts has 8000+). But you shouldn't focus at the amount of lines but make sure your code is efficient. Having the most lines of code doesn't have to mean jack shit. Sometimes the only thing it proves is that you can't write efficient code.

Well, the problem was that my MTA doesn't detect the modules. I would actually have agreed that MySQL would have been better! But well, if it doesn't work...

May I ask how exactly did you try to load the modules? I know that in my case adding a line to my server configuration like this "mta_mysql.dll" failed to load the module. I had to use this "" instead.

Link to comment

setTimer is usable in several ways:

Normal way:

setTimer(,,,)

Scripting command way:

setTimer(setElementPosition,,,player,0,0,3)

Alternate way:

setTimer(function() end,,)

And Ace: I did do that, the module also is added, everything like explained, but just doesn't detect it.

EDIT: Event "onPlayerWasted", works exactly like "onPlayerJoin". Except for a few optional parameters you should ignore. Try it with this info ;)

EDIT2: * added. *=in miliseconds (30 minutes = 60000*30 miliseconds = 1800000 miliseconds. ;) )

Link to comment
setTimer is usable in several ways:

Normal way:

setTimer(,,,)

Scripting command way:

setTimer(setElementPosition,,,player,0,0,3)

Alternate way:

setTimer(function() end,,)

And Ace: I did do that, the module also is added, everything like explained, but just doesn't detect it.

EDIT: Event "onPlayerWasted", works exactly like "onPlayerJoin". Except for a few optional parameters you should ignore. Try it with this info ;)

EDIT2: * added. *=in miliseconds (30 minutes = 60000*30 miliseconds = 1800000 miliseconds. ;) )

Thx very much man, I thought would have to script all day for onPlayerWasted because of the weird args, and setTimer i read on that a little bit more and understood what i should do :P, the timeconverting was made on this http://www.csgnetwork.com/timemath.html xD

Link to comment

Just some small pieces then. But do learn it yourself eh? :P

function iDontKnowWhatKindOfFunctionNameYouWantSoLolIllMakeAVeryShortFunctionNameCuzYouDeserveItDoYouSee() 
    if getPlayerTeam(source)==teamCops then 
        giveWeapon(source,31,10000) 
  
        ... 
end 
addEventHandler("onPlayerWasted",getRootElement(),iDontKnowWhatKindOfFunctionNameYouWantSoLolIllMakeAVeryShortFunctionNameCuzYouDeserveItDoYouSee) 

You know how to continue on your own. ;) I know!

Link to comment

and when you've done all this, you'll probably want to refactor your code a little into functions that do a specific thing and reduces duplicate code, e.g. in the example above, you might change it to something like:

  
function iDontKnowWhatKindOfFunctionNameYouWantSoLolIllMakeAVeryShortFunctionNameCuzYouDeserveItDoYouSee() 
     giveWeaponsToPlayer(source, getPlayerTeam(source)) 
end 
  
function giveWeaponsToPlayer(thePlayer, theTeam) 
     if (theTeam == teamCops) then  
          giveWeapon ( thePlayer, 31, 10000 ) 
          giveWeapon ( thePlayer, 24, 10000 ) 
          giveWeapon ( thePlayer, 25, 10000 ) 
          giveWeapon ( thePlayer, 29, 10000 ) 
          giveWeapon ( thePlayer, 17, 10000 ) 
          giveWeapon ( thePlayer, 42, 10000 ) 
    -- add more if statements here to handle the various teams 
     end 
end 
  
addEventHandler("onPlayerWasted",getRootElement(),iDontKnowWhatKindOfFunctionNameYouWantSoLolIllMakeAVeryShortFunctionNameCuzYouDeserveItDoYouSee) 
  

which would mean in your original function "assignCopTeam", you could also do this:

  
function assignCopTeam ( player, commandName ) 
   setPlayerTeam ( player, teamCops ) 
   giveWeaponsToPlayer(player, teamCops) 
   setPlayerSkin ( player, 280 ) 
   setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
   outputChatBox( "You are now logged in as a Los Santos Police Department officer", source, 0, 255, 0 ) 
   setPlayerNametagColor ( player, 101, 101, 215 ) 
end 
  

Much neater, isn't it? :)

Hopefully you get the idea of why re-factoring your code is a good thing :)

Link to comment
Well it's better yes. What's even better is storing a factions weapons in a table and read it out instead of giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon,giveWeapon! xD

one step at a time, eh? he's only just getting into scripting :D

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