Warcraft III resources & community, 2003–2006 · archived

-give x y

not rated
Submitted by N-a-z-g-u-lTriggers0 downloads
This command enables you to send y gold to player x. y can be "all", or a value with "k" at the end for *1000. x can be the name or the player id. Examples:
-give 1 all: Gives all gold to player 1.
-give N-a-z-g-u-l 2.5k: Gives 2500 gold to N-a-z-g-u-l.
-give 11 500: Gives 500 gold to player 11.

How to install?
Just create a trigger in the world editor named "Give", convert it to custom script and then replace the showed code with this script.

The messages
There are different messages in the code, which you can edit. For example the "Nopool is enabled" text may be edited. Nopool is an option for the map i made the script.

Source

function Trig_Give_Conditions takes nothing returns boolean
	if SubString( GetEventPlayerChatString(  ), 0, 6 ) != "-give " then
		return false
	elseif IsMapFlagSet(MAP_LOCK_RESOURCE_TRADING) then
		if GetTriggerPlayer() == GetLocalPlayer() then
			call DisplayTextToPlayer( GetLocalPlayer(  ), 0, 0, "|Cfffed312Nopool is enabled. Gold cannot be sent to allied players.|r" )
		endif
		return false
	endif
	return GetPlayerState( GetTriggerPlayer(  ), PLAYER_STATE_RESOURCE_GOLD ) != 0
endfunction

function Trig_Give_IsValidGiveTarget takes integer i returns boolean
	if GetTriggerPlayer(  ) == Player( i ) then
		return false
	elseif GetPlayerSlotState( Player( i ) ) != PLAYER_SLOT_STATE_PLAYING then
		return false
	endif
	return IsPlayerAlly(GetTriggerPlayer(  ), Player( i ) )
endfunction

function Trig_Give_Actions takes nothing returns nothing
	local string GiveStr = StringCase( GetEventPlayerChatString(  ), false )
	local string AmountStr
	local string S
	local integer i = 0
	local integer Amount = 0
	local integer Target = -1
	local integer Length = StringLength( GiveStr )

	loop
		exitwhen i > 11
		if Trig_Give_IsValidGiveTarget( i ) then
			set S = StringCase( GetPlayerName( Player( i ) ), false )
			if SubString( GiveStr, 6, 6 + StringLength( S ) ) == S then
				set Target = i
				set AmountStr = SubString( GiveStr, 7 + StringLength( S ), Length )
			elseif S2I( SubString( GiveStr, 6, 8 ) ) == i + 1 then
				set Target = i
				set AmountStr = SubString( GiveStr, 7 + StringLength( I2S( i + 1 ) ), Length )
			endif
		endif
		set i = i + 1
	endloop
	if Target != -1 then
		set i = GetPlayerState( GetTriggerPlayer(  ), PLAYER_STATE_RESOURCE_GOLD )
		set Length = StringLength( AmountStr )
		if SubString( AmountStr, Length - 3, Length ) == "all" then
			set Amount = i
		else
			if SubString( AmountStr, Length - 1, Length ) == "k" then
				set Amount = R2I( 1000.00 * S2R( AmountStr ) )
			else
				set Amount = S2I( AmountStr )
			endif
		endif
		if Amount > 0 then
			if Amount > i then
				set Amount = i
			endif
			if GetLocalPlayer(  ) == GetTriggerPlayer(  ) then
				call DisplayTextToPlayer( GetLocalPlayer(  ), 0, 0, "|Cfffed312Sent " + I2S( Amount ) + " gold to|r " + udg_Color[Target + 1] + GetPlayerName( Player( Target ) ) + "|r|Cfffed312.|r" )
			elseif GetLocalPlayer(  ) == Player( Target ) then
				call DisplayTextToPlayer( GetLocalPlayer(  ), 0, 0, "|Cfffed312Received " + I2S( Amount ) + " gold from|r " + udg_Color[GetPlayerId( GetTriggerPlayer(  ) ) + 1] + GetPlayerName( GetTriggerPlayer(  ) ) + "|r|Cfffed312.|r" )
			endif
			call SetPlayerState( GetTriggerPlayer(  ), PLAYER_STATE_RESOURCE_GOLD, i - Amount )
			call SetPlayerState( Player( Target ), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( Player( Target ), PLAYER_STATE_RESOURCE_GOLD ) + Amount )
		endif
	endif
endfunction

//===========================================================================
function InitTrig_Give takes nothing returns nothing
	local integer i = 0
	set gg_trg_Give = CreateTrigger(  )
	call TriggerAddCondition( gg_trg_Give, Condition( function Trig_Give_Conditions ) )
	call TriggerAddAction( gg_trg_Give, function Trig_Give_Actions )
	loop
		exitwhen i > 11
		call TriggerRegisterPlayerChatEvent( gg_trg_Give, Player(i), "-give ", false )
		set i = i + 1
	endloop
endfunction

Comments

0

No comments.