• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Easy code i got problems with..

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
allright... i guess its kind of embercaing..
but i cant figure why wont this work?
maybe its because of the gui convertion of player 1 = 1, and in jass its player 1 = 0? i have no idea.. but it wont work.
heres the 2 codes:


JASS:
library VoteKickStart initializer INIT
    globals
        
        public          boolean array  PlayerIsVoted
        public          boolean        VoteIsOn
        private         integer        AmountOfPlayers
        public          integer        PlayerNum
        
    endglobals
private function Actions takes nothing returns nothing
    local integer i = 0
    
    loop

    //if GetPlayerSlotState(ConvertedPlayer((i))) == PLAYER_SLOT_STATE_PLAYING and ConvertedPlayer((i)) == MAP_CONTROL_USER then
        
        set AmountOfPlayers = AmountOfPlayers + 1
        
   //endif
    
    set i = i + 1
    exitwhen i >= 11
    endloop
    
    if VoteIsOn == false then
        
        if AmountOfPlayers >= 4 then
                
                set VoteIsOn = true
                set PlayerIsVoted[S2I(SubString(GetEventPlayerChatString(), 10, 12))] = true
                set PlayerNum = GetPlayerId(Player(S2I(SubString(GetEventPlayerChatString(), 10, 12))))
        endif
        
    endif
    
endfunction

//===========================================================================
private function INIT takes nothing returns nothing
    local trigger VK = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( VK, Player(0), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(1), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(2), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(3), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(4), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(5), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(6), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(7), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(8), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(9), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(10), "-votekick", false )
    call TriggerRegisterPlayerChatEvent( VK, Player(11), "-votekick", false )
    call TriggerAddAction( VK, function Actions )
    set VK = null
endfunction
endlibrary

JASS:
library VoteKickCast initializer INIT
    
    globals
        
        private     boolean array    PlayerHasVoted
        private     integer          VoteCount
        private     string           PlayerName
        
    endglobals
    
private function Actions takes nothing returns nothing
    
    if VoteKickStart_VoteIsOn == true then
        
        if VoteKickStart_PlayerIsVoted[GetPlayerId(GetTriggerPlayer())] == false then
            
            if PlayerHasVoted[GetPlayerId(GetTriggerPlayer())] == false then
                
                set VoteCount = VoteCount + 1
                set PlayerName = GetPlayerName(GetTriggerPlayer())
                call DisplayTimedTextToForce(GetPlayersAll(), 10, PlayerName + " Has voted against " + GetPlayerName(Player(VoteKickStart_PlayerNum)))
                
            endif
            
        endif
        
    endif
endfunction

//===========================================================================
function INIT takes nothing returns nothing
    local trigger VK = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( VK, Player(0), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(1), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(2), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(3), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(4), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(5), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(6), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(7), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(8), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(9), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(10), "-yes", true )
    call TriggerRegisterPlayerChatEvent( VK, Player(11), "-yes", true )
    call TriggerAddAction( VK, function Actions )
    set VK = null
endfunction
endlibrary


thanks in advance.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
What do you have: GetPlayerId(Player(S2I(SubString(GetEventPlayerChatString(), 10, 12)))) for?

You're converting an ID to a player and then back to an ID, you can save a step:

JASS:
S2I(SubString(GetEventPlayerChatString(), 10, 12))

Other than that you need to give a description of what exactly won't work.
 
Notice that position 10-12 is in fact 11-13 when you type it.
"1234567890ABCDEFG"... - Will be "A-C", not "0-B".
This is because everything in JASS starts with 0 as index.

Player 1 (GUI) = Player 0 (JASS).
Basically, what you do are two mistakes.

And also, if you ignore my message once more, I will stop helping you.
Try to learn debugging your code to see whether it works or not, and then post it here.
 
Level 10
Joined
Jun 26, 2005
Messages
236
Brother, it never leaves the loop. You can't do "set AmountOfPlayers = AmountOfPlayers + 1" if you never gave the variable a value, so set it to 0 in the global block.

EDIT: You also didn't set VoteIsOn to false in the global block, so it can never enter the if-statement aswell...
EDIT2: Also it will only work once, since once the vote is over you never set VoteIsOn back to false.
EDIT3: Anachron, his SubString is fine... "-votekick 1" == "012345678910", the 1 is the 10. HOWEVER, when you type "-votekick 1" it's going to return player 1 (blue), when you need to return player 0 (red).
EDIT4: Sorry - I just noticed that you don't check if it's an invalid player... so someone can do "-votekick 20" and cause a fatal error...
 
Last edited:
JASS:
library VoteKickCast initializer init
    
    // Three types of votes:
    
    // -vote kick 12
    //     Kicks brown (player 11)
    // -vote yes
    //     Approves of the vote
    // -vote no
    //     Cancels the vote if it's typed by someone other than the one being
    //     voted against.
    
    globals
        private player          s_target        = null 
        private integer         s_votes         = 0
        private integer         s_total         = 0
        private boolean array   a_voted
    endglobals
    
    // From Bribe --
    // 
    // You only need one library.
    // You don't need == true.  Use "if bool then"
    // You don't need == false. Use "if not bool then"
    // Don't use DisplayTimedTextToForce(GetPlayersAll()), use
    //     DisplayTimedTextToPlayer(GetLocalPlayer()).
    // Don't create a bunch of events in a line, it's a waste of text and
    //     makes your map size larger, one reason why there are loops.
    
    private function ishuman takes player p returns boolean
        return (GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER)
    endfunction
    
    private function counthumans takes nothing returns integer
        set set s_total = 0
        loop
            if (ishuman(Player(i))) then
                set s_total = s_total + 1
            endif
            exitwhen i == 11
            set i = i + 1
        endloop
    endfunction
    
    private function clearvotes takes nothing returns nothing
        local integer i = 0
        set s_target = null
        set s_votes = 0
        loop
            set a_voted[i] = false
            exitwhen i == 11
            set i = i + 1
        endloop
    endfunction
    
    private function onChat takes nothing returns boolean
        local integer i = 0
        local player p = GetTriggerPlayer()
        local string s = GetEventPlayerChatString()
        local string t = SubString(s, 6, 7)
        
        if ((t == "ki") and (s_target == null)) then
            
            // Typed "-vote kick " followed by a number.
            
            set i = S2I(SubString(s, 11, 12))
            
            if (i > 0 and i < 13) then
                set s_target = Player(i - 1)
            endif
            
        elseif ((target != null) (p != s_target)) then
            
            // Don't allow the targetted player to vote for himself.
            
            if ((t == "ye") and not (a_voted[GetPlayerId(p)])) then
                
                // Typed "-vote yes"
                
                set i = counthumans()
                
                if (i > 2 and s_votes + 2 == i) then
                    call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(s_target) + " was voted out of the game!")
                    call clearvotes()
                else
                    call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(p) + " has voted against " + GetPlayerName(s_target) + "!")
                    
                    set s_votes = s_votes + 1
                    set a_voted[GetPlayerId(p)] = true
                endif
                
            elseif (t == "no") then
                
                // Typed "-vote no"
                
                call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(p) + " has saved " + GetPlayerName(s_target) + " from being voted out!")
                call clearvotes()
            endif
        else
            
            // Typed "-vote " followed by something invalid
            
            call DisplayTextToPlayer(p, 0.00, 0.00, "Invalid vote command.")
        endif
    endfunction

    //=======================================================================
    private function init takes nothing returns nothing // "init" must be PRIVATE.
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            if (ishuman(Player(i))) then
                set s_total = s_total + 1
                call TriggerRegisterPlayerChatEvent(t, Player(i), "-vote ", false)
            endif
            exitwhen i == 11
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Condition(function onChat))
    endfunction
    
endlibrary
 
Last edited:
Level 11
Joined
Sep 12, 2008
Messages
657
kk.. actually.. whenever i stop looking on it.. means i cant.. right?
my comp crushed.. so i cant do much atm. ill read everything more deeply when i get it back. right now im using laptop/my bro's comp..
and anarchon.. belive me.. i dont have much time to breath atm..
sry for ignoring you'r posts.
 
Status
Not open for further replies.
Top