Agon Posted August 11, 2012 Share Posted August 11, 2012 I tried to make something like this but it doesn't work. It gives errors. Here is the code: function setKillerAndVictim(source, command, killer, victim) if killer and victim then local sAccount = getPlayerAccount(source) local kAccount = getPlayerAccount(killer) local vAccount = getPlayerAccount(victim) local vx, vy, vz = getElementPosition(victim) if isObjectInACLGroup("user."..getAccountName(sAccount), aclGetGroup("Admin")) or isObjectInACLGroup("user."..getAccountName(sAccount), aclGetGroup("Owner")) then setAccountData(kAccount, "is.killer", true) setAccountData(vAccount, "is.victim", true) local vMarker = createMarker(vx, vy, vz, "arrow", 0.5, 255, 0, 0, 170, killer) attachElements(vMarker, victim, 0, 0, 1.5) else outputChatBox("[ERROR]: You don't have permission to use this command!", source, 255, 0, 0) end else outputChatBox("[ERROR]: The syntax is: /ktv [killername] [victimname]", source, 255, 0, 0) end end addCommandHandler("ktv", setKillerAndVictim) function giveCredits(ammo, killer, weapon, bodypart, victim, vMarker) local kAccount = getPlayerAccount(killer) local vAccount = getPlayerAccount(victim) local isKiller = getAccountData(kAccount, "is.killer") local isVictim = getAccountData(vAccount, "is.victim") if isKiller and isVictim then setAccountData(kAccount, "is.killer", false) setAccountData(vAccount, "is.victim", false) detachElements(vMarker, victim) givePlayerMoney(killer, 1000) setAccountData(kAccount, "game.points", getAccountData(kAccount, "game.points") +10) outputChatBox("[Mini Game]" .. getPlayerName(killer) .. "get 1000$ and 10 points by killing" .. getPlayerName(victim) .. "!", getRootElement(), 0, 120, 0) end end addEventHandler("onPlayerWasted", getRootElement(), giveCredits) and the errors: WARNING: ktv\ktv.lua:4: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got string 'agon'] WARNING: ktv\ktv.lua:5: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got string 'mahmut'] WARNING: ktv\ktv.lua:6: Bad argument @ 'getElementPosition' [Expected element at argument 1, got string 'mahmut'] WARNING: ktv\ktv.lua:8: Bad argument @ 'setAccountData' [Expected account at argument 1, got boolean] [WARNING: ktv\ktv.lua:9: Bad argument @ 'setAccountData' [Expected account at argument 1, got boolean] WARNING: ktv\ktv.lua:10: Bad argument @ 'createMarker' WARNING: ktv\ktv.lua:11: Bad argument @ 'attachElements' [Expected element at argument 1, got boolean] I defined them but .. Link to comment
Guest Guest4401 Posted August 11, 2012 Share Posted August 11, 2012 function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end function setKillerAndVictim(source, command, killer, victim) if killer and victim then local killer = getPlayerFromNamePart(killer) local victim = getPlayerFromNamePart(victim) if killer and victim then local sAccount = getPlayerAccount(source) local kAccount = getPlayerAccount(killer) local vAccount = getPlayerAccount(victim) local vx, vy, vz = getElementPosition(victim) if isObjectInACLGroup("user."..getAccountName(sAccount), aclGetGroup("Admin")) or isObjectInACLGroup("user."..getAccountName(sAccount), aclGetGroup("Owner")) then setAccountData(kAccount, "is.killer", true) setAccountData(vAccount, "is.victim", true) local vMarker = createMarker(vx, vy, vz, "arrow", 0.5, 255, 0, 0, 170, killer) attachElements(vMarker, victim, 0, 0, 1.5) else outputChatBox("[ERROR]: You don't have permission to use this command!", source, 255, 0, 0) end else outputChatBox("Player not found.",source,255,0,0) end else outputChatBox("[ERROR]: The syntax is: /ktv [killername] [victimname]", source, 255, 0, 0) end end addCommandHandler("ktv", setKillerAndVictim) function giveCredits(ammo, killer, weapon, bodypart, victim, vMarker) local kAccount = getPlayerAccount(killer) local vAccount = getPlayerAccount(victim) local isKiller = getAccountData(kAccount, "is.killer") local isVictim = getAccountData(vAccount, "is.victim") if isKiller and isVictim then setAccountData(kAccount, "is.killer", false) setAccountData(vAccount, "is.victim", false) detachElements(vMarker, victim) givePlayerMoney(killer, 1000) setAccountData(kAccount, "game.points", getAccountData(kAccount, "game.points") +10) outputChatBox("[Mini Game]" .. getPlayerName(killer) .. "get 1000$ and 10 points by killing" .. getPlayerName(victim) .. "!", getRootElement(), 0, 120, 0) end end addEventHandler("onPlayerWasted", getRootElement(), giveCredits) Link to comment
Agon Posted August 11, 2012 Author Share Posted August 11, 2012 It works fine until you kill the victim. WARNING: ktv\ktv.lua:38: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got boolean] WARNING: ktv\ktv.lua:39: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got boolean] WARNING: ktv\ktv.lua:40: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] WARNING: ktv\ktv.lua:41: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] Link to comment
Castillo Posted August 11, 2012 Share Posted August 11, 2012 If a player killed him, it shouldn't cause the error at line 38, but for the line 39, you didn't define anywhere: "victim". Link to comment
Kenix Posted August 11, 2012 Share Posted August 11, 2012 Variable victim is not element it's boolean so you should use predefined variable source. Source is wasted player. Link to comment
Agon Posted August 11, 2012 Author Share Posted August 11, 2012 Variable victim is not element it's boolean so you should use predefined variable source. Source is wasted player. But if i use source instead of victim, should i be able to detach the element? because it is attached to "victim" not source and btw I have 2 questions: 1) How can i make a timer? I mean for example I want the killer to kill victim in 5 minutes. 2)Will this work? I mean will the money and points be seen on the scoreboard? I'm not good at scoreboard function scoreBoard() scoreboardAddColumn("Points") scoreboardAddColumn("Money") end addEventHandler("onResourceStart", getResourceName(getThisResource()), scoreBoard) 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