/drag command - using timers, failure
#1

Hello,

I'm currently working on a /drag command for LEO factions for my RP server, and I've attempted to create a /drag command earlier but failed. Now I wanted to see if I notice the problem, but I failed again and I'm hopeless. I can't find the problem at all. Can anyone take a look at my code and tell me what I've done wrong etc? I don't need a fixed code. I want to learn it myself. It crashes my pawn compiler too though, I think I've missed a closing or opening bracket but I can't find where. Thanks in advance.

Command
pawn Код:
YCMD:drag(playerid, params[], help) {
    if(help) {
        SendClientMessage(playerid, X11_WHITE, "Drags a player");
        return 1;
     }
     if(!IsAnLEO(playerid)) {
        SendClientMessage(playerid, X11_TOMATO_2, "You are not a cop!");
        return 1;
     }
     if(!IsOnDuty(playerid)) {
        SendClientMessage(playerid, X11_TOMATO_2, "You are not on duty!");
        return 1;
     }
     new player;
     //new user;
     if(!sscanf(params,"k<playerLookup>", player)) {
        if(!IsPlayerConnectEx(player)) {
            SendClientMessage(playerid, X11_TOMATO_2, "User not found");
            return 1;
        }
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(player, X, Y, Z);
        if(!IsPlayerInRangeOfPoint(playerid, 2.5, X, Y, Z)) {
            SendClientMessage(playerid, X11_TOMATO_2, "You are too far away");
            return 1;
        }
        if(!IsPlayerConnectEx(player)) {
            SendClientMessage(playerid, X11_TOMATO_2, "User not found");
            return 1;
        }
        if(GetPVarType(player, "CuffTime") == PLAYER_VARTYPE_NONE) {
            SendClientMessage(playerid, X11_TOMATO_2, "This person isn't cuffed!");
            return 1;
        }
        new string[128];
        if(GetPVarInt(user, "Dragged") == 0) {
            if(GetDistanceBetweenPlayers(playerid, player) < 7) {
                //new rank = GetPVarInt(playerid, "Rank");
                format(string, sizeof(string), "* %s %s has started dragging %s.", GetPVarInt(playerid, "Rank"), GetPlayerNameEx(playerid, ENameType_RPName), GetPlayerNameEx(player, ENameType_RPName));
                ProxMessage(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                SetPVarInt(player, "Dragged", 1);
                draggingtimer[player] = SetTimerEx("draggingtimer", 1000, true, "ii", playerid, player); // Updates position every second
                TogglePlayerControllable(player, 0);
                return 1;
            }
        }
        if(GetPVarInt(user, "Dragged") == 1) {
            format(string, sizeof(string), "* Officer %s has stopped dragging %s.", GetPlayerNameEx(playerid, ENameType_RPName), GetPlayerNameEx(player, ENameType_RPName));
            ProxMessage(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetPVarInt(player, "Dragged", 0);
            KillTimer(draggingtimer[player]);
            TogglePlayerControllable(player, 1);
            return 1;
        }
    } else {
        SendClientMessage(playerid, X11_WHITE, "USAGE: /drag [playerid/name]");
    }
    return 1;
}
Public + forward
pawn Код:
forward draggingtimer(playerid);
public draggingtimer(playerid)
{
    new playa;
    new Float:X, Float:Y, Float:Z;
    new interior = GetPlayerInterior(playerid);
    new vw = GetPlayerVirtualWorld(playerid);
    SetPlayerVirtualWorld(playa, vw);
    SetPlayerInterior(playa, interior);
    GetPlayerPos(playerid, X, Y, Z);
    SetPlayerPos(playa, X, Y, Z);
    return 1;
}
Regards, Sidney.
Reply
#2

The variable "playa" has no player id assigned to it. Pass it as a parameter (which is what you do with the timer anyway).
Reply
#3

I tried to change:

pawn Код:
forward draggingtimer(playerid);
public draggingtimer(playerid)
{
    new playa;
    new Float:X, Float:Y, Float:Z;
    new interior = GetPlayerInterior(playerid);
    new vw = GetPlayerVirtualWorld(playerid);
    SetPlayerVirtualWorld(playa, vw);
    SetPlayerInterior(playa, interior);
    GetPlayerPos(playerid, X, Y, Z);
    SetPlayerPos(playa, X, Y, Z);
    return 1;
}
to:

pawn Код:
forward draggingtimer(playerid, player);
public draggingtimer(playerid, player)
{
    //new playa;
    new Float:X, Float:Y, Float:Z;
    new interior = GetPlayerInterior(playerid);
    new vw = GetPlayerVirtualWorld(playerid);
    SetPlayerVirtualWorld(player, vw);
    SetPlayerInterior(player, interior);
    GetPlayerPos(playerid, X, Y, Z);
    SetPlayerPos(player, X, Y, Z);
    return 1;
}
But it still crashes my pawn compiler, and I can't find any missing brackets at all.
Reply
#4

A missing bracket isn't the only thing that can make your compiler crash (and there are none in the code you posted above from what I can see). Unfortunately I do not remember anything else that could make it crash.
Reply
#5

I've noticed that I forgot to change some values. Therefore I can't find the problem at all. The compiler only crashes when I uncomment that part of code. But I never give up!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)