My CPU Usage is going crazy.
#1

Whenever there are like 2 players, it raises to 80% usage, and just auto-restarts, on one player it doesn't restard, but it's like on 50%.
My onplayerupdate :
pawn Код:
public OnPlayerUpdate(playerid)
{
    GetPlayerName(playerid, sendername, sizeof(sendername));
    GiveNameSpace(sendername);
    if(GetPlayerMoney(playerid) != PCash[playerid]) {
        SetPlayerMoney(playerid,PCash[playerid]);
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
    {
        new a, b, c;
        GetPlayerKeys(playerid, a, b ,c);
        if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
        {
            new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
            ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
        }
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        for(new i = 0; i < sizeof(SpikeInfo); i++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 3.0, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ]))
            {
                if(SpikeInfo[i][sCreated] == 1)
                {
                    new panels, doors, lights, tires;
                    new carid = GetPlayerVehicleID(playerid);
                    GetVehicleDamageStatus(carid, panels, doors, lights, tires);
                    tires = encode_tires(1, 1, 1, 1);
                    UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
                    return 0;
                }
            }
        }
    }
    if(PayDayAuth[playerid] == 1)
    {
        PayDayAuth[playerid] = 0;
        PayDay(playerid);
    }
    return 1;
}
Reply
#2

Well, you have a lot of shit in your OnPlayerUpdate, I suggest you to optimise the code, or use timers instead?
Reply
#3

It's nessecrey things, might giving me an advice to what I shall 'timer' ?
Reply
#4

The speed limit thing should be moved to a timer or removed completely. For spikes, you should create an invisible pickup (model 19300) and make it pickup-able by vehicles (type 14). Under OnPlayerPickUpPickup, spike the player if they enter the pickup and then re-create the pickup. Spikes should never be in a timer.
Reply
#5

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
The speed limit thing should be moved to a timer or removed completely. For spikes, you should create an invisible pickup (model 19300) and make it pickup-able by vehicles (type 14). Under OnPlayerPickUpPickup, spike the player if they enter the pickup and then re-create the pickup. Spikes should never be in a timer.
So to do like :
pawn Код:
spikepickup = CreatePickup(...)
on the strip place ?
Reply
#6

Yea and you'll also need to create two on the side. Make sure you actually add in spike code under OnPlayerPickUpPickup.

The offsets for the two side pickups are....

+ 0.6
- 0.6

on the Y coordinate.
Reply
#7

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Yea and you'll also need to create two on the side. Make sure you actually add in spike code under OnPlayerPickUpPickup.

The offsets for the two side pickups are....

+ 0.6
- 0.6

on the Y coordinate.
Like this ?

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{

    if(pickupid == spikepickup)
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            for(new i = 0; i < sizeof(SpikeInfo); i++)
            {
                if(IsPlayerInRangeOfPoint(playerid, 3.0, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ]))
                {
                    if(SpikeInfo[i][sCreated] == 1)
                    {
                        new panels, doors, lights, tires;
                        new carid = GetPlayerVehicleID(playerid);
                        GetVehicleDamageStatus(carid, panels, doors, lights, tires);
                        tires = encode_tires(1, 1, 1, 1);
                        UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
                        spikepickup = CreatePickup(19300, 14, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ], -1);
                        spikepickup = CreatePickup(19300, 14, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ]+0.6, -1);
                        spikepickup = CreatePickup(19300, 14, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ]-0.6, -1);
                        return 0;
                    }
                }
            }
        }
    }
    return 1;
}
Reply
#8

Like this:

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        for(new i = 0; i < sizeof(SpikeInfo); i++)
        {
            if(pickupid == Spikes[i][sPickup][0] || pickupid == Spikes[i][sPickup][1] || pickupid = Spikes[i][sPickup][2])
            {
                new panels, doors, lights, tires, carid = GetPlayerVehicleID(playerid);
                GetVehicleDamageStatus(carid, panels, doors, lights, tires);
                tires = encode_tires(1, 1, 1, 1);
                UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
                DestroyPickup(Spikes[i][sPickup][0]);
                DestroyPickup(Spikes[i][sPickup][1]);
                DestroyPickup(Spikes[i][sPickup][2]);
                Spikes[i][sPickup][0] = CreatePickup(19300, 14, SpikeInfo[i][sX], SpikeInfo[i][sY], SpikeInfo[i][sZ], -1);
                Spikes[i][sPickup][1] = CreatePickup(19300, 14, SpikeInfo[i][sX], SpikeInfo[i][sY] + 0.6, SpikeInfo[i][sZ], -1);
                Spikes[i][sPickup][2] = CreatePickup(19300, 14, SpikeInfo[i][sX], SpikeInfo[i][sY] - 0.6, SpikeInfo[i][sZ], -1);
                return 1;
            }
        }
    }
    return 1;
}
The offset is for the Y coordinate by the way, not Z.
Reply
#9

I think I did something bla bla, now I don't know what it is, just my 'OnPlayerLogin' function won't be called, when ever I put my password in my login dialog, it doesn't executes the function, this is the console, crashdetect plugin.
pawn Код:
[21:50:12] [debug] #4 00283ae4 in public OnDialogResponse (playerid=0, dialogid=5, response=1, listitem=-1, inputtext[]=@0x00ed3ebc "") at D:\SAMP\RD-RP Los Santos\gamemodes\rdrp.pwn:43951
[21:50:12] [debug] #3 000dcc1c in public OnPlayerLogin (playerid=0, password[]=@0x00ed3ebc "") at D:\SAMP\RD-RP Los Santos\gamemodes\rdrp.pwn:13068
[21:50:12] [debug] #2 0000bc48 in DOF2_GetString (file[]=@0x00f13818 "", key[]=@0x00e0f984 "Key", tag[]=@0x00ed40e0 "") at D:\SAMP\pawno\include\DOF2.inc:685
[21:50:12] [debug] #1 0000bdac in DOF2_GetStringEx (file[]=@0x00f13818 "", key[]=@0x00e0f984 "Key", result[]=@0x00f131f8 "", size=128, tag[]=@0x00ed40e0 "") at D:\SAMP\pawno\include\DOF2.inc:698
[21:50:12] [debug] #0 0000d0b8 in DOF2_ParseFile (file[]=@0x00f13818 "", extraid=-1, bool:callback=0) at D:\SAMP\pawno\include\DOF2.inc:1134
[21:50:12] [debug] AMX backtrace:
[21:50:12] [debug]  Accessing element at index 256 past array upper bound 255
[21:50:12] [debug] Run time error 4: "Array index out of bounds"
EDIT:
I can log in to my character on my homehost, but cannot on my host...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)