Jump to content

help string.format


yukitokun1996

Recommended Posts

i have this error : bad argument #2 to 'format'

this is my code : 

local function dog_refresh_info()
	local dog = getElementData(getElementData(localPlayer, "player:dog"), "dog")
	guiSetText(petsystem.label[2], string.format("Rasa: %s\nNasycenie: %s/100\nKondycja: %s/50\n", rasy[dog.rasa], dog.nasycenie, dog.stamina))
end

 

Link to comment
3 minutes ago, Gravestone said:

Can you paste full code?

ok , this my full code : 

addEventHandler("onClientResourceStart", resourceRoot, function()
	local txd = engineLoadTXD("dog.txd" )
	engineImportTXD(txd, 310)
	local dff = engineLoadDFF("dog.dff", 310)
	engineReplaceModel(dff, 310)
	
	local txd = engineLoadTXD("pitbull.txd" )
	engineImportTXD(txd, 311)
	local dff = engineLoadDFF("pitbull.dff", 311)
	engineReplaceModel(dff, 311)
	
	local txd = engineLoadTXD("rottweiler.txd" )
	engineImportTXD(txd, 312)
	local dff = engineLoadDFF("rottweiler.dff", 312)
	engineReplaceModel(dff, 312)
end)

setTimer(function()
	--HAU HAU HAU ;3
	for k,v in ipairs(getElementsByType("ped")) do
		if math.random(1,5)==1 then
			if getElementModel(v) == 310 then
				if getElementData(v, "dog:text") then
					local smp3 = playSound3D("szczekanie.mp3", 0, 0, 0)
					setElementInterior(smp3, getElementInterior(v))
					setElementDimension(smp3, getElementDimension(v))
					attachElements(smp3, v)
				end
			end
		end
	end
end, 8000, 0)




petsystem = {
    button = {},
    window = {},
    label = {},
    combobox = {},
	edit = {}
}

petsystem.window[1] = guiCreateWindow(0.43, 0.42, 0.23, 0.32, "", true)
guiWindowSetSizable(petsystem.window[1], false)


petsystem.combobox[1] = guiCreateComboBox(0.05, 0.15, 0.91, 0.6, "--WYBIERZ--", true, petsystem.window[1])
petsystem.label[2] = guiCreateLabel(0.04, 0.25, 0.92, 0.55, "Rasa: Wilczur\nNasycenie: 100%\nKondycja: 50/50\n", true, petsystem.window[1])
petsystem.button[1] = guiCreateButton(0.05, 0.75, 0.45, 0.10, "Wydaj polecenie", true, petsystem.window[1])
petsystem.button[2] = guiCreateButton(0.51, 0.75, 0.45, 0.10, "Zamknij", true, petsystem.window[1])
petsystem.edit[1] = guiCreateEdit(0.05, 0.86, 0.91, 0.139, "Imie-PREMIUM", true, petsystem.window[1])
guiSetEnabled(petsystem.edit[1], false)

guiLabelSetHorizontalAlign(petsystem.label[2], "center", false)
guiLabelSetVerticalAlign(petsystem.label[2], "center")

guiSetVisible(petsystem.window[1], false)
showCursor(false)

function centerWindow(center_window)
    local screenW,screenH=guiGetScreenSize()
    local windowW,windowH=guiGetSize(center_window,false)
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2
    guiSetPosition(center_window,x,y,false)
end

centerWindow(petsystem.window[1])

local function dog_refresh_skills()
	guiEditSetMaxLength(petsystem.edit[1], 12)
	guiComboBoxClear(petsystem.combobox[1])
	
	guiComboBoxAddItem(petsystem.combobox[1], "Spawn")
	guiComboBoxAddItem(petsystem.combobox[1], "Unspawn")
	local dog = getElementData(getElementData(localPlayer, "player:dog"), "dog")
	
	if getElementData(localPlayer, "premium") then guiSetEnabled(petsystem.edit[1], true) guiComboBoxAddItem(petsystem.combobox[1], "Zmiana nazwy") else guiSetEnabled(petsystem.edit[1], false) end
	-- guiSetEnabled(petsystem.edit[1], true) guiComboBoxAddItem(petsystem.combobox[1], "Zmiana nazwy")
	local s_dajglos = dog.skill_dajglos==1 and true or false
	local s_zostan = dog.skill_zostan==1 and true or false
	local s_donogi = dog.skill_donogi==1 and true or false
	
	
	if s_dajglos then guiComboBoxAddItem(petsystem.combobox[1], "P: Daj głos!") end
	if s_zostan then guiComboBoxAddItem(petsystem.combobox[1], "P: Zostań!") end
	if s_donogi then guiComboBoxAddItem(petsystem.combobox[1], "P: Do nogi!") end
	
	
end

local rasy = {
	[0]="Wilczur",
	[1]="Pitbull",
	[2]="Rottweiler",
}

local function dog_refresh_info()
	local dog = getElementData(getElementData(localPlayer, "player:dog"), "dog")
	guiSetText(petsystem.label[2], string.format("Rasa: %s\nNasycenie: %s/100\nKondycja: %s/50\n", rasy[dog.rasa], dog.nasycenie, dog.stamina))
end

addCommandHandler("mypet", function()
	if (not getElementData(localPlayer, "player:dog")) then
		triggerServerEvent("onDogCommand", localPlayer, "Spawn")
	else
		dog_refresh_skills()
		dog_refresh_info()
		guiSetVisible(petsystem.window[1], true)
		showCursor(true)
		dog_tick = getTickCount()
	end
end)

addEventHandler("onClientGUIClick", petsystem.button[1], function()
	if (getTickCount()-dog_tick) < 500 then return end
	dog_tick = getTickCount()
	local item = guiComboBoxGetSelected(petsystem.combobox[1])
	local selected = guiComboBoxGetItemText(petsystem.combobox[1], item)
	if selected == "--WYBIERZ--" then return end
	
	
	if selected == "Spawn" or selected == "Unspawn" then
		triggerServerEvent("onDogCommand", localPlayer, selected)
	elseif selected == "Zmiana nazwy" then
		outputDebugString(guiGetText(petsystem.edit[1]))
		triggerServerEvent("onDogCommand", localPlayer, selected, 0, guiGetText(petsystem.edit[1]))
	else
		local dog = getElementData(getElementData(localPlayer, "player:dog") or false, "dog") or false
		triggerServerEvent("onDogCommand", localPlayer, selected, dog.nasycenie or 0)
	end
end, false)

addEventHandler("onClientGUIClick", petsystem.button[2], function()
	guiSetVisible(petsystem.window[1], false)
	showCursor(false)
end, false)

addEvent("dog_polecenie", true)
addEventHandler("dog_polecenie", getRootElement(), function(cmd)
	if cmd == "P: Daj głos!" then
		local sound = playSound3D("szczekanie.mp3", 0, 0, 0)
		setElementInterior(sound, getElementInterior(getElementData(source, "player:dog")))
		setElementDimension(sound, getElementDimension(getElementData(source, "player:dog")))
		attachElements(sound, getElementData(source, "player:dog"))
	end
end)

the error in line 101

Edited by yukitokun1996
Link to comment
4 minutes ago, Gravestone said:

Umm, what does this statement return?

local dog = getElementData(getElementData(localPlayer, "player:dog"), "dog")

Debug it manually through either outputChatBox or outputDebugString.

this my server file :

--[[
@author Karer <[email protected]>
@author WUBE <[email protected]>
@copyright 2011-2013 Lukasz Biegaj <[email protected]>
@license Dual GPLv2/MIT
@package MTA-XyzzyRP
@link https://github.com/lpiob/MTA-XyzzyRP GitHub
]]--



function dogFollow(thecop, theprisoner)
		if not ( theprisoner and thecop ) then return end
		if not theprisoner then return end
		if not getElementData(theprisoner, "dog:moveblock") then
			local copx, copy, copz = getElementPosition ( thecop )
			local prisonerx, prisonery, prisonerz = getElementPosition ( theprisoner )
			copangle = ( 360 - math.deg ( math.atan2 ( ( copx - prisonerx ), ( copy - prisonery ) ) ) ) % 360
			setPedRotation ( theprisoner, copangle )
			local dist = getDistanceBetweenPoints2D ( copx, copy, prisonerx, prisonery )	
			if getElementInterior(thecop) ~= getElementInterior(theprisoner) then setElementInterior(theprisoner, getElementInterior(thecop)) end
			if getElementDimension(thecop) ~= getElementDimension(theprisoner) then setElementDimension(theprisoner, getElementDimension(thecop)) end
			local dog = getElementData(theprisoner, "dog")
			-- outputDebugString(dog.stamina or "lol")
			if dist >= 200 then
				local x,y,z = getElementPosition(thecop)
				setElementPosition(theprisoner, x, y, z)
			elseif dist >= 8 and dog.stamina>=50 then
				setPedAnimation(theprisoner, "ped", "sprint_civi")
			elseif dist >= 2 then
				setPedAnimation(theprisoner, "ped", "run_player")
			else
				setPedAnimation(theprisoner, false)
			end
		end
		local zombify = setTimer ( dogFollow, 500, 1, thecop, theprisoner )
		-- outputDebugString(dog.stamina)
end

local rasy = {
	[0]=310,
	[1]=311,
	[2]=312,
}

local rasyskiny = {
	[310]=0,
	[311]=1,
	[312]=2,
}

function reloadDog(player,msg)
--	if not getElementData(player,"character") then return end
	local check = exports.mysql:query_fetch_assoc("SELECT * FROM lss_petsystem WHERE `char_id`='"..getElementData(player,"dbid").."'")
	if getElementData(player, "player:dog") then
		destroyElement(getElementData(getElementData(player, "player:dog"),"dog:text"))
		destroyElement(getElementData(player, "player:dog"))
	end
	if check and check.id then
		local x,y,z = getElementPosition(player)
		local pies = createPed(rasy[tonumber(check["rasa"])], x, y, z)
		setElementData(pies, "dog:owner", player)
		setElementData(pies, "dog", check)
		setElementData(player, "player:dog", pies)
		dogFollow(player, pies)
		local text = createElement("text")
		setElementPosition(text, x, y, z)
		setElementData(text, "attach", pies)
		setElementData(text, "addz", 1)
		setElementData(text, "text", (tonumber(check["nazwa"])=="BRAK" and "Pies" or "Pies - "..tonumber(check["nazwa"])))
		setElementData(pies, "dog:text", text)
		setElementHealth(pies, tonumber(check["nasycenie"]))
	else
		return
	end
	
	if msg then outputChatBox("(( Pies został zespawnowany ))", player) end
end


function unspawnDog(player)
--	if not getElementData(player,"character") then return end
	if getElementData(player, "player:dog") then
		destroyElement(getElementData(getElementData(player, "player:dog"),"dog:text"))
		destroyElement(getElementData(player, "player:dog"))
		removeElementData(player, "player:dog")
	end
end

-- addCommandHandler("dogreload", function(plr)
	-- if getElementData(plr, "player:dog") then destroyElement(getElementData(plr, "player:dog")) end
	-- reloadDog(plr)
-- end)


--skrypt na tworzenie pieskow do oswojenia
local wildDog = {}

local wildDogsPos = {
	{1200.3642578125, -1329.6904296875, 13.3984375, 10},
	{1200.3642578125, -1329.6904296875, 13.3984375, 280},
	{1200.3642578125, -1329.6904296875, 13.3984375,260.3},
	{1200.3642578125, -1329.6904296875, 13.3984375,225.2},
	{1200.3642578125, -1329.6904296875, 13.3984375,62.6},
	{1200.3642578125, -1329.6904296875, 13.3984375,66.1},
}

local function respawnDogs()
      if #getElementsByType("ped",resourceRoot)>50 then return end
		for k,v in ipairs(wildDogsPos) do
			if math.random(1,5) == 1 then
                local cs=createColSphere(v[1],v[2],v[3],10)
                local ec=#getElementsWithinColShape(cs)
                destroyElement(cs)
                if (ec==0) then
    				wildDog[k] = createPed(math.random(310,312), v[1], v[2], v[3])
				  setElementData(wildDog[k], "dog:wild", true)
				  setElementRotation(wildDog[k], 0, 0, v[4])
				  local text = createElement("text")
				  setElementPosition(text, v[1], v[2], v[3]+1)
				  setElementData(text, "text", "Dziki pies")
				  setElementData(wildDog[k], "dog:text", text)
				  setElementFrozen(wildDog[k], true)
                end
			end
		end
end


function menu_oswajanie(args)
	triggerEvent("onDogOswajanie", args.dog, args.player)
end

addEvent("onDogOswajanie", true)
addEventHandler("onDogOswajanie", getRootElement(), function(player)
	local check = exports.mysql:query_fetch_assoc("SELECT * FROM lss_petsystem WHERE `char_id`="..getElementData(player,"dbid").."")
	if check and check.id then outputChatBox("(( Masz już psa! ))", player) return end
	local szansa=math.random(1,2)
	if szansa==1 then --zlapal
		triggerEvent('sendAme', player, getPlayerName(player).." đã bắt thành công và đeo vòng cổ cho thú hoang.", 5, 10, true)
		exports.mysql:query_free("INSERT INTO lss_petsystem SET `char_id`='"..tonumber(getElementData(player,"dbid")).."', `nazwa`='BRAK', `rasa`='"..rasyskiny[getElementModel(source)].."' ")
		reloadDog(player)
	else
		triggerEvent('sendAme', player, getPlayerName(player).." próbuje bezskutecznie złapać psa, który ucieka.",5, 10, true)
	end
	
	destroyElement(getElementData(source, "dog:text"))
	if source and getElementType(source) then destroyElement(source) end
	exports.global:takeItem(player, 165, 1)
end)

respawnDogs()
setTimer(respawnDogs, 1200000, 0)

for k,v in ipairs(getElementsByType("player")) do
	removeElementData(v, "player:dog")
end

addEventHandler("onPlayerQuit", getRootElement(), function()
	unspawnDog(source)
end)

local function getCharacterName(plr)
--	local character=getElementData(plr,"character")
	--if not character then return "Nieznana osoba" end
	local zamaskowany=getElementData(plr,"zamaskowany")
	if zamaskowany then
		return "Zamaskowana osoba"
	end
	return character.imie.." "..character.nazwisko
end

local function polecenie_say(plr, msg)
	local characterName=getCharacterName(plr)
	local x,y,z=getElementPosition(plr)
    local strefa=createColSphere(x,y,z,50)
    local gracze=getElementsWithinColShape(strefa, "player")
	
    for i,v in ipairs(gracze) do
		if (getElementInterior(v)==getElementInterior(plr) and getElementDimension(v)==getElementDimension(plr)) then
			local x2,y2=getElementPosition(v)
			if (getDistanceBetweenPoints2D(x,y,x2,y2)<=10) then
				outputChatBox( characterName .. " wydaje polecenie psu: " .. msg, v, 255, 255, 255, true)
			end
			
		end
	end
	destroyElement(strefa)    
end

addEvent("onDogCommand", true)
addEventHandler("onDogCommand", getRootElement(), function(cmd,nasycenie,add1)
	local nasycenie = tonumber(nasycenie)
	if cmd == "Spawn" then
		if getElementData(source, "player:dog") then return end
		reloadDog(source,true)
		
	elseif cmd == "Unspawn" then
		if not getElementData(source, "player:dog") then return end
		unspawnDog(source)
		outputChatBox("(( Pies został zunspawnowany ))", source)
	elseif cmd == "P: Daj głos!" then
		local pies = getElementData(source, "player:dog")
		if not pies then return end
		local pies_name = getElementData(pies, "dog").nazwa=="BRAK" and "" or getElementData(pies, "dog").nazwa
		if nasycenie <= 30 then triggerEvent('sendAme', pies, "Brzuch psa "..pies_name.." burczy z głodu", 5, 10, true) return end
		polecenie_say(source, "daj głos!")
		triggerClientEvent("dog_polecenie", source, "P: Daj głos!")
	elseif cmd == "P: Zostań!" then
		local pies = getElementData(source, "player:dog")
		if not pies then return end
		local pies_name = getElementData(pies, "dog").nazwa=="BRAK" and "" or getElementData(pies, "dog").nazwa
		if nasycenie <= 20 then triggerEvent('sendAme', pies, "Brzuch psa "..pies_name.." burczy z głodu", 5, 10, true) return end
		polecenie_say(source, "zostań!")
		
		setElementData(pies, "dog:moveblock", true)
		setElementFrozen(pies, true)
		setPedAnimation ( pies, "JST_BUISNESS", "girl_02", -1, false, false )
		-- setPedAnimation(pies, "INT_OFFICE", "OFF_Sit_Idle_Loop", -1, true, false)
	elseif cmd == "P: Do nogi!" then
		local pies = getElementData(source, "player:dog")
		if not pies then return end
		local pies_name = getElementData(pies, "dog").nazwa=="BRAK" and "" or getElementData(pies, "dog").nazwa
		if nasycenie <= 20 then triggerEvent('sendAme', pies, "Brzuch psa "..pies_name.." burczy z głodu", 5, 10, true) return end
		polecenie_say(source, "do nogi!")
		
		setElementData(pies, "dog:moveblock", false)
		setElementFrozen(pies, false)
		setPedAnimation(pies, false)
	elseif cmd == "Zmiana nazwy" then
		local pies = getElementData(source, "player:dog")
		if not pies then return end
		exports.mysql:query_free("UPDATE lss_petsystem SET `nazwa`="..add1.." WHERE `char_id`="..getElementData(source, "dbid").."")
		unspawnDog(source)
		setTimer(reloadDog,50, 1, source,true)
	end
end)


local function dog_glod()
	--glod pieskow ;c
	for k,v in ipairs(getElementsByType("ped")) do
		if getElementModel(v) == 310 or getElementModel(v) == 311 or getElementModel(v) == 312 then
			if getElementData(v, "dog:owner") then
				--glod
				dog = getElementData(v, "dog")
				dog.nasycenie = ((dog.nasycenie)-1)<0 and 0 or ((dog.nasycenie)-1)
				setElementData(v, "dog", dog)
				exports.mysql:query_free("UPDATE lss_petsystem SET `nasycenie`=nasycenie-1 WHERE `char_id`='"..getElementData(getElementData(v, "dog:owner"),"dbid").."' ")
				setElementHealth(v, dog.nasycenie)
				if dog.nasycenie <= 0 then --zabijamy psa :(
					triggerEvent('sendAme', v, "Pies "..dog.nazwa.." umiera z głódu.", 5, 10, true)
					exports.mysql:query_free("DELETE FROM lss_petsystem WHERE `char_id`='"..getElementData(getElementData(v, "dog:owner"),"dbid").."' ")
					unspawnDog(getElementData(v, "dog:owner"))
				end
				
			end
		end
	end
end
setTimer(dog_glod, 240000, 0)
-- setTimer(dog_glod, 5000, 0)

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...