Adde Posted August 29, 2013 Posted August 29, 2013 Hello. How do I set the missionTimer only visible to the jailed person? I am using "setElementVisibleTo" to make it visible for the jailed person, but then i have to hide it for the rest of the players. I don´t know how I should target the rest of the players... and btw, how can I finish the function "freeFromJail" and make it work? When I use setTimer(freeFromJail, 3000,1) the debug says "bad function at arg 1" or something. function policeJob ( attacker, attackerweapon, bodypart, loss ) if attacker and getElementType(attacker) == "player" then theTeam = getPlayerTeam ( attacker ) local wlevel = getPlayerWantedLevel( source ) theSkin = getElementModel ( attacker ) if (attackerweapon == 3) and (loss > 2 ) and (wlevel > 0) then if getTeamName( theTeam ) == "Police Department" or getTeamName( theTeam ) == "Staff" or getTeamName( theTeam ) == "US Army" or getTeamName( theTeam ) == "US Marines" then setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 6 ) setElementDimension ( source, 3 ) toggleControl(source, "fire", false) toggleControl(source, "next_weapon", false) toggleControl(source, "previous_weapon", false) toggleControl(source, "aim_weapon", false) toggleControl(source, "vehicle_fire", false) theName = getPlayerName ( source ) theCop = getPlayerName ( attacker ) outputChatBox ( "You have been jailed by "..theCop.. " for 5 minutes.", source ) outputChatBox ( "You have jailed "..theName, attacker ) local thisreward = wlevel*kreward givePlayerMoney ( attacker, thisreward ) setPlayerWantedLevel ( source, 0) MissionTimer = exports.missionTimer:createMissionTimer ( 300000, true, "%m:%s" , 0.5, 0.5, true, "default-bold", 5, 255, 10, 10 ) setElementVisibleTo ( MissionTimer, source, true ) end end end end addEventHandler ("onPlayerDamage", getRootElement(), policeJob) function freeFromJail() local time = getMissionTimerTime ( MissionTimer ) if ( time ) == 0 then destroyElement(MissionTimer) setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 0 ) setElementDimension ( source, 0 ) toggleControl(source, "fire", true) toggleControl(source, "next_weapon", true) toggleControl(source, "previous_weapon", true) toggleControl(source, "aim_weapon", true) toggleControl(source, "vehicle_fire", true) end end
HunT Posted August 30, 2013 Posted August 30, 2013 addEventHandler ( "onClientMissionTimerElapsed", MissionTimer, freeFromJail) Edit: u need make the script client side.
Adde Posted August 30, 2013 Author Posted August 30, 2013 Okay so this should work: function freeFromJail() local time = getMissionTimerTime ( MissionTimer ) if ( time ) == 0 then destroyElement(MissionTimer) setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 0 ) setElementDimension ( source, 0 ) toggleControl(source, "fire", true) toggleControl(source, "next_weapon", true) toggleControl(source, "previous_weapon", true) toggleControl(source, "aim_weapon", true) toggleControl(source, "vehicle_fire", true) end end addEventHandler ( "onClientMissionTimerElapsed", MissionTimer, freeFromJail) Do you mean both functions or just freeFromJail?
HunT Posted August 30, 2013 Posted August 30, 2013 U no need getMissionTimerTime onClientMissionTimerElapsed start the function if the timer is 0 Edit again: u need make the complete script client side. Now i cant give u the example reply with iphone.
Adde Posted August 30, 2013 Author Posted August 30, 2013 U no need getMissionTimerTime onClientMissionTimerElapsed start the function if the timer is 0 Ah okay. Now my script looks like: client: function setTimer() MissionTimer = exports.missionTimer:createMissionTimer ( 300000, true, "%m:%s" , 0.5, 0.5, true, "default-bold", 5, 255, 10, 10 ) setElementVisibleTo ( MissionTimer, source, true ) end addEvent("setMissionTimer", true) addEventHandler("setMissionTimer", getLocalPlayer(), setTimer) function freeFromJail() destroyElement(MissionTimer) setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 0 ) setElementDimension ( source, 0 ) toggleControl(source, "fire", true) toggleControl(source, "next_weapon", true) toggleControl(source, "previous_weapon", true) toggleControl(source, "aim_weapon", true) toggleControl(source, "vehicle_fire", true) end addEventHandler ( "onClientMissionTimerElapsed", MissionTimer, freeFromJail) server: kreward = 150 function policeJob ( attacker, attackerweapon, bodypart, loss ) if attacker and getElementType(attacker) == "player" then theTeam = getPlayerTeam ( attacker ) local wlevel = getPlayerWantedLevel( source ) theSkin = getElementModel ( attacker ) if (attackerweapon == 3) and (loss > 2 ) and (wlevel > 0) then if getTeamName( theTeam ) == "Police Department" or getTeamName( theTeam ) == "Staff" or getTeamName( theTeam ) == "US Army" or getTeamName( theTeam ) == "US Marines" then setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 6 ) setElementDimension ( source, 3 ) toggleControl(source, "fire", false) toggleControl(source, "next_weapon", false) toggleControl(source, "previous_weapon", false) toggleControl(source, "aim_weapon", false) toggleControl(source, "vehicle_fire", false) theName = getPlayerName ( source ) theCop = getPlayerName ( attacker ) outputChatBox ( "You have been jailed by "..theCop.. " for 5 minutes.", source ) outputChatBox ( "You have jailed "..theName, attacker ) local thisreward = wlevel*kreward givePlayerMoney ( attacker, thisreward ) setPlayerWantedLevel ( source, 0) triggerClientEvent("setMissionTimer", source) end end end end addEventHandler ("onPlayerDamage", getRootElement(), policeJob) So this is correct? But I get error in debug, client.lua:19: bad argument @ addEventHandler [ expected element at argument 2, got nil. Not tested if it still works, but I will test.
HunT Posted August 30, 2013 Posted August 30, 2013 Server kreward = 150 function policeJob ( attacker, attackerweapon, bodypart, loss ) if attacker and getElementType(attacker) == "player" then theTeam = getPlayerTeam ( attacker ) local wlevel = getPlayerWantedLevel( source ) theSkin = getElementModel ( attacker ) if (attackerweapon == 3) and (loss > 2 ) and (wlevel > 0) then if getTeamName( theTeam ) == "Police Department" or getTeamName( theTeam ) == "Staff" or getTeamName( theTeam ) == "US Army" or getTeamName( theTeam ) == "US Marines" then setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 6 ) setElementDimension ( source, 3 ) toggleControl(source, "fire", false) toggleControl(source, "next_weapon", false) toggleControl(source, "previous_weapon", false) toggleControl(source, "aim_weapon", false) toggleControl(source, "vehicle_fire", false) theName = getPlayerName ( source ) theCop = getPlayerName ( attacker ) outputChatBox ( "You have been jailed by "..theCop.. " for 5 minutes.", source ) outputChatBox ( "You have jailed "..theName, attacker ) local thisreward = wlevel*kreward givePlayerMoney ( attacker, thisreward ) setPlayerWantedLevel ( source, 0) triggerClientEvent("setMissionTimer", source) end end end end addEventHandler ("onPlayerDamage", getRootElement(), policeJob) Client function startMission() MissionTimer = exports.missionTimer:createMissionTimer ( 300000, true, "%m:%s" , 0.5, 0.5, true, "default-bold", 5, 255, 10, 10 ) addEventHandler ( "onClientMissionTimerElapsed", MissionTimer, freeFromJail) end addEvent("setMissionTimer", true) addEventHandler("setMissionTimer", getLocalPlayer(), startMission) function freeFromJail() if MissionTimer then destroyElement(MissionTimer) setElementPosition ( source, 264.74, 77.69, 1001.03 ) setElementInterior ( source, 0 ) setElementDimension ( source, 0 ) toggleControl(source, "fire", true) toggleControl(source, "next_weapon", true) toggleControl(source, "previous_weapon", true) toggleControl(source, "aim_weapon", true) toggleControl(source, "vehicle_fire", true) end end The mission timer work now but maybe u have other problem in the script.
Adde Posted September 1, 2013 Author Posted September 1, 2013 Still "addEventHandler [ expected element at argument 2, got nil ]"
Adde Posted September 1, 2013 Author Posted September 1, 2013 Client:5: addEventHandler [ expected element at argument 2, got nil ] It works to jail a person, but the timer don´t show on the screen in jail and it doesn´t even start. You never get out of jail.
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