Raised This Month: $ Target: $400
 0% 

Plugin Crashes TF2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
klashfire
Member
Join Date: May 2014
Location: NY, USA
Old 04-08-2016 , 14:41   Plugin Crashes TF2
Reply With Quote #1

(well, actually the server. Not the game itself.)
yeah, I kind of know why, even before I tested it, but I need a better alternative.
The plugin is not yet complete, but should be functional.

The plugin's purpose is to set a HUD element based timer for whatever purpose the player needs it for.

PHP Code:
#pragma semicolon 1

#include <sourcemod>

public void OnPluginStart() {
    
RegAdminCmd("sm_timer"Command_SetTimerADMFLAG_SLAY"Set a timer countdown.");
}

public 
Action Command_SetTimer(clientargs) {

    
char arg1[32];
    
char arg2[32];
    
char TimerResult[128];
    
    if (
args || args 3) {
        
ReplyToCommand(client"[SM] Usage: sm_timer <minutes> <seconds> (<timer result>)");
        return 
Plugin_Handled;
    }
    
    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));
    
    
int Minutes StringToInt(arg1);
    
int Seconds StringToInt(arg2);
    
    
GetCmdArg(3TimerResultsizeof(TimerResult));
    
    if (
Seconds 60 || Seconds || Minutes || Minutes 60) {
        
ReplyToCommand(client"[SM] Seconds and Minutes must be an intiger value between 0 and 60");
        return 
Plugin_Handled;
    }
    
    
int oldTime GetTime();

    
int timerTime Seconds + (Minutes 60);
    
    for (
int i 0oldTime <= timerTimeGetTime()) {
        if (
oldTime == 60) {
            
oldTime += 60;
            
Minutes--;
        }
        
        
Seconds = (timerTime - (oldTime)) % 60;
        
        
PrintCenterText(client"%d:%d"MinutesSeconds);
    }

    
    return 
Plugin_Handled;

The plugin crashes tf2 most likely by the constant spam of PrintCentertext() in the for loop.
Can someone give me a good alternative that wouldn't present constant spam or at least not crash TF2?


P.S. checking if a second has passed before using PrintCenterText() might work, but I'm not quite sure.
EDIT: nope. That didn't help. Same result.
__________________


Last edited by klashfire; 04-08-2016 at 14:51.
klashfire is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 04-08-2016 , 15:07   Re: Plugin Crashes TF2
Reply With Quote #2

A for loop is not asynchronous, so while you are looping everything else is blocked.

Repeatable Timers

Create a repeatable timer with a 1 second interval, and PrintCenterText until the time has passed.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
klashfire
Member
Join Date: May 2014
Location: NY, USA
Old 04-08-2016 , 17:38   Re: Plugin Crashes TF2
Reply With Quote #3

Quote:
Originally Posted by DJ Tsunami View Post
A for loop is not asynchronous, so while you are looping everything else is blocked.

Repeatable Timers

Create a repeatable timer with a 1 second interval, and PrintCenterText until the time has passed.
It seems I have no idea what I'm doing. Any help with this?
PHP Code:
#pragma semicolon 1

#include <sourcemod>

public void OnPluginStart() {
    
RegAdminCmd("sm_timer"Command_SetTimerADMFLAG_SLAY"Set a timer countdown.");
}

public 
Action Command_SetTimer(clientargs) {

    
char arg1[32];
    
char arg2[32];
    
char TimerResult[128];
    
    if (
args || args 3) {
        
ReplyToCommand(client"[SM] Usage: sm_timer <minutes> <seconds> (<timer result>)");
        return 
Plugin_Handled;
    }
    
    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));
    
    
Minutes StringToInt(arg1);
    
Seconds StringToInt(arg2);
    
    
GetCmdArg(3TimerResultsizeof(TimerResult));
    
    if (
Seconds 60 || Seconds || Minutes || Minutes 60) {
        
ReplyToCommand(client"[SM] Seconds and Minutes must be an intiger value between 0 and 60");
        return 
Plugin_Handled;
    }
    
    
timerTime Seconds + (Minutes 60);
    
    
CreateTimer(1.0Timer_ShowTimeLeft_TIMER_REPEAT);
    
    
    return 
Plugin_Handled;
}

public 
Action Timer_ShowTimeLeft(Handle timer)
{
    
// Create a global variable visible only in the local scope (this function).
    
static int secondCounter 0;
    static 
int minuteHandler 0;
 
    if (
secondCounter >= timerTime) {
        
secondCounter 0;
        return 
Plugin_Stop;
    }
    if (
MinuteHandler == 60) {
        
Minutes--;
        
minuteHandler 0;
    }
    if (
Seconds 1) {
        
Seconds 60;
    }
    
    
PrintCenterTextAll("%d:%d"MinutesSeconds)
    
secondCounter++;
    
MenuHandler++;
    
Seconds--;
    return 
Plugin_Continue;

got 11 errors:
Code:
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(23) : error 008: must be a constant expression; assumed zero
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(24) : error 008: must be a constant expression; assumed zero
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(33) : error 008: must be a constant expression; assumed zero
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(33) : warning 203: symbol is never used: "timerTime"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(47) : error 017: undefined symbol "timerTime"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(51) : error 017: undefined symbol "MinuteHandler"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(52) : error 017: undefined symbol "Minutes"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(52) : warning 215: expression has no effect
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(55) : error 017: undefined symbol "Seconds"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(56) : error 017: undefined symbol "Seconds"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(56) : warning 215: expression has no effect
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(59) : error 017: undefined symbol "Minutes"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(61) : error 017: undefined symbol "MenuHandler"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(61) : warning 215: expression has no effect
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(62) : error 017: undefined symbol "Seconds"
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(62) : warning 215: expression has no effect
/home/groups/sourcemod/upload_tmp/phps5XZ5w.sp(53) : warning 204: symbol is assigned a value that is never used: "minuteHandler"
__________________

klashfire is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 04-08-2016 , 18:02   Re: Plugin Crashes TF2
Reply With Quote #4

I'm not familiar with the new syntax due to lazyness...

But half of the errors is self explained and

PHP Code:
    Minutes StringToInt(arg1);
    
Seconds StringToInt(arg2); 
Minutes and Seconds integers ain't defined anywhere in the code causing the:

Code:
error 017: undefined symbol "Minutes"
error 017: undefined symbol "Seconds"
__________________
xines is offline
klashfire
Member
Join Date: May 2014
Location: NY, USA
Old 04-08-2016 , 18:39   Re: Plugin Crashes TF2
Reply With Quote #5

Quote:
Originally Posted by xines View Post
I'm not familiar with the new syntax due to lazyness...

But half of the errors is self explained and

PHP Code:
    Minutes StringToInt(arg1);
    
Seconds StringToInt(arg2); 
Minutes and Seconds integers ain't defined anywhere in the code causing the:

Code:
error 017: undefined symbol "Minutes"
error 017: undefined symbol "Seconds"
yeah, I just edited it back to that when posting since I went through an unnecessary code fix. there was actually an 'int' before them, still returning the same error.

and yeah, I am not so familiar either with the new syntax, but a guy urged me to use it instead of the old one.

I believe most of the errors there are due to inconsistencies between global and local scope variables. Can you recommend a fix?
__________________

klashfire is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 04-08-2016 , 20:40   Re: Plugin Crashes TF2
Reply With Quote #6

Quote:
Originally Posted by klashfire View Post
Can you recommend a fix?
This is tested and works on CSS, so give it a shot.

Guess this is more than the fix you requested:

PHP Code:
#pragma semicolon 1
#include <sourcemod>

int Minutes,
    
Seconds,
    
TimerTime,
    
SecondCounter 0;

char TimerResult[128],
    
arg1[32],
    
arg2[32];
    
bool TimerRunning;

public 
void OnPluginStart() 
{
    
RegAdminCmd("sm_timer"Command_SetTimerADMFLAG_SLAY"Set a timer countdown.");
}

public 
Action Command_SetTimer(clientargs
{    
    if (
args || args 3) {
        
ReplyToCommand(client"[SM] Usage: sm_timer <minutes> <seconds> (<timer result>)");
        return 
Plugin_Handled;
    }
    
    if (
TimerRunning == false) { //check if timer aint running
        
TimerRunning true;
    }
    else {
        
ReplyToCommand(client"[SM] Timer is already running, so you can't start a new one.");
        return 
Plugin_Handled;
    }
    
    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));
    
GetCmdArg(3TimerResultsizeof(TimerResult));
    
    
Minutes StringToInt(arg1);
    
Seconds StringToInt(arg2);
    
    if (
Seconds 60 || Seconds || Minutes || Minutes 60) {
        
ReplyToCommand(client"[SM] Seconds and Minutes must be an intiger value between 0 and 60");
        return 
Plugin_Handled;
    }
    
    
TimerTime Seconds + (Minutes 60);

    
CreateTimer(1.0Timer_ShowTimeLeft_TIMER_REPEAT);

    return 
Plugin_Handled;
}

public 
Action Timer_ShowTimeLeft(Handle timer)
{
    if (
SecondCounter >= TimerTime) {
        
SecondCounter 0;
        
PrintToChatAll("%s"TimerResult); // print whatever stored in arg 3, when timer is done
        
TimerRunning false// set to false for new timer to be ready for use
        
return Plugin_Stop;
    }
    if (
Minutes && Seconds 1) {
        
Minutes--;
        
Seconds 60;
    }
    
    
PrintCenterTextAll("%d:%d"MinutesSeconds);
    
SecondCounter++;
    
Seconds--;
    return 
Plugin_Continue;

__________________
xines is offline
klashfire
Member
Join Date: May 2014
Location: NY, USA
Old 04-09-2016 , 21:47   Re: Plugin Crashes TF2
Reply With Quote #7

Quote:
Originally Posted by xines View Post
This is tested and works on CSS, so give it a shot.

Guess this is more than the fix you requested:

PHP Code:
#pragma semicolon 1
#include <sourcemod>

int Minutes,
    
Seconds,
    
TimerTime,
    
SecondCounter 0;

char TimerResult[128],
    
arg1[32],
    
arg2[32];
    
bool TimerRunning;

public 
void OnPluginStart() 
{
    
RegAdminCmd("sm_timer"Command_SetTimerADMFLAG_SLAY"Set a timer countdown.");
}

public 
Action Command_SetTimer(clientargs
{    
    if (
args || args 3) {
        
ReplyToCommand(client"[SM] Usage: sm_timer <minutes> <seconds> (<timer result>)");
        return 
Plugin_Handled;
    }
    
    if (
TimerRunning == false) { //check if timer aint running
        
TimerRunning true;
    }
    else {
        
ReplyToCommand(client"[SM] Timer is already running, so you can't start a new one.");
        return 
Plugin_Handled;
    }
    
    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));
    
GetCmdArg(3TimerResultsizeof(TimerResult));
    
    
Minutes StringToInt(arg1);
    
Seconds StringToInt(arg2);
    
    if (
Seconds 60 || Seconds || Minutes || Minutes 60) {
        
ReplyToCommand(client"[SM] Seconds and Minutes must be an intiger value between 0 and 60");
        return 
Plugin_Handled;
    }
    
    
TimerTime Seconds + (Minutes 60);

    
CreateTimer(1.0Timer_ShowTimeLeft_TIMER_REPEAT);

    return 
Plugin_Handled;
}

public 
Action Timer_ShowTimeLeft(Handle timer)
{
    if (
SecondCounter >= TimerTime) {
        
SecondCounter 0;
        
PrintToChatAll("%s"TimerResult); // print whatever stored in arg 3, when timer is done
        
TimerRunning false// set to false for new timer to be ready for use
        
return Plugin_Stop;
    }
    if (
Minutes && Seconds 1) {
        
Minutes--;
        
Seconds 60;
    }
    
    
PrintCenterTextAll("%d:%d"MinutesSeconds);
    
SecondCounter++;
    
Seconds--;
    return 
Plugin_Continue;

wow, thanks!
__________________

klashfire is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 04-10-2016 , 10:37   Re: Plugin Crashes TF2
Reply With Quote #8

Quote:
Originally Posted by klashfire View Post
wow, thanks!
No problem .
__________________
xines is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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