Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 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
Ace_Gambit Posted August 11, 2008 Share Posted August 11, 2008 ...but if i don't use "freeroam" it's just black... You must fade the camera in. It is faded out by default. That's why your screen stays black when you start a blank game mode. http://development.mtasa.com/index.php?title=FadeCamera Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 ...but if i don't use "freeroam" it's just black... You must fade the camera in. It is faded out by default. That's why your screen stays black when you start a blank game mode. http://development.mtasa.com/index.php?title=FadeCamera LOL that sounds really retard well thanks =) Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 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
churchill Posted August 11, 2008 Share Posted August 11, 2008 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 Link to comment
Gamesnert Posted August 11, 2008 Share Posted August 11, 2008 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. 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
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 Ok, thx i did as you said, it works great now i'll add teamArmy Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 Hmm ok everything works fine the only thing that's not working is when i spawn it puts the camera up on a mountain and i have to use freeroam to spawn -.-' Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 Hmm ok everything works fine the only thing that's not working is when i spawn it puts the camera up on a mountain and i have to use freeroam to spawn -.-' oh i have to use: "spawnPlayer(source, x, y, z)" sorry Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 Ok, i'm one step forward on the team.lua it works good, no problems right now but there will be problems later on 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
50p Posted August 11, 2008 Share Posted August 11, 2008 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
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 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 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 Link to comment
Gamesnert Posted August 11, 2008 Share Posted August 11, 2008 Ok, i'm one step forward on the team.lua it works good, no problems right now but there will be problems later on 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? 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? ) which is. 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
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 LOL can you help making a payday script i want everyone to have a special amount of money after been on server in a halfhour i didn't understand how to use that setTimer EDIT: I need a to respawn the player after he's wasted, how? Plz, help me!!! Link to comment
Ace_Gambit Posted August 11, 2008 Share Posted August 11, 2008 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
Gamesnert Posted August 11, 2008 Share Posted August 11, 2008 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
Michael_Sund Posted August 12, 2008 Author Share Posted August 12, 2008 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 , the timeconverting was made on this http://www.csgnetwork.com/timemath.html Link to comment
Michael_Sund Posted August 12, 2008 Author Share Posted August 12, 2008 And Ace: I did do that, the module also is added, everything like explained, but just doesn't detect it. LOL i installed on 1 minute it works for me Link to comment
Michael_Sund Posted August 12, 2008 Author Share Posted August 12, 2008 Can i have some help to make a code for check which team a player is in and spawn the player in that team after he died and with the right weapons? LOL when i'm waiting for answer i can listen to this song: https://www.youtube.com/watch?v=H_zp4fsDrNA and this omg it's so sad, Dean in Supernatural why did he get to hell!?!? <----Sucks :@but this got me happy look at 2:16 Link to comment
Gamesnert Posted August 12, 2008 Share Posted August 12, 2008 You can make the check code yourself: Things you need to know: - Event for dieing (already gave you ) - getPlayerTeam(player) command - How to script Link to comment
Michael_Sund Posted August 12, 2008 Author Share Posted August 12, 2008 You can make the check code yourself:Things you need to know: - Event for dieing (already gave you ) - getPlayerTeam(player) command - How to script lol i know all that but i don't know how to code it anyway i need more infop can't u give me an example? Link to comment
Gamesnert Posted August 12, 2008 Share Posted August 12, 2008 Just some small pieces then. But do learn it yourself eh? 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
churchill Posted August 12, 2008 Share Posted August 12, 2008 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
Gamesnert Posted August 12, 2008 Share Posted August 12, 2008 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! Link to comment
churchill Posted August 12, 2008 Share Posted August 12, 2008 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! one step at a time, eh? he's only just getting into scripting Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now