Everything's fine, compiles and runs... But wtf?!
#1

Ok, I got a blank gamemode with nothing fancy... Just two scripts with commands actually. One is that something will happen if your HP is under 20 (with timer checking it) and another is if you type /tackle near someone something will happen.

Ok when I go test it myself alone, everything works perfectly. You can use /getup (view the script), and /tackle "works" (says SendClientMessage text).

When I go test it with my friend, it fuck up. "AutoCrack" won't work at all, the script won't reconize /getup, /tackle... And no, auto-crack didn't work of course. Only a filterscript worked, which I had left in the server cfg file lol. Wtf... Someone could check the script and tell me why it fucks up with more players than one? Here's the whole script:
pawn Код:
#include <a_samp>


new
    g_tCrackTick[MAX_PLAYERS],
    g_bCrackState[MAX_PLAYERS];

main( ) { }

 #undef MAX_PLAYERS
 #define MAX_PLAYERS 15


 forward AutoCrack(playerid);

public OnGameModeInit()
{
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, 0xFFFFFF, " Hello, and welcome testing scripts by John, mostly for Cisco City Roleplay! ");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetTimer("AutoCrack", 3500, true);
    SetPlayerSkin(playerid, 28);
    GivePlayerWeapon(playerid, 24, 50);
    GivePlayerWeapon(playerid, 25, 50);
    GivePlayerWeapon(playerid, 29, 300);
    GivePlayerWeapon(playerid, 30, 300);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new
        Float:health;

    GetPlayerHealth(playerid, health);
   
    if (strcmp("/getup", cmdtext, true, 6) == 0)
    {
        if(health <= 20.0)
        if ((GetTickCount() - g_tCrackTick[playerid]) > 15000)
        {
            SetPlayerHealth(playerid, 21);
            TogglePlayerControllable(playerid, true);
            ApplyAnimation(playerid,"PED","getup_front",5.0,0,1,1,1,1,1);
            SendClientMessage(playerid, 0x4AF8FF, " You've successfully got up! Remember to roleplay your injuries. ");
            g_bCrackState[playerid] = 0;
        }
    }
    else
    {
        SendClientMessage(playerid, 0x4AF8FF, " Error: Cmd fail? Trololol ");
    }
    if (strcmp("/crackme", cmdtext, true, 6) == 0)
    {
        SetPlayerHealth(playerid, 10);
    }
    if (strcmp("/tackle", cmdtext, true, 6) == 0) {
        new victimid = GetClosestPlayer(playerid);
        if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
        {
            if(random(2) == 0)
            {
                ApplyAnimation(playerid,"DODGE","Cover_Dive_01",5.0,0,1,1,1,1,1);
                TogglePlayerControllable(victimid, false);
                ApplyAnimation(victimid,"PARACHUTE","FALL_skyDive_DIE",5.0,0,1,1,1,1,1);
                SendClientMessage(playerid, 0x4AF8FF, " You have successfully downed your target! ");
                SendClientMessage(victimid, 0x4AF8FF, " You have been tackle'd down by someone! ");
                }
                else
                {
                    SendClientMessage(playerid, 0x4AF8FF, " You've failed to tackle your target. ");
                    SendClientMessage(victimid, 0x4AF8FF, " Someone tried to tackle you! ");
            }
        }
        return 1;
    }
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

public AutoCrack(playerid)
{
    new
        Float:health;

    GetPlayerHealth(playerid, health);

    if(health <= 20.0 && !g_bCrackState[playerid])
    {
        TogglePlayerControllable(playerid, false);
        ApplyAnimation(playerid,"PED","KO_spin_L",3.0,0,1,1,1,1,1);
        g_bCrackState[playerid] = 1;
        g_tCrackTick[playerid] = GetTickCount();
    }
    return 1;
}

forward Float:GetDistanceBetweenPlayers(p1,p2);
public Float:GetDistanceBetweenPlayers(p1,p2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2)) {
        return -1.00;
    }
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}


forward GetClosestPlayer(p1);
public GetClosestPlayer(p1)
{
    new x,Float:dis,Float:dis2,player;
    player = -1;
    dis = 99999.99;
    for (x=0;x<MAX_PLAYERS;x++) {
        if(IsPlayerConnected(x)) {
            if(x != p1) {
                dis2 = GetDistanceBetweenPlayers(x,p1);
                if(dis2 < dis && dis2 != -1.00) {
                    dis = dis2;
                    player = x;
                }
            }
        }
    }
    return player;
}
P.S. I might know why the AutoCrack's timer won't work even without other players. I didn't have "GivePlayerShit" and "SetPlayerPoop" stuff under the "SetTimer" for AutoCrack. I fucked up the timer with that crap, am I right? :P


Edit: A screenie. When Mark said shit in the chat he did /q. And see how the script dos after i'm alone...
Reply
#2

Ok, i found a few problems.


First problem is you are using SetTimer, instead of SetTimerEx, so you dont pass its playerid.
This brings up the problem that you need to store a players 'TimerID'

At the top:
pawn Код:
new playerTimers[MAX_PLAYERS];
Setting the timer:
pawn Код:
playerTimers[playerid] = SetTimerEx("AutoCrack", 3500, true, i, playerid);
Finaly, Kill this timer when they Die, or disconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason) {
    KillTimer(playerTimers[playerid]);
    return 1;
}
public OnPlayerDeath(playerid, killerid, reason) {
    KillTimer(playerTimers[playerid]);
    return 1;
}
About the commands, '/crackme' is 8 long, so:
pawn Код:
if (strcmp("/crackme", cmdtext, true, 6) == 0)
Should be:
pawn Код:
if (strcmp("/crackme", cmdtext, true, 8) == 0)

I hope this helps.
Reply
#3

Try now

pawn Код:
#include <a_samp>

new g_bCrackState[MAX_PLAYERS];

main( ) { }

 #undef MAX_PLAYERS
 #define MAX_PLAYERS 15
 
forward AutoCrack(playerid);

public OnGameModeInit()
{
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, 0xFFFFFF, " Hello, and welcome testing scripts by John, mostly for Cisco City Roleplay! ");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetTimer("AutoCrack", 3500, true);
    SetPlayerSkin(playerid, 28);
    GivePlayerWeapon(playerid, 24, 50);
    GivePlayerWeapon(playerid, 25, 50);
    GivePlayerWeapon(playerid, 29, 300);
    GivePlayerWeapon(playerid, 30, 300);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new
        Float:health;

    GetPlayerHealth(playerid, health);

    if (strcmp("/getup", cmdtext, true, 6) == 0)
    {
        GetPlayerHealth(playerid,health);
        if(health < 20.0)
        {
            SetTimerEx("AutoCrack", 15000, false, "is", 1337, " ");
            SetPlayerHealth(playerid, 21);
            TogglePlayerControllable(playerid, true);
            ApplyAnimation(playerid,"PED","getup_front",5.0,0,1,1,1,1,1);
            SendClientMessage(playerid, 0x4AF8FF, " You've successfully got up! Remember to roleplay your injuries. ");
            g_bCrackState[playerid] = 0;
         }
    }
    if (strcmp("/crackme", cmdtext, true, 8) == 0)
    {
        SetPlayerHealth(playerid, 10);
        SendClientMessage(playerid,-1,"you have sucefully cracked yourself !"); // here...
        return 1;
    }
    if (strcmp("/tackle", cmdtext, true, 8) == 0) {
        new victimid = GetClosestPlayer(playerid);
        if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
        {
            new Chance = random(10); // your random function was totally wrong
            {
               switch(Chance)
               {
                  case 5,10:
                  {
                    ApplyAnimation(playerid,"DODGE","Cover_Dive_01",5.0,0,1,1,1,1,1);
                    TogglePlayerControllable(victimid, false);
                    ApplyAnimation(victimid,"PARACHUTE","FALL_skyDive_DIE",5.0,0,1,1,1,1,1);
                    SendClientMessage(playerid, 0x4AF8FF, " You have successfully downed your target! ");
                    SendClientMessage(victimid, 0x4AF8FF, " You have been tackle'd down by someone! ");
                  }
                  case 1,2,3,4,7,8,9:
                  {
                    SendClientMessage(playerid, 0x4AF8FF, " You've failed to tackle your target. ");
                    SendClientMessage(victimid, 0x4AF8FF, " Someone tried to tackle you! ");
                  }
               }
            }
        }
        return 1;
    }
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

public AutoCrack(playerid)
{
    new Float:health;

    GetPlayerHealth(playerid,health);
    if(health < 20.0 && !g_bCrackState[playerid])
    {
        TogglePlayerControllable(playerid, false);
        ApplyAnimation(playerid,"PED","KO_spin_L",3.0,0,1,1,1,1,1);
        g_bCrackState[playerid] = 1;
    }
    return 1;
}

forward Float:GetDistanceBetweenPlayers(p1,p2);
public Float:GetDistanceBetweenPlayers(p1,p2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2)) {
        return -1.00;
    }
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}


forward GetClosestPlayer(p1);
public GetClosestPlayer(p1)
{
    new x,Float:dis,Float:dis2,player;
    player = -1;
    dis = 99999.99;
    for (x=0;x<MAX_PLAYERS;x++) {
        if(IsPlayerConnected(x)) {
            if(x != p1) {
                dis2 = GetDistanceBetweenPlayers(x,p1);
                if(dis2 < dis && dis2 != -1.00) {
                    dis = dis2;
                    player = x;
                }
            }
        }
    }
    return player;
}
Reply
#4

Alright i'll test those as soon as I get a friend with me.

Btw, leonardo's code destroyed my tick... Ehich was really needed. Now I can spam /getup as much as I want, making the whole AutoCrack system useless lmao.
Reply
#5

Well, Just add a block funtion there to lock the command for a while, i forgot to do this.

Anyways, all comands are working now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)