wc3edit.net

United Warcraft 3 map hacking!
It is currently January 24th, 2018, 7:15 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: June 4th, 2017, 12:38 pm 
Offline
Newcomer

Joined: June 14th, 2009, 2:31 am
Posts: 15
How can I change ownership of a selected unit by typing something like "-give color".

Let's say I want to give a unit of mine to player blue. So I type in the message "-give blue" and then the selected unit of mine is changed ownership to blue. However, only the player of that unit can change the ownership of that unit. So If I'm player red, I'm the only one that change my unit's ownership and no other players are able to change the ownership of my units.

Similar Example: So I want to give a unit of mine to player green, so I type in "give green" and the selected unit of mine is given to green.

How do I do this trigger in world editor?


Top
 Profile  
 
PostPosted: September 22nd, 2017, 11:50 am 
Offline
Newcomer

Joined: September 22nd, 2017, 2:37 am
Posts: 6
select unit and do -owner (color) , im using this


Top
 Profile  
 
PostPosted: September 23rd, 2017, 12:49 pm 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3775
Location: JEW LAND
Assuming you already have triggers on globals and have a way to enable the string comamnds. Here is what I would do in jass once the command is activated.

Code:
function PS2PID takes string s returns integer
    if (s=="red") then
        return 0
    elseif (s=="blue" then
        return 1
        //continue for all names
    endif
    return -1
endfunction

function gift_unit takes nothing returns nothing
    local string s=StringCase(GetEventPlayerChatString(),false)
    local group g=CreateGroup()
    local unit u
    //check target player
    local integer tar=PS2PID(SubString(s,6,StringLength(s)))
    //if cannot get target player - exit the function
    if (tar==-1) then
        return
    endif
    //go thourhg all the picked units
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        //check that you are giving your OWN unit
        if (GetOwningPlayer(u)==GetTriggerPlayer()) then
            call SetUnitOwner(u,Player(tar),true)
        endif
    endloop
    //fix memory leaks
    call DestroyGroup(g)
    set g=null
    set s=""
endfunction

didnt test it tough...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

phpBB SEO


Privacy Policy Statement
Impressum (German)