#Dv^ Posted October 26, 2016 Share Posted October 26, 2016 (edited) Hola! ¿Qué necesito para contar las kills de un player pero solo aquellas que haga con M4? Algo como así addEventHandler("onPlayerWasted",getRootElement(), function ( ammo, attacker, weapon, bodypart ) if getElementInterio(attacker) == 1 then if attacker then if ( attacker ~= source and getElementType ( attacker ) == "player" ) then local playergun = getWeaponNameFromID ( attacker ) if ( playergun == 31 ) then end end end end end ) Es decir quiero que las kills se cuenten en un interior, para eso se que se usa getElementInterior, pero luego de que los players salgan de ese interior las kills se vuelvas a reiniciar ¿Qué tengo que usar? Gracias Edited October 26, 2016 by Slash14 Link to comment
aka Blue Posted October 26, 2016 Share Posted October 26, 2016 Para que se reinicien debes hacer un evento o un checking con un timer que cuente siempre cuando un jugador sale o entra en un interior. Si usas un sistema de interiores, tendrá que tener algún evento que es cuando el jugador sale del mismo. Por lo demás, esto debería funcionar como quieres: local kills = { } addEventHandler( "onPlayerWasted", getRootElement( ), function( ammo, attacker, weapon, bodypart ) if getElementInterior( attacker ) == 1 and getElementInterior( source ) == 1 then if attacker then if ( attacker ~= source and getElementType ( attacker ) == "player" ) then local gun = getWeaponNameFromID( getPedWeapon( attacker ) ) if gun == 31 then if kills[ attacker ] == nil then kills[ attacker ] = 0 end kills[ attacker ] = tonumber( kills[ attacker ] ) + 1 end end end end end ) function getPlayerKills( player ) if player then if kills[ player ] == nil return nil else return kills[ player ] end end return false end Te añadí una función (getPlayerKills) que te devuelve las kills que ha hecho un jugador, por si lo quieres usar en otro script como export o algo parecido, ya que no usa elementData, sino, tablas. Link to comment
#Dv^ Posted October 26, 2016 Author Share Posted October 26, 2016 Gracias @aka Blue ¿Para exportar debo usar esto? meta <export function="getPlayerKills" type="server" /> server exports.xG_Duelos:getPlayerKills(player) ¿Algo así para obtener las kills? function kills (player) local v = exports.[Resource]:getPlayerKills(player) outputChatBox("Tus kills son "..tonumber(v).."") end addCommandHandler("stat", kills) Link to comment
#Dv^ Posted October 26, 2016 Author Share Posted October 26, 2016 Al escribir /stat me sale este error attempt to concatenate a nil value Link to comment
aka Blue Posted October 26, 2016 Share Posted October 26, 2016 (edited) exports.xG_Duelos:getPlayerKills(player) usa eso, no exports.[resource] Disculpa, error mío, cambia ésto: if kills[ player ] == nil return nil else return kills[ player ] end por esto: if kills[ player ] == nil then return 0 else return kills[ player ] end Edited October 26, 2016 by aka Blue Link to comment
Tomas Posted October 26, 2016 Share Posted October 26, 2016 return kills[ player ] or 0 Link to comment
#Dv^ Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) Gracias por su ayuda, lo estuve probando, y las kills no me salen cuando alguien muere en cierta int, al terminar el duelo me sale este error y en el chat solo sale en 0 los resultados Bad argument @ "getElementInterior" [Expected element at argument 1, got boolean] function getPlayerFromID ( id ) return call ( getResourceFromName ( "ID" ), "getPlayerFromID", tonumber ( id ) ); end local state = 0 local fightOn = 0 duelTable = { }; goFight = { 2750, -1603, 290, 34, 1542 }; function goToFight ( element ) setElementPosition ( element, goFight[1], goFight[2], goFight[3] ); setElementInterior ( element, goFight[4] ); setElementDimension ( element, goFight[5] ); giveWeapon ( element, 34 ); end function checkDuel ( player, cmd, arg ) if state == 0 then if ( tonumber ( arg ) ) then local p = getPlayerFromID( arg ); if ( isElement ( p ) ) then if ( not duelTable [ p ] ) then duelTable [ p ] = player; outputChatBox ( "Tu invitaste a " .. getPlayerName ( p ) .. " a un duelo!", player, 255, 255, 255, true ); outputChatBox ( "" .. getPlayerName ( player ) .. " te invitó a un duelo!", p, 255, 255, 255, true ); else outputChatBox ( "Este player ya esta en un duelo!", player, 255, 0, 0, true ); end else outputChatBox ( "No se encuentra esta ID!", player, 255, 0, 0, true ); end end else outputChatBox("Ya hay un duelo en marcha o invitación pendiente"); end if ( arg == "aceptar" ) and fightOn == 0 then local p = duelTable [ player ]; local v = getPlayerKills(p) local b = getPlayerKills(player) if ( isElement ( p ) ) then outputChatBox ( "El jugador " .. getPlayerName ( player ) .. " retó a un duelo a " .. getPlayerName ( p ) .. "", root, 255, 255, 255, true ); fightOn = 1 goToFight ( p ); goToFight ( player ); state = 1 setTimer(function() state = 0 fightOn = 0 outputChatBox("[VS] Resultados: "..getPlayerName(player).." ["..tonumber(v).."] vs ["..tonumber(b).."] "..getPlayerName(p).."",root, 255,255,255,true) duelTable [ player ] = nil; killPed(player) killPed(p) end,60000,1) else outputChatBox ( "No tienes ninguna invitación de duelo!", player, 255, 0, 0, true ); end elseif ( arg == "rechazar" ) and fightOn == 0 then local p = duelTable [ player ]; if ( isElement ( p ) ) then duelTable [ player ] = nil; fightOn = 0 state = 0 outputChatBox ( getPlayerName ( player ) .. " rechazó tu invitación.", p, 255, 0, 0, true ); end else return; end end local kills = { } addEventHandler( "onPlayerWasted", getRootElement( ), function( ammo, attacker, weapon, bodypart ) if getElementInterior( source ) == 34 and getElementInterior( attacker ) == 34 then if attacker then if ( attacker ~= source and getElementType ( attacker ) == "player" ) then local gun = getWeaponNameFromID( getPedWeapon( attacker ) ) if gun == 34 then if kills[ attacker ] == nil then kills[ attacker ] = 0 end kills[ attacker ] = tonumber( kills[ attacker ] ) + 1 end end end end end ) function getPlayerKills( player ) if player then if kills[ player ] == nil then return 0 else return kills[ player ] or 0 end end return false end Edited October 27, 2016 by Slash14 Link to comment
#Dv^ Posted October 28, 2016 Author Share Posted October 28, 2016 ¿Alguna ayuda por favor? Link to comment
#Dv^ Posted October 29, 2016 Author Share Posted October 29, 2016 (edited) Yo invito a un player a un duelo con /duelo ID, luego si el acepta con /duelo aceptar van a un int y dimensión, al terminar el duelo después de 3 miinutos salen los resultados en el chat "Resultados [Nick 0 - 0 Nick]" de las kills que hace cada uno en esa int. ya luego que salgan de esa int las kills se reinicien de nuevo Edited October 29, 2016 by Slash14 Link to comment
Tomas Posted October 29, 2016 Share Posted October 29, 2016 local duelKills = {} local duelDim = 69 local duelInt = 72 addEventHandler("onPlayerWasted", root, function (attacker) if attacker and attacker ~= source then if getElementType(attacker) == "player" then if getElementDimension(attacker) == duelDim and getElementDimension(source) == duelDim then if getElementInterior(attacker) == duelInt and getElementInterior(source) == delInt then duelKills[attacker] = ( duelKills[attacker] or 0 ) + 1 end end end end end ) Link to comment
Recommended Posts