AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Argument Mismatch + Invalid Expression (https://forums.alliedmods.net/showthread.php?t=154862)

Cyb3rH4Xter 04-14-2011 11:28

Argument Mismatch + Invalid Expression
 
I have edited a plugin that enables RTV for another plugin, but now I am getting a few errors when compiling this code:

Code:

/*
 *    RockTheVote for Polymorph
 *    Requires Polymorph v0.8.2 or later
 *
 */

#include <amxmodx>
#include <amxmisc>
// #include <polymorph>

native polyn_votemod()

new bool:g_rockedVote[33], g_rockedVoteCnt
new bool:g_hasbeenrocked = false
new RoundCount;

// Cvars
new cvar_rtv_enabled
new cvar_rtv_ratio
new cvar_rtv_show

public plugin_init()
{
    register_plugin("Polymorph: RockTheVote", "1.0", "Fysiks")
   
    register_clcmd("amx_rtv","cmdAdminRTV", ADMIN_MAP, " Manually RockTheVote")
    register_clcmd("admin_rtv","cmdAdminRTV", ADMIN_MAP, " Manually RockTheVote")
    register_clcmd("say rtv", "cmdSayRTV")
    register_clcmd("say rockthevote", "cmdSayRTV")
   
    register_logevent("logevent_RoundStart", 2, "1=Round_Start");
   
    // Cvars
    cvar_rtv_enabled = register_cvar("rtv_enable", "1")    // <0|1>
    cvar_rtv_ratio = register_cvar("rtv_ratio", "0.51")        // Use amx_votemap_ratio?
    cvar_rtv_show = register_cvar("rtv_show", "1")        // Display how many more votes needed to rtv
}

public logevent_RoundStart() {
    RoundCount++;
}

public cmdAdminRTV(id, level, cid)
{
    if(!cmd_access(id,level,cid,1))
        return PLUGIN_HANDLED
   
    if(g_hasbeenrocked)
    {
        client_print(id,print_console,"[RTV] Vote has already been rocked")
    }
    else
    {
        g_hasbeenrocked = true
        new admin_name[32]
        get_user_name(id, admin_name, 31)
        show_activity(id, admin_name, "has RockedTheVote")
        client_print(id,print_console, "[RTV] You have RockedTheVote")
        set_task(3.5,"announce_vote")
        set_task(5.0,"startRockVote")
    }
    // Add functionality to cancel rocked vote.
    return PLUGIN_HANDLED
}

public client_connect(id)
{
    g_rockedVote[id] = false
}

public client_disconnect(id)
{
    if(g_rockedVote[id])
    {
        g_rockedVote[id] = false
        g_rockedVoteCnt--
    }
}

public cmdSayRTV(id)
{
    if(!get_pcvar_num(cvar_rtv_enabled))
        return PLUGIN_CONTINUE // PLUGIN_HANDLED
   
    if(g_hasbeenrocked)
    {
        client_print(id, print_chat, "[RTV] Vote has already been Rocked.")
        return PLUGIN_HANDLED
    }
   
    if(g_rockedVote[id])
    {
        client_print(id, print_chat, "[RTV] You already voted.")
        rtv_remind()
        return PLUGIN_CONTINUE  // PLUGIN_HANDLED for blind?
    }
   
    if( get_pcvar_float("mp_timelimit") != 0 )
    {
        if(get_timeleft() < 240 ) // don't allow rtv 4 minutes before map ends
        {
            client_print(id, print_chat, "[RTV] Too Late to RockTheVote.")
            return PLUGIN_HANDLED
        }
    }
    else if( get_pcvar_float("mp_maxrounds") != 0 )
    {
        new Float:roundsLeft = get_pcvar_float("mp_maxrounds") - RoundCount
       
        if( roundsLeft <= 4) ) // don't allow rtv 4 rounds before map ends
        {
            client_print(id, print_chat, "[RTV] Too Late to RockTheVote.")
            return PLUGIN_HANDLED
        }
    }
   
    // You (id) just voted to rock.
    g_rockedVote[id] = true
    g_rockedVoteCnt++
    client_print(id,print_chat, "[RTV] You chose to RockTheVote")
   
    if( g_rockedVoteCnt >= get_RocksNeeded() )    // Decide if we rock the vote
    {
        g_hasbeenrocked = true
        client_print(0,print_chat, "[RTV] The Vote has been Rocked!")
        set_task(3.5,"announce_vote")
        set_task(5.0,"startRockVote")
    }
    else
    {
        rtv_remind()
    }
   
    return PLUGIN_CONTINUE
}

public startRockVote()
{
    polyn_votemod()
}

get_RocksNeeded()
{
    return floatround(get_pcvar_float(cvar_rtv_ratio) * float(get_realplayersnum()), floatround_ceil);
}

stock get_realplayersnum()
{
    new players[32], playerCnt;
    get_players(players, playerCnt, "ch");
   
    return playerCnt;
}

rtv_remind()
{
    if(get_pcvar_num(cvar_rtv_show))
    {  // Not tested yet.
        client_print(0,print_chat, "[RTV] Need %d more players to RockTheVote.", get_RocksNeeded() - g_rockedVoteCnt)
    }
}

public announce_vote()
{
    client_cmd(0, "spk buttons/blip2")  // Moved here from startRockVote to give heads up
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1053{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/

The errors are on line 98, 106, 108, 110.
Would be awesome if somebody told me whats wrong. Am a newbie pawn coder, normally a C# coder :)

kotinha 04-14-2011 11:41

Re: Argument Mismatch + Invalid Expression
 
PHP Code:

/*
 *    RockTheVote for Polymorph
 *    Requires Polymorph v0.8.2 or later
 *
 */

#include <amxmodx>
#include <amxmisc>
// #include <polymorph>

native polyn_votemod()

new 
bool:g_rockedVote[33], g_rockedVoteCnt
new bool:g_hasbeenrocked false
new RoundCount;

// Cvars
new cvar_rtv_enabled
new cvar_rtv_ratio
new cvar_rtv_show

public plugin_init()
{
    
register_plugin("Polymorph: RockTheVote""1.0""Fysiks")
    
    
register_clcmd("amx_rtv","cmdAdminRTV"ADMIN_MAP" Manually RockTheVote")
    
register_clcmd("admin_rtv","cmdAdminRTV"ADMIN_MAP" Manually RockTheVote")
    
register_clcmd("say rtv""cmdSayRTV")
    
register_clcmd("say rockthevote""cmdSayRTV")
    
    
register_logevent("logevent_RoundStart"2"1=Round_Start");
    
    
// Cvars
    
cvar_rtv_enabled register_cvar("rtv_enable""1")    // <0|1>
    
cvar_rtv_ratio register_cvar("rtv_ratio""0.51")        // Use amx_votemap_ratio?
    
cvar_rtv_show register_cvar("rtv_show""1")        // Display how many more votes needed to rtv
}

public 
logevent_RoundStart() {
    
RoundCount++;
}

public 
cmdAdminRTV(idlevelcid)
{
    if(!
cmd_access(id,level,cid,1))
        return 
PLUGIN_HANDLED
    
    
if(g_hasbeenrocked)
    {
        
client_print(id,print_console,"[RTV] Vote has already been rocked")
    }
    else
    {
        
g_hasbeenrocked true
        
new admin_name[32]
        
get_user_name(idadmin_name31)
        
show_activity(idadmin_name"has RockedTheVote")
        
client_print(id,print_console"[RTV] You have RockedTheVote")
        
set_task(3.5,"announce_vote")
        
set_task(5.0,"startRockVote")
    }
    
// Add functionality to cancel rocked vote.
    
return PLUGIN_HANDLED
}

public 
client_connect(id)
{
    
g_rockedVote[id] = false
}

public 
client_disconnect(id)
{
    if(
g_rockedVote[id])
    {
        
g_rockedVote[id] = false
        g_rockedVoteCnt
--
    }
}

public 
cmdSayRTV(id)
{
    if(!
get_pcvar_num(cvar_rtv_enabled))
        return 
PLUGIN_CONTINUE // PLUGIN_HANDLED
    
    
if(g_hasbeenrocked)
    {
        
client_print(idprint_chat"[RTV] Vote has already been Rocked.")
        return 
PLUGIN_HANDLED
    
}
    
    if(
g_rockedVote[id])
    {
        
client_print(idprint_chat"[RTV] You already voted.")
        
rtv_remind()
        return 
PLUGIN_CONTINUE  // PLUGIN_HANDLED for blind?
    
}
    
    if( 
get_pcvar_num("mp_timelimit") != )
    {
        if(
get_timeleft() < 240 // don't allow rtv 4 minutes before map ends
        
{
            
client_print(idprint_chat"[RTV] Too Late to RockTheVote.")
            return 
PLUGIN_HANDLED
        
}
    }
    else if( 
get_pcvar_num("mp_maxrounds") != )
    {
        new 
Float:roundsLeft get_pcvar_num("mp_maxrounds") - RoundCount
        
        
if( roundsLeft <= // don't allow rtv 4 rounds before map ends
        
{
            
client_print(idprint_chat"[RTV] Too Late to RockTheVote.")
            return 
PLUGIN_HANDLED
        
}
    }
    
    
// You (id) just voted to rock.
    
g_rockedVote[id] = true
    g_rockedVoteCnt
++
    
client_print(id,print_chat"[RTV] You chose to RockTheVote")
    
    if( 
g_rockedVoteCnt >= get_RocksNeeded() )     // Decide if we rock the vote
    
{
        
g_hasbeenrocked true
        client_print
(0,print_chat"[RTV] The Vote has been Rocked!")
        
set_task(3.5,"announce_vote")
        
set_task(5.0,"startRockVote")
    }
    else
    {
        
rtv_remind()
    }
    
    return 
PLUGIN_CONTINUE
}

public 
startRockVote()
{
    
polyn_votemod()
}

get_RocksNeeded()
{
    return 
floatround(get_pcvar_float(cvar_rtv_ratio) * float(get_realplayersnum()), floatround_ceil);
}

stock get_realplayersnum()
{
    new 
players[32], playerCnt;
    
get_players(playersplayerCnt"ch");
    
    return 
playerCnt;
}

rtv_remind()
{
    if(
get_pcvar_num(cvar_rtv_show))
    {  
// Not tested yet.
        
client_print(0,print_chat"[RTV] Need %d more players to RockTheVote."get_RocksNeeded() - g_rockedVoteCnt)
    }
}

public 
announce_vote()
{
    
client_cmd(0"spk buttons/blip2")  // Moved here from startRockVote to give heads up
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1053{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/ 


SpeeDeeR 04-14-2011 11:42

Re: Argument Mismatch + Invalid Expression
 
Code:

get_pcvar_float("mp_timelimit")
:arrow:
Code:

get_cvar_pointer("mp_timelimit")
Code:

new Float:roundsLeft = get_cvar_pointer("mp_maxrounds") - RoundCount
       
        if( roundsLeft <= 4) )

:arrow:
Code:

new roundsLeft = get_cvar_pointer("mp_maxrounds") - RoundCount
       
        if( roundsLeft <= 4)

Another thing is that you check if a float value is other than an integer.

Cyb3rH4Xter 04-14-2011 11:54

Re: Argument Mismatch + Invalid Expression
 
Great, fix those 2 things. Now I only have one error a a warning left at this area:

PHP Code:

        new Float:roundsLeft get_cvar_pointer("mp_maxrounds") - RoundCount
        
        
if( roundsLeft <= 4.0) ) // don't allow rtv 4 rounds before map ends
        
{
            
client_print(idprint_chat"[RTV] Too Late to RockTheVote.")
            return 
PLUGIN_HANDLED
        


The error and warning is on the if (roundsLeft..... line.
Its a tag mismatch and a invalid expression :S

kotinha 04-14-2011 11:59

Re: Argument Mismatch + Invalid Expression
 
I corrected you wrongly up there :stupid:

You didn't remove the ) from this:
PHP Code:

if( roundsLeft <= 4.0) ) 


Cyb3rH4Xter 04-14-2011 12:25

Re: Argument Mismatch + Invalid Expression
 
Oops missed that one, now there is just one error left:
Tag mismatch at the same line:

PHP Code:

        new Float:roundsLeft get_cvar_pointer("mp_maxrounds") - RoundCount
        
        
if( roundsLeft <= 4.0 // don't allow rtv 4 rounds before map ends 

Awesome fast help here :D

SpeeDeeR 04-14-2011 12:26

Re: Argument Mismatch + Invalid Expression
 
Quote:

Originally Posted by SpeeDeeR (Post 1449479)
Code:

new Float:roundsLeft = get_cvar_pointer("mp_maxrounds") - RoundCount
       
        if( roundsLeft <= 4) )

:arrow:
Code:

new roundsLeft = get_cvar_pointer("mp_maxrounds") - RoundCount
       
        if( roundsLeft <= 4)


You check if a float value is less or equal to an integer one and that triggers tag mismatch BECAUSE ITS WRONG.
You really code C# ?

kotinha 04-14-2011 12:27

Re: Argument Mismatch + Invalid Expression
 
nvm, SpeedDeeR posted it first lol

Cyb3rH4Xter 04-14-2011 12:51

Re: Argument Mismatch + Invalid Expression
 
Quote:

Originally Posted by SpeeDeeR (Post 1449509)
You check if a float value is less or equal to an integer one and that triggers tag mismatch BECAUSE ITS WRONG.
You really code C# ?

Yes I code C#, maybe I am not that experienced in it but I have written 2300 lines in my current project and it works well, but usually I am used a easier-to-use debugger and why I wrote that is because I know there are differences in these 2 languages. For example I tried to declare an int but there was no such thing so I went with float. Apparently it becomes an int if you don't specify any type lol. Secondly, of course I know you can't match one type of variable with one of another type, but how the heck should I know how to convert an int to a float if I never coded pawn before?

SpeeDeeR 04-14-2011 13:01

Re: Argument Mismatch + Invalid Expression
 
Code Snippets/Tutorials

new a > int
new a[32] > string
new Array:a[32] > array
new Float:a > float
new bool:a > bool
new const a[] > const
new Trie:a > trie


All times are GMT -4. The time now is 19:53.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.