AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Need help for complied errors (https://forums.alliedmods.net/showthread.php?t=314691)

reid123455 03-03-2019 04:16

Need help for complied errors
 
Hello everyone!
Sorry for my bad English first.
And I've never written any plugin or program before.
I can only use C to print a Xmas tree in console. :oops:

But I want to give myself a big challenge, so I try to write a simple plugin by myself.

Here is my idea of this plugin:
I just want to restrict everyone's movement until warmup is end in CS:GO.

Here is my source code:
PHP Code:

#include <sourcemod>
#include <sdktools>


public Plugin:myinfo 
{
    
name "Warmup Waiting",
    
author "Reid",
    
description "Simple plugin for waiting other player's connecting by restricting movement",
    
version "0.01",
    
url ""
};

public 
OnPluginStart()
{
    
HookEvent("warmup_wating"OnWarmUp);
}


public 
OnWarmUp(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
userid GetEventInt(event"userid"); // Get player #userid from event
    
new client GetClientOfUserId(userid); // Get client index by #userid

    
new team GetClientTeam(client);
    new 
MaxClients GetConVarInt(FindConVar("maxplayers"));
    new 
GetWarmUpTime GetConVarInt(FindConVar("mp_warmuptime"));
    
    if(
team == || team == 3)
    {
        for (new 
1<= MaxClientsi++)
        {
            if (
IsClientInGame(i) && IsPlayerAlive(i))
            {
                
SetEntityMoveType(iMOVETYPE_NONE); 
            }
        }
        
        
PrintToChatAll(client"Please wait for other players connect.");
    }
    
    while(
GetWarmUpTime != 0//keep checking if wamrup time == 0
    
{    
        new 
GetWarmUpTime CreateTimer(GetWarmUpTime); //Sorry. I really don't understand CreateTimer().
    
}
    
    if(
GetWarmUpTime == 0)
    {
        for(new 
1<= MaxClientsi++)
        {
            if (
IsClientInGame(i) && IsPlayerAlive(i))
            {
                
SetEntityMoveType(iMOVETYPE_WALK); 
            }
        }
        
        
PrintToChatAll(client"Game is going to start!");
    }
    


Due to my bad logic, this is may be a terrible and horrible code :oops:
And I got these errors:
Code:

//// WarmupWaiting.sp
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(27) : warning 219: local variable "MaxClients" shadows a variable at a preceding level
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(40) : error 035: argument type mismatch (argument 1)
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(45) : warning 219: local variable "GetWarmUpTime" shadows a variable at a preceding level
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(45) : warning 213: tag mismatch
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(45) : error 092: number of arguments does not match definition
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(45) : warning 213: tag mismatch
// D:\Server\csgo server\csgo\addons\sourcemod\scripting\WarmupWaiting.sp(58) : error 035: argument type mismatch (argument 1)
//
// 3 Errors.

Can anyone help me to fix these errors? Thank you!

Nexd 03-03-2019 05:55

Re: Need help for complied errors
 
Code:

error 035: argument type mismatch (argument 1)
this is because you want to print something for every client, so you should do it in this way:
PHP Code:

PrintToChatAll("Please wait for other players connect."); 


asherkin 03-03-2019 06:09

Re: Need help for complied errors
 
PHP Code:

new MaxClients GetConVarInt(FindConVar("maxplayers")); 

Remove this line, MaxClients is a global variable managed by SM.

I suggesting looking at the timer documentation: https://wiki.alliedmods.net/Timers_(...Mod_Scripting)

XiLuo 03-03-2019 06:42

Re: Need help for complied errors
 
PHP Code:

#include <sourcemod> 
#include <sdktools> 


public Plugin:myinfo =  

    
name "Warmup Waiting"
    
author "Reid"
    
description "Simple plugin for waiting other player's connecting by restricting movement"
    
version "0.01"
    
url "" 
}; 

public 
OnPluginStart() 

    
HookEvent("warmup_wating"OnWarmUp); 



public 
OnWarmUp(Handle:event, const String:name[], bool:dontBroadcast
    { 
    new 
userid GetEventInt(event"userid"); // Get player #userid from event 
    
new client GetClientOfUserId(userid); // Get client index by #userid 

    
new team GetClientTeam(client); 

    
//MaxClient may needn't to get , this value has define by sm and is 64
    //new MaxClients = GetConVarInt(FindConVar("maxplayers")); 

    //Try not to repeat the definition
    
new getWarmUpTime GetConVarInt(FindConVar("mp_warmuptime")); //new GetWarmUpTime = GetConVarInt(FindConVar("mp_warmuptime")); 
     
    
if(team == || team == 3
    { 
        for (new 
1<= MaxClientsi++) 
        { 
            if (
IsClientInGame(i) && IsPlayerAlive(i)) 
            { 
                
SetEntityMoveType(iMOVETYPE_NONE);  
            } 
        } 
        
        
//stock PrintToChatAll(const String:format[], any:...)
        
PrintToChatAll("Please wait for other players connect."); //PrintToChatAll(client, "Please wait for other players connect."); 
    
}
     
    
//don‘t use 'while' simplly , may cause server crash,use timer
    /*while(GetWarmUpTime != 0) //keep checking if wamrup time == 0 
    {     
        new GetWarmUpTime = CreateTimer(GetWarmUpTime); //Sorry. I really don't understand CreateTimer(). 
    } */

    //create a timer that several seconds later will carry out the callback, parameter 1 is the second , callback method for 2 , Refer to official documentation for other details
    
CreateTimer(getWarmUpTime*1.0,WarmupTimeOver);
     
    
/*if(GetWarmUpTime == 0) 
    { 
        for(new i = 1; i <= MaxClients; i++) 
        { 
            if (IsClientInGame(i) && IsPlayerAlive(i)) 
            { 
                SetEntityMoveType(i, MOVETYPE_WALK);  
            } 
        } 
         
        PrintToChatAll(client, "Game is going to start!"); 
    }  */
}

//the callback method for CreateTimer
public Action:WarmupTimeOver(Handle:timer)
{
    for(new 
1<= MaxClientsi++) 
    { 
        if (
IsClientInGame(i) && IsPlayerAlive(i)) 
        { 
            
SetEntityMoveType(iMOVETYPE_WALK);  
        } 
    } 

    
PrintToChatAll("Game is going to start!"); 


Hei , though I fix some code , I'm not sure it can work well.
I just help fix code that some methods on using , I never wrote plugin for csgo ,just for l4d2 and with my now knowledge.
so hope my fix can work or give you little help.
Sorry for my poor English.

reid123455 03-03-2019 09:16

Re: Need help for complied errors
 
Quote:

Originally Posted by XiLuo (Post 2641717)
PHP Code:

#include <sourcemod> 
#include <sdktools> 


public Plugin:myinfo =  

    
name "Warmup Waiting"
    
author "Reid"
    
description "Simple plugin for waiting other player's connecting by restricting movement"
    
version "0.01"
    
url "" 
}; 

public 
OnPluginStart() 

    
HookEvent("warmup_wating"OnWarmUp); 



public 
OnWarmUp(Handle:event, const String:name[], bool:dontBroadcast
    { 
    new 
userid GetEventInt(event"userid"); // Get player #userid from event 
    
new client GetClientOfUserId(userid); // Get client index by #userid 

    
new team GetClientTeam(client); 

    
//MaxClient may needn't to get , this value has define by sm and is 64
    //new MaxClients = GetConVarInt(FindConVar("maxplayers")); 

    //Try not to repeat the definition
    
new getWarmUpTime GetConVarInt(FindConVar("mp_warmuptime")); //new GetWarmUpTime = GetConVarInt(FindConVar("mp_warmuptime")); 
     
    
if(team == || team == 3
    { 
        for (new 
1<= MaxClientsi++) 
        { 
            if (
IsClientInGame(i) && IsPlayerAlive(i)) 
            { 
                
SetEntityMoveType(iMOVETYPE_NONE);  
            } 
        } 
        
        
//stock PrintToChatAll(const String:format[], any:...)
        
PrintToChatAll("Please wait for other players connect."); //PrintToChatAll(client, "Please wait for other players connect."); 
    
}
     
    
//don‘t use 'while' simplly , may cause server crash,use timer
    /*while(GetWarmUpTime != 0) //keep checking if wamrup time == 0 
    {     
        new GetWarmUpTime = CreateTimer(GetWarmUpTime); //Sorry. I really don't understand CreateTimer(). 
    } */

    //create a timer that several seconds later will carry out the callback, parameter 1 is the second , callback method for 2 , Refer to official documentation for other details
    
CreateTimer(getWarmUpTime*1.0,WarmupTimeOver);
     
    
/*if(GetWarmUpTime == 0) 
    { 
        for(new i = 1; i <= MaxClients; i++) 
        { 
            if (IsClientInGame(i) && IsPlayerAlive(i)) 
            { 
                SetEntityMoveType(i, MOVETYPE_WALK);  
            } 
        } 
         
        PrintToChatAll(client, "Game is going to start!"); 
    }  */
}

//the callback method for CreateTimer
public Action:WarmupTimeOver(Handle:timer)
{
    for(new 
1<= MaxClientsi++) 
    { 
        if (
IsClientInGame(i) && IsPlayerAlive(i)) 
        { 
            
SetEntityMoveType(iMOVETYPE_WALK);  
        } 
    } 

    
PrintToChatAll("Game is going to start!"); 


Hei , though I fix some code , I'm not sure it can work well.
I just help fix code that some methods on using , I never wrote plugin for csgo ,just for l4d2 and with my now knowledge.
so hope my fix can work or give you little help.
Sorry for my poor English.


Thanks for all replys, and thanks for XiLuo's rewrote version as well.
It compiled successfully, but plugin failed to work
I found errors from log file
Code:

L 03/03/2019 - 20:16:54: [SM] Exception reported: Game event "warmup_waiting" does not exist
L 03/03/2019 - 20:16:54: [SM] Blaming: WarmupWaiting.smx
L 03/03/2019 - 20:16:54: [SM] Call stack trace:
L 03/03/2019 - 20:16:54: [SM]  [0] HookEvent
L 03/03/2019 - 20:16:54: [SM]  [1] Line 16, WarmupWaiting.sp::OnPluginStart
L 03/03/2019 - 20:16:54: [SM] Unable to load plugin "WarmupWaiting.smx": Error detected in plugin startup (see error logs)
L 03/03/2019 - 20:17:17: [SM] Exception reported: Script execution timed out

I thought maybe because I just misunderstood how to use HookEvent
So I decided to rewrite again.

PHP Code:

#include <sourcemod>
#include <sdktools>


public Plugin:myinfo 
{
    
name "Warmup Waiting",
    
author "Reid",
    
description "Simple plugin for waiting other player's connecting by restricting movement",
    
version "0.0.1",
    
url ""
};

public 
OnClientPutInServer(client)
{
    
//new team = GetClientTeam(client);
    
new GetWarmUpTime GetConVarInt(FindConVar("mp_warmuptime"));
    
CreateTimer(GetWarmUpTime*1.0,WarmUpOver); //let GetWarmUpTime be float and set WarmUpOver callback
    
    
for (new 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
SetEntityMoveType(iMOVETYPE_NONE); 
        }
    } 
    
    
PrintToChat(client"Please wait for other players connect.");
}

public 
Action:WarmUpOver(Handle:timerany:client)
{
    for(new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
SetEntityMoveType(iMOVETYPE_WALK); 
        }
    }
    
PrintToChat(client"Game is going to start!");


This version complied successfully and didn't get any errors.
But Players still can move or go around when warmup.
I don't know why, guess I misunderstand SetEntityMoveType() function again?
By the way, I found this function from here
https://forums.alliedmods.net/showthread.php?t=273053

impossible_cc 03-03-2019 12:20

Re: Need help for complied errors
 
I did not test it, but it should work.

I changed your logic actually, I'm sorry if it is a bit difficult for you.
Also I prefer new syntax, it is more familiar to me, because it is closer to 'C' syntax :)
Feel free to ask questions


PHP Code:

#include <sourcemod> 
//#include <sdktools> 


public Plugin myinfo =  

    
name "Warmup Waiting"
    
author "Reid"
    
description "Simple plugin for waiting other player's connecting by restricting movement"
    
version "0.0.1"
    
url "" 
};

public 
void OnMapStart() 

    
//new GetWarmUpTime = GetConVarInt(FindConVar("mp_warmuptime")); 
    //CreateTimer(GetWarmUpTime*1.0,WarmUpOver); //let GetWarmUpTime be float and set WarmUpOver callback 
    
    
float GetWarmUpTime = (FindConVar("mp_warmuptime")).FloatValue
    if(
GetWarmUpTime 0.0)
    {
        
HookEvent("player_spawn"OnPlayerSpawnEventHookMode_Post);
        
        
CreateTimer(GetWarmUpTime,WarmUpOver);
    }


public 
void OnPlayerSpawn(Event event, const char[] namebool dontBroadcast
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    if(
IsClientInGame(client) && IsPlayerAlive(client))
    {
        
SetEntityMoveType(clientMOVETYPE_NONE);  
    }
    
    
PrintCenterText(client"Please wait for other players connect"); 
    
PrintToChat(client"Please wait for other players connect."); 


public 
Action WarmUpOver(Handle timer
{
    
UnhookEvent("player_spawn"OnPlayerSpawnEventHookMode_Post);        //We don't need it anymore, so unhook.
    
    
for(int i 1<= MaxClientsi++) 
    { 
        if (
IsClientInGame(i) && IsPlayerAlive(i)) 
        { 
            
SetEntityMoveType(iMOVETYPE_WALK);  
        } 
    }
    
    
PrintCenterTextAll("Game is going to start!"); 
    
PrintToChatAll("Game is going to start!"); 



Cruze 03-03-2019 12:23

Re: Need help for complied errors
 
1 Attachment(s)
Compile it here!
Untested

Nexd 03-03-2019 15:08

Re: Need help for complied errors
 
PHP Code:

if (GameRules_GetProp("m_bWarmupPeriod") == 1

edit: sry, i haven't downloaded cruze's code before

reid123455 03-04-2019 06:50

Re: Need help for complied errors
 
Quote:

Originally Posted by Cruze (Post 2641778)

Wow, thanks a lot.
I really appreciate it, it's working perfectly.
But I still don't understand why I get errors if using my compiler. :shock:

impossible_cc's version can be compiled in this website, but plugin still failed to work
without any errors.

But thank you guys. I've learned a lot from these threads. :)

Cruze 03-04-2019 06:52

Re: Need help for complied errors
 
Quote:

Originally Posted by reid123455 (Post 2641878)
Wow, thanks a lot.
I really appreciate it, it's working perfectly.
But I still don't understand why I get errors if using my compiler. :shock:

impossible_cc's version can be compiled in this website, but plugin still failed to work
without any errors.

But thank you guys. I've learned a lot from these threads. :)

Use SM 1.9 latest build to compile


All times are GMT -4. The time now is 05:46.

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