Fabio(GNR) Posted December 30, 2010 Share Posted December 30, 2010 Another question: i wan to get random coordinates for a teleport, its for a deathmatch area so you don't always get spawned at one point with anyone else, i thought a table is ok, but i don't know how to do this... i read the lua tutorial about math.random but no succes... other Question: i want to setElementData on playersource that types a command, and then getElementData, to check if something is toggled on... script so far: addCommandHandler("god", function (thePlayer, playerSource) setElementData ( playerSource, "godmode", true ) addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end) function cancelalldamage ( thePlayer, playerSource ) godonoroff = getElementData ( playerSource, "godmode" ) if ( godonoroff == true ) then if getElementDimension ( thePlayer ) == 0 then cancelEvent() end end end it gives bad arguments at well set and get Data Link to comment
MaddDogg Posted December 30, 2010 Share Posted December 30, 2010 Well the parameters, which the script expects at cancelalldamage, isn't what the event onClientPlayerDamage will give you. The second parameter is the weapon, with which the damage was generated. Have a look at this: https://wiki.multitheftauto.com/wiki/OnC ... ayerDamage So actually, your playerSource variable holds an integer in the end, not a player element. Regarding your random spawn: What did you already try? You just have to get a random number between 0 and the width or length of your area. So a calculation for the x value could look like this: spawnX = 1200.0 + math.random(0, 140.0) 1200.0 is the minimum spawn position, 140.0 the width of your spawn area. Link to comment
DiSaMe Posted December 30, 2010 Share Posted December 30, 2010 If you want to make a list of coordinates, so that you will spawn at one position of multiple positions defined, you can do that in this way: spawn_pos = { {x1,y1,z1}, {x2,y2,z2}, ... } To get random coordinates: x,y,z = unpack(spawn_pos[math.random(#spawn_pos)]) And you can use x,y,z in spawnPlayer. Link to comment
Fabio(GNR) Posted December 30, 2010 Author Share Posted December 30, 2010 Well the parameters, which the script expects at cancelalldamage, isn't what the event onClientPlayerDamage will give you.The second parameter is the weapon, with which the damage was generated. Have a look at this: https://wiki.multitheftauto.com/wiki/OnC ... ayerDamage So actually, your playerSource variable holds an integer in the end, not a player element. Regarding your random spawn: What did you already try? You just have to get a random number between 0 and the width or length of your area. So a calculation for the x value could look like this: spawnX = 1200.0 + math.random(0, 140.0) 1200.0 is the minimum spawn position, 140.0 the width of your spawn area. Thanks but i tried the same but with addCommandHandler and then playerSource should be valid... and the random spawn is like doomed space marine's "idea" ( thanks for that btw ) EDIT: I thought i did, but i dont really understand you MaddDogg, if i would do this: function cancelalldamage (attacker, weapon, bodypart, loss, thePlayer, playerSource) it should work, well i tried but it didnt Link to comment
Remp Posted January 1, 2011 Share Posted January 1, 2011 The second parameter for addCommandHandler is the command name, so playerSource in your god command isn't a player (its "god"). You need to use thePlayer instead (because the first parameter is the player that typed the command) function cancelalldamage (attacker, weapon, bodypart, loss, thePlayer, playerSource) It doesn't matter what you write in there or what you call each thing, the value it holds won't change (you could call them 'apple, banana, pear, orange' and it would still represent the attacker element, the weapon id, the bodypart id and the loss). It's only passed 4 parameters so that's all there is, you can't add more to the end like that The player that is being damaged is 'source' addCommandHandler("god", function (thePlayer) setElementData ( thePlayer, "godmode", true ) addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end ) function cancelalldamage ( ) godonoroff = getElementData ( source, "godmode" ) if ( godonoroff == true ) then if getElementDimension ( source ) == 0 then cancelEvent() end end end Link to comment
Fabio(GNR) Posted January 1, 2011 Author Share Posted January 1, 2011 The second parameter for addCommandHandler is the command name, so playerSource in your god command isn't a player (its "god"). You need to use thePlayer instead (because the first parameter is the player that typed the command)It doesn't matter what you write in there or what you call each thing, the value it holds won't change (you could call them 'apple, banana, pear, orange' and it would still represent the attacker element, the weapon id, the bodypart id and the loss). It's only passed 4 parameters so that's all there is, you can't add more to the end like that The player that is being damaged is 'source' Ah ok Thanks alot i will test it later but THANKS! EDIT: No, doesnt work bad argument at setElementData Link to comment
Castillo Posted January 2, 2011 Share Posted January 2, 2011 addCommandHandler("god", function (thePlayer) setElementData ( getLocalPlayer(), "godmode", true ) addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end ) function cancelalldamage ( ) godonoroff = getElementData ( source, "godmode" ) if ( godonoroff == true ) then if getElementDimension ( source ) == 0 then cancelEvent() end end end Link to comment
Fabio(GNR) Posted January 2, 2011 Author Share Posted January 2, 2011 addCommandHandler("god", function (thePlayer) setElementData ( getLocalPlayer(), "godmode", true ) addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end ) function cancelalldamage ( ) godonoroff = getElementData ( source, "godmode" ) if ( godonoroff == true ) then if getElementDimension ( source ) == 0 then cancelEvent() end end end You Are My Hero!!!!!! It worked Thanks YES Link to comment
dizzy_hype Posted February 10, 2011 Share Posted February 10, 2011 is that the god mode? for admins only or all players? Link to comment
Fabio(GNR) Posted February 11, 2011 Author Share Posted February 11, 2011 is that the god mode?for admins only or all players? all, but try to write something yourself 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