Command dosnt work..
#1

Hey..
I'm trying to make a /robammu so you will be able to rob weapons from ammunation but as soon as i type the cmd i crash. I get no errors in pawno but when im testing it ingame i keep crashing so please help me!

pawn Код:
if(strcmp(cmd, "/robammu", true) == 0)
    {
        new success = random(2);
        if(AmmuRobbedRecently == 1)
        {
            SendClientMessage(playerid, COLOR_GREY, "* This Location Was Robbed Recently, Try Again Later");
            return 1;
        }
        if(PlayerInfo[playerid][pRobTime] >= 1)
        {
            SendClientMessage(playerid, COLOR_GREY, "* You already attempted or robbed a place recently, please wait.");
            return 1;
        }
        if(IsPlayerInRangeOfPoint(playerid, 10, 314.2548,-133.6627,999.6016) || IsPlayerInRangeOfPoint(playerid, 3,311.9589,-166.1407,999.6010))
        {
            if(GetPlayerWeapon(playerid) >= 24 && GetPlayerWeapon(playerid) <= 40)
            {
                if(PlayerInfo[playerid][pDuty] == 0)
                {
                    if(success == 1)
                    {
                        SendClientMessage(playerid, COLOR_ORANGE, "* You are now Robbing the Ammunation, please remain in the checkpoint for 290 Seconds!");
                        RobbingTime[playerid] = 95;
                        RobAmmuTimer = SetTimerEx("RobAmmu",3000,true,"i",playerid);
                        WantedPoints[playerid] = 5;
                        SetPlayerCriminal(playerid,255, "Robbing Ammunation");
                        PlayerInfo[playerid][pRobTime] = 3600;
                        AmmuRobbedRecently = 1;
                        SetTimer("UnsetAmmuRob",1500000,false);
                        OnePlayAnim(playerid, "SHOP", "ROB_Shifty", 4.0, 0, 0, 0, 0, 0); // Rob Lookout
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_ORANGE, "* You failed to rob ammunation!");
                        WantedPoints[playerid] = 2;
                        SetPlayerCriminal(playerid,255, "Attempting to rob Ammunation");
                        PlayerInfo[playerid][pRobTime] = 3600;
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "* Go Off duty first!");
                    return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "* You need a deadly weapon to perform this Act!");
                return 1;
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "* You're not at Ammunation's Rob Point!");
            return 1;
        }
        return 1;
    }
and here is the public shit
pawn Код:
public RobAmmu(playerid)
{
    new string[128];
    if(IsPlayerInRangeOfPoint(playerid, 10, 314.2548,-133.6627,999.6016) || IsPlayerInRangeOfPoint(playerid, 3,311.9589,-166.1407,999.6010))
    {
        if(RobbingTime[playerid] > 0)
        {
            RobbingTime[playerid] --;
            GameTextForPlayer(playerid, "~w~Remain in the ~r~Pickup ~w~~until the time ends!", 1000,4);
        }
        else
        {
            RobbingTime[playerid] = 0;
            KillTimer(RobAmmuTimer);
            new gun = random;
            new ammo = 500;
            SafeGivePlayerWeapon(playerid, gun, ammo);
            format(string, sizeof(string),"~w~You Robbed ~g~%s ~w~From ~y~Ammunation!", gun);
            GameTextForPlayer(playerid, string, 6000, 4);
            format(string, sizeof(string),"* You robbed %s From Ammunation!",gun);
            SendClientMessage(playerid, COLOR_GREY, string);
            WantedPoints[playerid] = 10;
            SetPlayerCriminal(playerid,255, "Robbing Ammunation");
        }
    }
    else
    {
        GameTextForPlayer(playerid, "~w~You Left The Checkpoint!", 1000,4);
        RobbingTime[playerid] = 0;
        KillTimer(RobAmmuTimer);
    }
}
Reply
#2

I think the string may be too large but i say only i THINK so. so i don't promise it is right
Reply
#3

Quote:
Originally Posted by Red_Dragon.
Посмотреть сообщение
I think the string may be too large but i say only i THINK so. so i don't promise it is right
i dont think thats the problem, i changed
pawn Код:
new gun = random
and
pawn Код:
new ammo = 500
and removed the
pawn Код:
= 500
and the
pawn Код:
= random
and accedently complied so i tested and then i didnt crash but also i didnt get any weapon or ammo
Reply
#4

Add prints to "debug" the command. After each and every line, add a print, then see server.log after the server crashes and count the number of printed messages - you will then find out what line is the last to execute before the crash, thus probably being the one causing the crash.

If you don't understand, here's a tiny example:

pawn Код:
if( something == something_else )
{
    print( "test" );
    doSomething();
    print( "test" );
    doSomethingMore();
    print( "test" );
    while( you == something_totally_different )
    {
        print( "test" );
        dontDoAnything();
        print( "test" );
    }
    doOneLastThing();
    print( "test" );
    return true;
}
If I'd count 3 "test" messages in the console, I'd know that the last thing to happen before the crash was the function doSomethingMore() - thus making it possible that this function is the reason for the crash.
Reply
#5

Quote:
Originally Posted by LarzI
Посмотреть сообщение
Add prints to "debug" the command. After each and every line, add a print, then see server.log after the server crashes and count the number of printed messages - you will then find out what line is the last to execute before the crash, thus probably being the one causing the crash.

If you don't understand, here's a tiny example:

pawn Код:
if( something == something_else )
{
    print( "test" );
    doSomething();
    print( "test" );
    doSomethingMore();
    print( "test" );
    while( you == something_totally_different )
    {
        print( "test" );
        dontDoAnything();
        print( "test" );
    }
    doOneLastThing();
    print( "test" );
    return true;
}
If I'd count 3 "test" messages in the console, I'd know that the last thing to happen before the crash was the function doSomethingMore() - thus making it possible that this function is the reason for the crash.
ok i didnt understand that, could u give another example?
Reply
#6

anyone knows what my problem is? i really want to make this work!
Reply
#7

help please
Reply
#8

Quote:
Originally Posted by Don_Cage
Посмотреть сообщение
ok i didnt understand that, could u give another example?
Well okay. You do know how the print function works, right?

If you put this in your code:
pawn Код:
print("hey");
Then the server console - samp-server.exe - will "print" the message "hey".

If you then try to run an if-statement like this for example:
pawn Код:
if( IsPlayerConnected( playerid ))
{
    mySendMessageFunc(playerid);
    myOtherFunc();
    return true;
}
And it doesn't work. You'll know that something is wrong with the code. If you then use the print function after each and every line, like so:
pawn Код:
if( IsPlayerConnected( playerid ))
{
    print("test1");
    mySendMessageFunc(playerid);
    print("test2");
    myOtherFunc();
    print("test3");
    return true;
}
and the server console prints out "test1" and "test2", you'll know that whatever came after test2 made the code crash - in this example it was the "myOtherFunc()" function.

If you do the same with your code, you can then debug/troubleshoot/diagnose what line causes the crash to appear.

If you decide to do this, make sure that you don't put prints between statements, callbacks, function-declarations, and their brace (between public/stock/randomFunctionName/if/else if/else/while/for and their { brace) - you always have to put it after, else the code will return in an error.

I can't explain this in an easier way, so I hope you understand this time!

I helped you start off by debugging the command part for you: http://pastebin.com/UyGdUB03
When you put that in your script instead of your original command, and you try running it by doing the command in-game, the serverconsole will print a lot of messages saying "test" and a number. Please post your server.log contents to pastebin.com and reply to this thread with the results.
Reply
#9

I got this errors:
Код:
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35741) : error 029: invalid expression, assumed zero
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35756) : error 029: invalid expression, assumed zero
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35763) : warning 225: unreachable code
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35766) : error 029: invalid expression, assumed zero
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35773) : warning 225: unreachable code
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35776) : error 029: invalid expression, assumed zero
C:\Users\new account\Desktop\Everything and Anything\Server\NEW SCRIPT!!!\Script\gamemodes\mazda.pwn(35783) : warning 225: unreachable code
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#10

Help please
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)