TextItemSetText: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 4: Line 4:


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">void textItemSetText ( textitem textitem, string text )</syntaxhighlight>  
<syntaxhighlight lang="lua">void textItemSetText ( textitem theTextitem, string text )</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''textitem:''' An existing text item that was previously created with '''textDisplayAddText'''
*'''theTextitem:''' An existing text item that was previously created with [[textDisplayAddText]]
*'''text:''' The new text for the text item
*'''text:''' The new text for the text item


Line 14: Line 14:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerWasted ( ammo, killer, weapon )
function onPlayerWasted ( ammo, killer, weapon )
if ( killer ~= false) then --Checks to see if anything killed the player. This can be false but it never equals true.
if ( killer ~= false) then   -- Check to see if anything killed the player
if (players[getClientName(killer)].gang == "grove") then --If a player killed this person and they are part of the grove gang
local killerTeam = getTeamName ( getPlayerTeam(killer) )
groveteamscore = groveteamscore + 1 --Grove gets 1 point
if ( killerTeam == "grove" ) then           -- if a Grove player scored the kill
textItemSetText ( scoregrove, tostring(groveteamscore) ) --Update scoreboard. Use tostring() to change the varible to a string to satisfy the function.
groveteamscore = groveteamscore + 1   -- Grove gets 1 point
elseif (players[getClientName(killer)].gang == "balla") then --If a player killed this person and they are part of the balla gang
textItemSetText ( scoregrove, tostring(groveteamscore) ) -- Update scoreboard.
ballateamscore = ballateamscore + 1 --Ballas get 1 point
elseif ( killerTeam == "balla" ) then       -- if a Balla player scored the kill
textItemSetText ( scoreballa, tostring(ballateamscore) ) --Update scoreboard.
ballateamscore = ballateamscore + 1   -- Ballas get 1 point
textItemSetText ( scoreballa, tostring(ballateamscore) ) -- Update scoreboard.
end
end
end
end

Revision as of 17:55, 21 August 2007

Overwrites a previously created text item with the specified text.

Syntax

void textItemSetText ( textitem theTextitem, string text )

Required Arguments

  • theTextitem: An existing text item that was previously created with textDisplayAddText
  • text: The new text for the text item

Example

Here, it is being used to update a scoreboard:

function onPlayerWasted ( ammo, killer, weapon )
	if ( killer ~= false) then   -- Check to see if anything killed the player
		local killerTeam = getTeamName ( getPlayerTeam(killer) )
		if ( killerTeam == "grove" ) then           -- if a Grove player scored the kill
			groveteamscore = groveteamscore + 1   -- Grove gets 1 point
			textItemSetText ( scoregrove, tostring(groveteamscore) ) -- Update scoreboard.
		elseif ( killerTeam == "balla" ) then       -- if a Balla player scored the kill
			ballateamscore = ballateamscore + 1   -- Ballas get 1 point
			textItemSetText ( scoreballa, tostring(ballateamscore) ) -- Update scoreboard.
		end
	end
end
addEventHandler ( "onPlayerWasted", getRootElement(), onPlayerWasted )

See Also