User:Bkiro/sandbox: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 74: Line 74:
return 1
return 1
end
end
 
</source>
= Techniques =
= Techniques =
= Tips =
= Tips =

Revision as of 12:55, 17 September 2014

Codes

My Codes

Displaying Popup Message When Game Starts

This will Display An ingame Popup Message When The Game Starts ( Pre Game )

In scripts\vscripts\addon_game_mode.lua

-- addon_game_mode.lua

-- First we set up a listener

function Activate()
	GameRules.AddonTemplate:InitGameMode()
end

function CAddonTemplateGameMode:InitGameMode()
	GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
        -- This above thinker is irrelevent for this example

	ListenToGameEvent("game_rules_state_change",show_message,nil)
        -- This will run the function "show_message" whenever the event "game_rules_state_change" occurs.

end 

function show_message()
        g_state=GameRules:State_Get() -- This Line will assign the game state to the variable g_state
        if g_state == DOTA_GAMERULES_STATE_PRE_GAME then
                ShowGenericPopup( "#popup_title", "#popup_body", "", "", DOTA_SHOWGENERICPOPUP_TINT_SCREEN )
                -- "#popup_title" and "#popup_body" can be edited in resource\addon_english.txt
        end
end

In resource\addon_english.txt

"lang"
{
	"Language"		"English"
	"Tokens"
	{		
		"addon_game_name"			"name_of_your_addon"
		"popup_title"                           "Title of your popup message"
    		"popup_body"                     	"What message do you wanna give"
	}
}

Check for enemy units alive on the map and declare victory if all are dead

In scripts\vscripts\addon_game_mode.lua

function initiate()
	g_state=GameRules:State_Get()
	if g_state == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
		GameRules:GetGameModeEntity():SetThink( VictoryAssesment, 32)
	end
end

function VictoryAssesment()
	local unit = FindUnitsInRadius(DOTA_TEAM_GOODGUYS,
                              Vector(0, 0, 0),
                              nil,
                              FIND_UNITS_EVERYWHERE,
                              DOTA_UNIT_TARGET_TEAM_ENEMY,
                              DOTA_UNIT_TARGET_ALL,
                              DOTA_UNIT_TARGET_FLAG_NONE,
                              FIND_ANY_ORDER,
                              false)
	if #unit==0 then
		GameRules:SetGameWinner(DOTA_TEAM_GOODGUYS)
		return nil
	end
	return 1
end

Techniques

Tips