myonlake Posted December 12, 2011 Share Posted December 12, 2011 (edited) Hello everyone, I am attempting to make a code that moves all vehicles and players away from the marker when I have executed the command. If you know what "Fus Ro Dah" means, you should know what I am trying to catch here. Server function fusRoDah(player, cmd) if hasObjectPermissionTo(player, "function.banPlayer") then local px, py, pz = getElementPosition(player) outputChatBox("Fus Ro Dah!", root, 255, 0, 0, false) triggerClientEvent("onFusCommand", root, px, py, pz) marker = createMarker(px, py, pz, "cylinder", 150, 255, 0, 0, 255) setTimer(function() destroyElement(marker) end, 1000, 1) for ipl,pla in ipairs(getElementsByType("player")) do if not isElementWithinMarker(pla, marker) then end local x, y, z = getElementPosition(pla) setElementPosition(pla, x + 50, y + 50, z + 1) end for ive,veh in ipairs(getElementsByType("vehicle")) do if not isElementWithinMarker(veh, marker) then end local x, y, z = getElementPosition(veh) setElementPosition(veh, x + 50, y + 50, z + 1) end end end addCommandHandler("fus", fusRoDah) Client local root = getRootElement() local thisRoot = getResourceRootElement(getThisResource()) function playFusRoDah(px, py, pz) local sound = playSound3D("fusrodah.wav", px, py, pz, false) end addEvent("onFusCommand", true) addEventHandler("onFusCommand", root, playFusRoDah) So, it plays the voice and everything correctly. But it doesn't move the players or vehicles away from the marker. It doesn't output any errors or anything. I assume it's just that it checks the for ... do stuff and if one of them is invalid, it won't execute my function I am trying to do here. Edited May 30, 2019 by myonlake Link to comment
Wojak Posted December 12, 2011 Share Posted December 12, 2011 just remone line 16 and 17 (else return) Link to comment
myonlake Posted December 12, 2011 Author Share Posted December 12, 2011 And that's not going to make a difference, it's tested. Link to comment
Wojak Posted December 12, 2011 Share Posted December 12, 2011 return not only exit the loop, but the whole function - it should make a massive difference... Link to comment
myonlake Posted December 12, 2011 Author Share Posted December 12, 2011 return not only exit the loop, but the whole function - it should make a massive difference... And how am I able to make that return? Not sure, but you cannot return for .. do? Link to comment
Aibo Posted December 12, 2011 Share Posted December 12, 2011 "else" is not obligatory. and you dont need "return" for a loop to work. also you can exit the loop using "break", though im not sure if that is what you want Link to comment
myonlake Posted December 12, 2011 Author Share Posted December 12, 2011 I have removed the annoying else returns now. I am not sure have you really understood the problem; it possibly ends the function as it detects a player or a vehicle that is not in the marker, meaning that all players and vehicles should be in the marker to let the script work. EDIT: I have fixed the problem by making a check if the element is in the marker. Check the updated code. Link to comment
unknooooown Posted December 12, 2011 Share Posted December 12, 2011 (edited) marker = createMarker(px, py, pz, "cylinder", 150, 255, 0, 0, 255) setTimer(function() destroyElement(marker) end, 1000, 1) Instead of creating a marker and destroying it a second after it has been created, I would just add a colshape to the player when he joins. If you know that he is gonna use "Fus Ro Dah" when he is connected, the col could just be there all the time. It could be something like: col = {} function fusRoDahMe() local x,y,z = getElementPosition(source) col[source] = createColCircle(x,y,150) attachElements(col[source], source) end addEventHandler("onPlayerSpawn", root, fusRoDahMe) Like this you can just check if players/vehs are in the attached colshape everytime you need it. Edited December 12, 2011 by Guest Link to comment
myonlake Posted December 12, 2011 Author Share Posted December 12, 2011 marker = createMarker(px, py, pz, "cylinder", 150, 255, 0, 0, 255) setTimer(function() destroyElement(marker) end, 1000, 1) Instead of creating a marker and destroying it a second after it has been created, I would just add a colshape to the player when he joins. If you know that he is gonna use "Fus Ro Dah" when he is connected, the col could just be there all the time. It could be something like: col = {} function fusRoDahMe() local x,y,z = getElementPosition(source) col[source] = createColCircle(x,y,150) attachElements(col[source], source) end addEventHandler("onPlayerSpawn", root, fusRoDahMe) Like this you can just check if players/vehs are in the attached colshape everytime you need it. Thanks for the suggestion, I thought about it aswell but decided to work on a little easier first. I am changing it to colshapes now 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