~ Checkpoint Help Please ~
#1

#include <streamer>
new Text:gMyText1;
...

public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
if(checkpointid == Checkpoint[0]){
if(gTeam[playerid] == TEAM_GANG){
new string[50], i = 30;
while(i >= 0)
{
i--;
format(string, sizeof(string), "CP TIME: %d", i);
TextDrawFont(gMyText1, 1);
TextDrawAlignment(gMyText1, 2);
TextDrawSetShadow(gMyText1, 0);
TextDrawSetString(gMyText1, string);
gMyText1 = TextDrawCreate(280,435,string);
TextDrawShowForAll(gMyText1);
}
}
}
return 1;
}

It shows "CP TIME:" and then some random letter on top of another letter I think its a bit messy cant really read it off. Any solution why the CP TIME: doesnt go down from 30 seconds?
Reply
#2

You're setting the textdraw's font, alignment and shadow, THEN creating it.

What's the purpose of this code? What is the 30 for?
Reply
#3

I see..

I'm trying to build a countdown Checkpoint. So the checkpoint starts off from 30 and goes down to 0 which is the end point, then call another function from there. But the textdraw is constant some reason..
Reply
#4

In seconds? You need to use a timer. When they enter the checkpoint, start a timer (SetTimerEx) with an interval of 1 second, repeating on. Use a variable to store the timer's ID and kill it when they leave a CP (OnPlayerLeaveDynamicCP) with KillTimer().

Example:

pawn Код:
new Text:gMyText1;
new cp_count = 30; // Set to 30 seconds
new cp_timer_id;

public OnGameModeInit()
{
    AddPlayerClass(188, 6, 6, 3, random(360), WEAPON_DEAGLE, 28, WEAPON_M4, 180, WEAPON_GRENADE,  1);
    Checkpoint[0] = CreateDynamicCP(-36.5200,-5.2453,3.1094,2,0,0);
    return 1;
}

public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == Checkpoint[0] && gTeam[playerid] == TEAM_GANG && cp_count == 31)
    {
        cp_count--; // Set to 30, this lets you know that the timer is active
        gMyText1 = TextDrawCreate(280, 435, "CP TIME: 30");
        TextDrawFont(gMyText1, 1);
        TextDrawAlignment(gMyText1, 2);
        TextDrawSetShadow(gMyText1, 0);
        TextDrawSetOutline(gMyText1, 1);
        TextDrawShowForAll(gMyText1);
        cp_timer_id = SetTimer("cp_timer", 888, true); // Timers are slow, 888 MS is around a second.
    }
}

public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
    if(checkpointid == Checkpoint[0] && gTeam[playerid] == TEAM_GANG && cp_count < 31)
    {
        KillTimer(cp_timer_id);
        TextDrawDestroy(gMyText1);
        cp_count = 31; // Set back to 30 so we know it's stopped
    }
    return 1;
}

forward cp_timer();
public cp_timer()
{
    cp_count--;
    if(cp_count == 0)
    {
        // Reached 0, give score or whatever
        KillTimer(cp_timer_id);
        TextDrawDestroy(gMyText1);
        cp_count = 31; // So we know the timer isn't running
    }
    else // Still counting
    {
        new tds[32];
        format(tds, sizeof(tds), "CP TIME: %i", cp_count);
        TextDrawSetString(gMyText1, tds);
    }
    return 1;
}
Please note that this isn't tested, and I'm not sure if it will even compile. It looks fine to me.
Reply
#5

Nice It works but the first time I go on checkpoint the textdraw doesn't show up. But if I leave it then re-enter it then it all works onwards from then. Any solution for this one?

EDIT 2: I can also take the CP while im in a vehicle. How could I disable that?
Reply
#6

Quote:
Originally Posted by theinformer
Посмотреть сообщение
I can also take the CP while im in a vehicle. How could I disable that?
Use IsPlayerInAnyVehicle.
Reply
#7

Thanks, And about the other bug which is: it doesnt show textdraw the first time I go on the Checkpoint but when I re-enter it, it shows me the textdraw.
Reply
#8

It works fine for me. Make sure you're using my updated code, there were problems at first.
Reply
#9

http://pastebin.com/TN7SE9wn

Please take a look, I've got the same exact codes.. Also please take notice that I've changed my TEAM_GANG into TEAM_att and possible also changed some defined variables, I.E. the colors.
Reply
#10

Why do you have

pawn Код:
forward OnPlayerEnterDynamicCP(playerid, checkpointid);
forward OnPlayerLeaveDynamicCP(playerid, checkpointid);
?

They are forwarded in streamer.inc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)