GabWas Posted November 15, 2015 Share Posted November 15, 2015 Hi there! I'm new at scripting and I'm making my first script (bomb). It's maybe a little complicated for a beginner, but how hard could it be? So, I have a question. Is there any way to put 2 functions into 1 command using CommandHandler? Because when the bomb is planted, you can plant another one, but then you can't detonate previous one. I need some kind of blockade, so you can plant only one bomb at the time. I would be very thankful for your help, guys Link to comment
t3wz Posted November 15, 2015 Share Posted November 15, 2015 function a () end function b () end addCommandHandler ( "bomb", a ); addCommandHandler ( "bomb", b ); btw you won't need 2 functions for this, read about tables and you can create it easily. Link to comment
GabWas Posted November 15, 2015 Author Share Posted November 15, 2015 How can that help me? I don't get it Link to comment
ALw7sH Posted November 15, 2015 Share Posted November 15, 2015 That's actually based on your idea&codes There's no certain way to do certain thing in scripting Link to comment
Tekken Posted November 16, 2015 Share Posted November 16, 2015 Use variables! This may help you: local isBombPlanted = false; function plant(player) if (isBombPlanted == false) then -- Make the bomb plant here! outputChatBox("You planted the bomb!", player, 255, 255, 255) isBombPlanted = true else outputChatBox("The bomb is already planted!", player, 255, 255, 255) end end addCommandHandler("bomb", plant) function bombExplode() -- Make the bomb explode! -- When the bomb explode set isBombPlanted to false so you can plant ti again! isBombPlanted = false end addCommandHandler("explode", bombExplode) Link to comment
GabWas Posted November 16, 2015 Author Share Posted November 16, 2015 Use variables! That will help a lot, thank you! Link to comment
Tekken Posted November 16, 2015 Share Posted November 16, 2015 Use variables! That will help a lot, thank you! No problem! Link to comment
n3wage Posted November 16, 2015 Share Posted November 16, 2015 This is not very effective because other players will not be able to plant a bomb if another player already did it. Link to comment
GabWas Posted November 16, 2015 Author Share Posted November 16, 2015 This is not very effective because other players will not be able to plant a bomb if another player already did it. You can be surprised, but that's what I needed Link to comment
Tekken Posted November 17, 2015 Share Posted November 17, 2015 This is not very effective because other players will not be able to plant a bomb if another player already did it. He can make it client-side, or maybe he need the bomb to be planted by only one player like in CS. Link to comment
GabWas Posted November 17, 2015 Author Share Posted November 17, 2015 This is not very effective because other players will not be able to plant a bomb if another player already did it. He can make it client-side, or maybe he need the bomb to be planted by only one player like in CS. Yes, something like that Do you maybe have idea about defusing? I thought about defusing, when a player is in invisible marker (created with model of bomb), but I just don't know how to do it. I tried onMarkerHit, but I've got an error with addEventHandler Link to comment
Saml1er Posted November 17, 2015 Share Posted November 17, 2015 Just use tables and do everything server side since you definitely don't want to bomb yourself lol. You are placing a bomb so it can explode other players, right? So do it sever side. local bombs = {} addCommandHandler ("bomb", function ( p, cmd ) if not bombs[getPlayerSerial (p) ] then local x, y, z = getElementPosition(p) local colShape = createColSphere ( x, y, z, 1 ) bombs[getPlayerSerial (p) ] = colShape -- save the xyz else -- bomb is already planted for current player end end ) addCommandHandler ("explode", function ( p, cmd ) if bombs[getPlayerSerial (p) ]) then local x, y, z = getElementPosition ( bombs[getPlayerSerial (p) ] ) destroyElement (bombs[getPlayerSerial (p) ]) bombs[getPlayerSerial (p) ] = nil createExplosion ( x, y, z,8 ) end ) addEventHandler ( "onColShapeHit", resourceRoot, -- resourceRoot will only allow this event handler to get triggered if colshape is created by this resource where this script is currently running function ( elem ) if getElementType(elem) == "player" then -- source of this event is the colshape local x, y, z = getElementPosition ( source ) createExplosion ( x, y, z, 8 ) destroyElement ( source ) end end ) serial is always good to use because it won't change even if player reconnects but if you want to remove bomb when player disconnects from server then set this same thing to nil, for example, addEventHandler("onPlayerQuit", root, function () if bombs[getPlayerSerial (source) ]) then destroyElement (bombs[getPlayerSerial (source) ]) bombs[getPlayerSerial (source) ] = nil end --this (nil) will remove the entry completely from the table. Don't use false use nil if you want to remove it and save memory just like I did end) I wrote this script from mobile. If you find any errors then fix it on your own. 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