Michael_Sund Posted August 10, 2008 Share Posted August 10, 2008 (edited) I will try making a gamemode, i will post all stuff i got problem with and tell you what i have done. Edited August 31, 2008 by Guest Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 (edited) function createTeamsOnStart () teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) teamCops = createTeam ( "Cops", 101, 101, 215 ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart ) --we attach the function to this resource's root element function assignNewTeam ( source, commandName ) setPlayerTeam ( source, Cops ) end addCommandHandler ( "command", assignNewTeam ) Ok here is the current team script, the "createTeamsOnStart" works but not the "assignNewTeam" why? Ok, i changed setPlayerTeam ( source, Cops ) to setPlayerTeam ( source, teamCops ) Now it works! Edited August 10, 2008 by Guest Link to comment
churchill Posted August 10, 2008 Share Posted August 10, 2008 Ok here is the current team script, the "createTeamsOnStart" works but not the "assignNewTeam" why? plz help! should be: function assignNewTeam ( source, commandName ) setPlayerTeam ( source, teamCops) -- the team "Cops" doesn't exist according to your code, teamCops does, however. end addCommandHandler ( "command", assignNewTeam ) -- if "command" is what you type in the console, in order to activate the function, shouldn't the word be more be something more descriptive such as "assignToCops" ? Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 Ok here is the current team script, the "createTeamsOnStart" works but not the "assignNewTeam" why? plz help! should be: function assignNewTeam ( source, commandName ) setPlayerTeam ( source, teamCops) -- the team "Cops" doesn't exist according to your code, teamCops does, however. end addCommandHandler ( "command", assignNewTeam ) -- if "command" is what you type in the console, in order to activate the function, shouldn't the word be more be something more descriptive such as "assignToCops" ? LOL i just did that without seeing your post, i just guessed i'm so happy my first 10 lines of lua works :') Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 Ok, heres is an update of the team script... function createTeamsOnStart () teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) teamCops = createTeam ( "Cops", 101, 101, 215 ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart ) --we attach the function to this resource's root element function assignNewTeam ( source, commandName ) setPlayerTeam ( source, teamCops ) end addCommandHandler ( "command", assignNewTeam ) function assignCivilian ( source, commandName ) setPlayerTeam ( source, teamCivilians ) end addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) function setCivilian ( source, commandName ) setPlayerTeam ( source, teamCivilians ) end addCommandHandler ( "civilian", setCivilian ) Everything but function assignCivilian ( source, commandName ) setPlayerTeam ( source, teamCivilians ) end addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) works, i want to make it so when a player joins it puts him in teamCivilian. Can you find the errors? Link to comment
Gamesnert Posted August 10, 2008 Share Posted August 10, 2008 I think so: function assignCivilian ( source, commandName ) setPlayerTeam ( source, teamCivilians ) end addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) source==nil. Why? OnPlayerJoin has NO PARAMETERS! Still, you did list source, commandName. But they'll just be nil. (for as far as I know...) Solution? Remove source,commandName in line 1. Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 I think so: function assignCivilian ( source, commandName ) setPlayerTeam ( source, teamCivilians ) end addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) source==nil. Why? OnPlayerJoin has NO PARAMETERS! Still, you did list source, commandName. But they'll just be nil. (for as far as I know...) Solution? Remove source,commandName in line 1. Ok, it works but i still get a warning but that's not important Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 (edited) Ok, this is my current job on the 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 ) end addCommandHandler ( "secret", assignNewTeam ) function setCivilian ( source, commandName ) setPlayerTeam ( source, teamCivilians ) takeAllWeapons ( source ) setPlayerSkin ( source, 0 ) end addCommandHandler ( "civilian", setCivilian ) function assignCivilian ( ) setPlayerTeam ( source, teamCivilians ) end addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) It works perfectly Edited August 10, 2008 by Guest Link to comment
Gamesnert Posted August 10, 2008 Share Posted August 10, 2008 Good! Work some more on it and you can post it in the resources list. You might want to learn how XML and tables work if you make them public: XML: HERE Tables: HERE and HERE If you want to keep it for yourself, I still recommend you look at them. (especially tables!) Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 Good! Work some more on it and you can post it in the resources list. You might want to learn how XML and tables work if you make them public: XML: HERE Tables: HERE and HERE If you want to keep it for yourself, I still recommend you look at them. (especially tables!) Thanks, but i'm only 13 years old and haven't really understood what to use those tables for that xml maybe is good tho... Link to comment
Gamesnert Posted August 10, 2008 Share Posted August 10, 2008 13 years old is no excuse. I'm really only a year older! ^^ Anyway, tables are like variables, but they can store more at a time. It's handy to use tables because you can make tables on top of your script, allowing users to edit it easily when you put it in the resources list. Or, you can do something like table destroyedVehicles, and that if you do destroyedVehicles[aVehicleElement], it'll check if it's present. If it is, it's destroyed. If it isn't, well guess. ^^ Tables aren't necessary in the beginning. But later on, you'll see the importance of knowing how to use them. That's why I recommend you to already learn XML and tables, so you don't have to right when you need them. EDIT: I just edited the xmlNodeGetValue and xmlNodeSetValue pages, so they might be a little different seen the documentation. But otherwise you looked at a lot of "blah"... ^^ Link to comment
Michael_Sund Posted August 10, 2008 Author Share Posted August 10, 2008 13 years old is no excuse. I'm really only a year older! ^^ C00L! Can you help me making a /savepos command? I tried to but the best i could was function savePosition ( source, commandName ) local playerPos = getElementPosition ( player ) local hFile = fileOpen("savedpositions.txt", false) if hFile then fileWrite(hFile, "Coordinates: " .. playerPos ) fileClose(hFile) end addCommandHandler ( "savepos", savePosition ) function makePositionFile ( source, commandName ) local newFile = fileCreate("savedpositions.txt") if newFile then fileClose(newFile) end addCommandHandler ( "makeposfile", makePositionFile ) but i think something is wrong in there Well g2g and sleep now, but i'll check your answer tomorrow (If you answered! 666 ) Link to comment
50p Posted August 10, 2008 Share Posted August 10, 2008 You can take a look at this resource: https://community.multitheftauto.com/index.php?p= ... ils&id=124 Or search this forum (I'm sure there was a script with command to save coords for vehicles too). Link to comment
Gamesnert Posted August 10, 2008 Share Posted August 10, 2008 13 years old is no excuse. I'm really only a year older! ^^ C00L! Can you help me making a /savepos command? I tried to but the best i could was function savePosition ( source, commandName ) local playerPos = getElementPosition ( player ) local hFile = fileOpen("savedpositions.txt", false) if hFile then fileWrite(hFile, "Coordinates: " .. playerPos ) fileClose(hFile) end addCommandHandler ( "savepos", savePosition ) function makePositionFile ( source, commandName ) local newFile = fileCreate("savedpositions.txt") if newFile then fileClose(newFile) end addCommandHandler ( "makeposfile", makePositionFile ) but i think something is wrong in there Well g2g and sleep now, but i'll check your answer tomorrow (If you answered! 666 ) I would really recommend XML or (My)SQL for this. But SQL is a bit difficult and MySQL modules were failed for me. So I recommend XML instead of .txt's. So it should be something like: (have a good look at the lines with -- ! and compare with your script) function savePosition(player) -- ! local x,y,z=getElementPosition(player) local xmlFile=xmlLoadFile("savedpositions.xml") or false if xmlFile==false then -- ! xmlFile=xmlCreateFile("savedpositions.xml","positions") xmlFile=xmlLoadFile("savedpositions.xml") or false end if xmlFile then local playerNode=xmlFindSubNode(xmlFile,getClientName(player),0) or false -- ! if not playerNode then playerNode=xmlCreateSubNode(xmlFile,getClientName(player)) playerNode=xmlFindSubNode(xmlFile,getClientName(player),0) or false -- ! end if playerNode then local success=xmlNodeSetAttribute(playerNode,"x",x) -- ! xmlNodeSetAttribute(playerNode,"y",y) xmlNodeSetAttribute(playerNode,"z",z) if success then outputChatBox("Position saved!",player,0,255,0) -- ! end end end end Now it's the best that you read both the wiki and the script I gave you (untested!) to make a load version. A little note: you might see: "or false" sometimes. Don't think: "Huh?", because this has a reason. If it does not succeed, I never like errors. I usually set up my own errors. ^^ Didn't do it now, (almost bedtime for me too) but I can add it later on. If you still want to see if there are error messages in the meantime, remove "or false". P.S. 50P was first You might want to try his code aswell since he's a more talented and experienced scripter than I am. EDIT: By the way, didn't he mean saving positions of players..? Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 Ok thx, i will put that on my server and test in about 2 hours! i really needed that Link to comment
Ace_Gambit 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. Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 EDIT: By the way, didn't he mean saving positions of players..? I wanted to save the position of a player so i can use it to put cars and stuff there, because i haven't heard of a /save command as in SA-MP Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 You can take a look at this resource:https://community.multitheftauto.com/index.php?p= ... ils&id=124 Or search this forum (I'm sure there was a script with command to save coords for vehicles too). Oh, i missed this reply, sorry then i'll just downlooad that to save time, Gamesnert thx anyway Thanks 50p too =) Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 50p! can you help me? I did "//" with your saveposition script enabled, it said position saved but nothing was in the file when i checked Link to comment
haybail Posted August 11, 2008 Share Posted August 11, 2008 you could what I do, and copy paste out of the console. function getPos ( thePlayer ) local x,y,z = getElementPosition ( thePlayer ) outputChatBox ( x .. ", " .. y .. ", " .. z ) end addCommandHandler ( "position", getPos ) Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 you could what I do, and copy paste out of the console. function getPos ( thePlayer ) local x,y,z = getElementPosition ( thePlayer ) outputChatBox ( x .. ", " .. y .. ", " .. z ) end addCommandHandler ( "position", getPos ) but i wanna save the position instead so i can look on it later Link to comment
haybail Posted August 11, 2008 Share Posted August 11, 2008 haha ok. maybe outputServerLog ( string text ) Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 50p! can you help me? I did "//" with your saveposition script enabled, it said position saved but nothing was in the file when i checked Oh, 50p i did wrong i check the saved_coords.txt in the resource folder i should have looked in the one in resourcecache my bad Link to comment
Michael_Sund Posted August 11, 2008 Author Share Posted August 11, 2008 haha ok.maybe outputServerLog ( string text ) nah i fixed the problem look at the newest quote i did before this Link to comment
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 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