Hutchpe Posted November 12, 2012 Share Posted November 12, 2012 Hi everyone I'm having some trouble working out what's wrong with my script. What it is supposed to do is create a marker, when a player enters it check if they are on a certain team and if they are then reload 2 resources and spawn the player at a spawn point. At the moment it is creating the marker but nothing happens when a player from either team enters it. objectivemarker = createMarker( 2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255 ) function objective(thePlayer, matchingDimensions) local team = getPlayerTeam (source) if isElementWithinMarker(thePlayer, objectivemarker) and (team == teamMexicans) then outputChatBox ( "Mexicans Have Won!" ) outputChatBox ( "Loading Next Round! Please Wait" ) setTimer ( function() local players = getElementByType ( "player" ) reloadResource "Mexihunt" reloadResource "Teamblips" spawnPlayer( players, 1544.4279785156, -1353.2464599609, 329.47442626953 ) end, 5000, 1 ) else outputChatBox ( "You aren't a Mexican" ) end end addEventHandler ( "objective", getRootElement(), objective ) I'm not getting any errors in the console with the following script. Any help is greatly appreciated. (Also sorry for my recent spate of requests for help . I'm rather new to programming and learning as quickly as I can ) Link to comment
./BlackBird# Posted November 12, 2012 Share Posted November 12, 2012 if(isElementWithinMarker(thePlayer,objectivemarker) and getTeamName(team)=="teamMexicans")then Link to comment
Hutchpe Posted November 12, 2012 Author Share Posted November 12, 2012 (edited) Thanks for the reply MJNONFIK but I'm still getting the same error as before. EDIT: And still with your modified script. Edited November 12, 2012 by Guest Link to comment
./BlackBird# Posted November 12, 2012 Share Posted November 12, 2012 humm where is 138 line? Link to comment
Hutchpe Posted November 12, 2012 Author Share Posted November 12, 2012 (edited) Line 138 has the following local team = getPlayerTeam (source) This is start of the script as it is currently function objective(thePlayer, matchingDimensions) local team = getPlayerTeam (source) if isElementWithinMarker(thePlayer, objectivemarker) and getTeamName(team) == teamMexicans then With the above script I am now getting the previous error and the below error I go into the marker WARNING: Mexihunt\script.lua:139: Bad argument @ 'getTeamName' Edited November 12, 2012 by Guest Link to comment
./BlackBird# Posted November 12, 2012 Share Posted November 12, 2012 objectivemarker = createMarker( 2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255 ) function objective(thePlayer, matchingDimensions) local team = getPlayerTeam(source) if isElementWithinMarker(thePlayer, objectivemarker) and (team == teamMexicans) then outputChatBox ( "Mexicans Have Won!" ) outputChatBox ( "Loading Next Round! Please Wait" ) setTimer ( function() local players = getElementByType ( "player" ) reloadResource "Mexihunt" reloadResource "Teamblips" spawnPlayer( players, 1544.4279785156, -1353.2464599609, 329.47442626953 ) end, 5000, 1 ) else outputChatBox ( "You aren't a Mexican" ) end end addEventHandler ( "objective", getRootElement(), objective ) Link to comment
Hutchpe Posted November 12, 2012 Author Share Posted November 12, 2012 (edited) Ok I tried your code and it is still jumping straight to the else statement and I get the following error in console WARNING: Mexihunt\script.lua:138: Bad 'player' pointer @ 'getPlayerTeam' (1) Edited November 12, 2012 by Guest Link to comment
myonlake Posted November 12, 2012 Share Posted November 12, 2012 Just got on my computer, your code was and is a mess. Try this. You need to be in the "Mexicans" team to make it work. If you don't have that team, then create it using createTeam. Server-side local objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255) addEventHandler("onMarkerHit", objectivemarker, function(hitElement, matchingDimension) if getElementType(hitElement) == "player" and matchingDimension then if getPlayerTeam(hitElement) == "Mexicans" then outputChatBox("Mexicans have won!", root, 0, 255, 0, false) outputChatBox("Loading next round! Please wait...", root, 255, 180, 0, false) setTimer(function() for i,v in ipairs(getElementsByType("player")) do restartResource(getResourceFromName("Mexihunt")) restartResource(getResourceFromName("Teamblips")) spawnPlayer(v, 1544.4279785156, -1353.2464599609, 329.47442626953) end end, 5000, 1) else outputChatBox("You aren't in the Mexicans team.", hitElement, 255, 0, 0, false) end end end ) Link to comment
./BlackBird# Posted November 12, 2012 Share Posted November 12, 2012 try this p: for i,player in ipairs(getElementsByType("player")) do if(getTeamName(getPlayerName(player)=="Mexicans")then local objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255,player) end end addEventHandler("onMarkerHit", objectivemarker, function(hitElement, matchingDimension) if getElementType(hitElement) == "player" and matchingDimension then outputChatBox("Mexicans have won!", root, 0, 255, 0, false) outputChatBox("Loading next round! Please wait...", root, 255, 180, 0, false) setTimer(function() for i,v in ipairs(getElementsByType("player")) do restartResource(getResourceFromName("Mexihunt")) restartResource(getResourceFromName("Teamblips")) spawnPlayer(v, 1544.4279785156, -1353.2464599609, 329.47442626953) end end, 5000, 1) end end end ) Link to comment
myonlake Posted November 12, 2012 Share Posted November 12, 2012 (edited) try this p: for i,player in ipairs(getElementsByType("player")) do if(getTeamName(getPlayerName(player)=="Mexicans")then local objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255,player) end end Wrong a little. And it updates rarely so new players can't see the marker. addEventHandler("onPlayerSpawn", root, function() if getPlayerTeam(source) and getTeamName(getPlayerTeam(source)) == "Mexicans" then objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255, source) end end ) addEventHandler("onMarkerHit", objectivemarker, function(hitElement, matchingDimension) if getElementType(hitElement) == "player" and matchingDimension then outputChatBox("Mexicans have won!", root, 0, 255, 0, false) outputChatBox("Loading next round! Please wait...", root, 255, 180, 0, false) setTimer(function() for i,v in ipairs(getElementsByType("player")) do restartResource(getResourceFromName("Mexihunt")) restartResource(getResourceFromName("Teamblips")) spawnPlayer(v, 1544.4279785156, -1353.2464599609, 329.47442626953) end end, 5000, 1) end end ) Edited November 12, 2012 by Guest Link to comment
Hutchpe Posted November 12, 2012 Author Share Posted November 12, 2012 Thankyou so much myonlake and MJNONFIK and sorry that my code was such a mess . Anyway I have tried both your scripts. myonlake yours says that I'm not on the Mexican team even though I am. MJNONFIK yours gives me the following errors in the console when I start the resource. Quote SCRIPT ERROR: Mexihunt\script.Lua:138: ')' expected near 'then' Quote WARNING: Loading script failed: Mexihunt\script.Lua:138: ')' expected near 'then' Link to comment
myonlake Posted November 12, 2012 Share Posted November 12, 2012 I suggest not using his code since it is bugged, my code should be working correctly if you are set in "Mexicans" team via setPlayerTeam function. It won'y work if the name of the team is not "Mexicans". No problem though. Link to comment
Hutchpe Posted November 12, 2012 Author Share Posted November 12, 2012 The team name is Mexicans so I'm not sure why it isn't working. Below is the code I have to create the teams and then for the player to join the teams. function createTeamsOnStart () createBlip ( 2491.2993164063, -1665.7626953125, 13.34375, 3 ) --snuck this in here BorderControl = createTeam ( "Border Control", 0, 0, 255 ) Mexicans = createTeam ( "Mexicans", 255, 0, 0 ) end addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) addCommandHandler("joinmexicans", function(thePlayer, commandName) spawnPlayer(thePlayer, 364.96685791016, 2507.6645507813,16.496768951416, 0,173,0,0,Mexicans) outputChatBox("You are a Mexican.",thePlayer) end ) addCommandHandler("joinbordercontrol", function(thePlayer, commandName) spawnPlayer(thePlayer, -1602.9626464844,660.72479248047,7.1875, 0,71,0,0,BorderControl) outputChatBox("You are the Border Control.",thePlayer) end ) Is there anything wrong with the code I have here that would be causing your script not to work? Link to comment
myonlake Posted November 12, 2012 Share Posted November 12, 2012 You don't necessarily need that event. Try this. createBlip(2491.2993164063, -1665.7626953125, 13.34375, 3) BorderControl = createTeam("Border Control", 0, 0, 255) Mexicans = createTeam("Mexicans", 255, 0, 0) Link to comment
Guest Guest4401 Posted November 12, 2012 Share Posted November 12, 2012 It will never work Should be: if getTeamName(getPlayerTeam(hitElement)) == "Mexicans" then Link to comment
myonlake Posted November 12, 2012 Share Posted November 12, 2012 It will never workShould be: if getTeamName(getPlayerTeam(hitElement)) == "Mexicans" then viewtopic.php?f=91&t=50113#p490260 Already fixed there. Link to comment
Hutchpe Posted November 13, 2012 Author Share Posted November 13, 2012 Everything is working great now! Thank you so much myonlake and eveyone else who helped me out here. 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