SA-MP Forums Archive
I discover something on my NPC - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I discover something on my NPC (/showthread.php?tid=292548)



I discover something on my NPC - GAMER_PS2 - 24.10.2011

I found Something on my NPC
when i connect it to my server it works fine
but goes what my rank system and score system
textdraw is look like getting buggy/glitch.

Heres what i mean

heres my original rank

Code:
LEVEL: 36
SCORE: 109871
but every 2 secs it became

Code:
LEVEL: 0
SCORE: 0
but after 1 secs it came back to normal again

Heres my code of NPC

pawn Code:
#include <a_npc>
#define rec "BallasSeller"
#define onfoot 2

main(){}

public OnRecordingPlaybackEnd() StartRecordingPlayback(onfoot,rec);
public OnNPCSpawn()
{
    SetMyPos(1904.8568,-1737.0551,13.3292);
    StartRecordingPlayback(onfoot,rec);
}
Gamemode Deatils:

OnGameModeInit:

pawn Code:
ConnectNPC("ZondonX","BallasSeller"); //Ballas Seller - NPC
OnPlayerSpawn

pawn Code:
if(IsPlayerNPC(playerid))
   {
      new npcname[MAX_PLAYER_NAME];
      GetPlayerName(playerid, npcname, sizeof(npcname));
      if(!strcmp(npcname, "ZondonX", true))
      {
         SetPlayerSkin(playerid,102);
      }
      return 1;
   }
Help me guys


Re: I discover something on my NPC - =WoR=Varth - 24.10.2011

Show us the code where you set the textdraw.


Re: I discover something on my NPC - GAMER_PS2 - 25.10.2011

Here you go

pawn Code:
//at the top of script

new Text:Score;
new Text:Level;
new rank[MAX_PLAYERS];
pawn Code:
//OnGameModeInit

//============================================================================//

    Score = TextDrawCreate(498.000000, 113.000000, "SCORE:~r~");
    TextDrawBackgroundColor(Score, 0x0088FFAA);
    TextDrawFont(Score, 3);
    TextDrawLetterSize(Score, 0.479997, 2.299998);
    TextDrawColor(Score, 0xE100E1FF);
    TextDrawSetOutline(Score, 1);
    TextDrawSetProportional(Score, 1);
   
//============================================================================//
   
    Level = TextDrawCreate(498.000000, 95.000000, "LEVEL:~r~");
    TextDrawBackgroundColor(Level, 0x0088FFAA);
    TextDrawFont(Level, 3);
    TextDrawLetterSize(Level, 0.519999, 2.299998);
    TextDrawColor(Level, 0xE100E1FF);
    TextDrawSetOutline(Level, 1);
    TextDrawSetProportional(Level, 1);

//============================================================================//
pawn Code:
public OnPlayerUpdate(playerid)
{
    new string[128];
    new score;
    score = GetPlayerScore(playerid);
    format(string, sizeof string, "SCORE:~r~%d", score);
    TextDrawSetString(Score, string);
    if(GetPlayerScore(playerid) >= 40000) rank[playerid] = 36;
    else if(GetPlayerScore(playerid) >= 30000) rank[playerid] = 35;
    else if(GetPlayerScore(playerid) >= 25000) rank[playerid] = 34;
    else if(GetPlayerScore(playerid) >= 20000) rank[playerid] = 33;
    else if(GetPlayerScore(playerid) >= 15000) rank[playerid] = 32;
    else if(GetPlayerScore(playerid) >= 10000) rank[playerid] = 31;
    else if(GetPlayerScore(playerid) >= 9500) rank[playerid] = 30;
    else if(GetPlayerScore(playerid) >= 9000) rank[playerid] = 29;
    else if(GetPlayerScore(playerid) >= 8500) rank[playerid] = 28;
    else if(GetPlayerScore(playerid) >= 8000) rank[playerid] = 27;
    else if(GetPlayerScore(playerid) >= 7500) rank[playerid] = 26;
    else if(GetPlayerScore(playerid) >= 7000) rank[playerid] = 25;
    else if(GetPlayerScore(playerid) >= 6500) rank[playerid] = 24;
    else if(GetPlayerScore(playerid) >= 6000) rank[playerid] = 23;
    else if(GetPlayerScore(playerid) >= 5500) rank[playerid] = 22;
    else if(GetPlayerScore(playerid) >= 5000) rank[playerid] = 21;
    else if(GetPlayerScore(playerid) >= 4500) rank[playerid] = 20;
    else if(GetPlayerScore(playerid) >= 4000) rank[playerid] = 19;
    else if(GetPlayerScore(playerid) >= 3500) rank[playerid] = 18;
    else if(GetPlayerScore(playerid) >= 3000) rank[playerid] = 17;
    else if(GetPlayerScore(playerid) >= 2500) rank[playerid] = 16;
    else if(GetPlayerScore(playerid) >= 2000) rank[playerid] = 15;
    else if(GetPlayerScore(playerid) >= 1500) rank[playerid] = 14;
    else if(GetPlayerScore(playerid) >= 1000) rank[playerid] = 13;
    else if(GetPlayerScore(playerid) >= 900) rank[playerid] = 12;
    else if(GetPlayerScore(playerid) >= 800) rank[playerid] = 11;
    else if(GetPlayerScore(playerid) >= 700) rank[playerid] = 10;
    else if(GetPlayerScore(playerid) >= 600) rank[playerid] = 9;
    else if(GetPlayerScore(playerid) >= 500) rank[playerid] = 8;
    else if(GetPlayerScore(playerid) >= 400) rank[playerid] = 7;
    else if(GetPlayerScore(playerid) >= 300) rank[playerid] = 6;
    else if(GetPlayerScore(playerid) >= 200) rank[playerid] = 5;
    else if(GetPlayerScore(playerid) >= 100) rank[playerid] = 4;
    else if(GetPlayerScore(playerid) >= 75) rank[playerid] = 3;
    else if(GetPlayerScore(playerid) >= 50) rank[playerid] = 2;
    else if(GetPlayerScore(playerid) >= 25) rank[playerid] = 1;
    else if(GetPlayerScore(playerid) >= 0) rank[playerid] = 0;
    format(string, sizeof string, "LEVEL:~r~%d", rank[playerid]);
    TextDrawSetString(Level, string);
    return 1;
}
pawn Code:
//OnPlayerSpawn

   TextDrawShowForPlayer(playerid, Score);
   TextDrawShowForPlayer(playerid, Level);
Now what?


Re: I discover something on my NPC - =WoR=Varth - 25.10.2011

Check if player is NPC or not inside your "OnPlayerUpdate(playerid)" and "OnPlayerSpawn"


Re: I discover something on my NPC - GAMER_PS2 - 25.10.2011

Dude Exactly the NPC is onplayerspawn


Re: I discover something on my NPC - GAMER_PS2 - 26.10.2011

i read rules 48 hours has been pass so i can bump...


Re: I discover something on my NPC - AndreT - 26.10.2011

You're doing it wrong. You need to have one textdraw per player, not one per all.

Create it like this:
pawn Code:
new Text:playerTD[MAX_PLAYERS];
for(new i = 0; i != MAX_PLAYERS; i++)
{
    playerTD[i] = TextDrawCreate(...);
}
Also, the code for your rank "calculating" is very very bad.
1) Don't run such code in OnPlayerUpdate, run it where the score is actually modified. This means you should create your own wrapper for SetPlayerScore. The wrapper needs to do what you do in OnPlayerUpdate. Otherwise, in plain words, the script is fucked performance-wise.
2) Don't call GetPlayerScore(playerid) theoretically 37 times. Just do it once and use a switch statement.
pawn Code:
switch(GetPlayerScore(playerid))
{
    case 0 .. 25: rank[playerid] = 1;
    case 25 .. 50: rank[playerid] = 2;
    // ...
}



Re: I discover something on my NPC - i514x - 26.10.2011

@UP: Second part of the post wasn't there when I was posting :P

Quote:
Originally Posted by AndreT
View Post
You're doing it wrong. You need to have one textdraw per player, not one per all.

Create it like this:
pawn Code:
new Text:playerTD[MAX_PLAYERS];
for(new i = 0; i != MAX_PLAYERS; i++)
{
    playerTD[i] = TextDrawCreate(...);
}
Correct, also why did you put it in OnPlayerUpdate, it should only be updated when you give or take score from player so make it into a function, and call the function when SetPlayerScore is called.


Quote:
Originally Posted by GAMER_PS2
View Post
i read rules 48 hours has been pass so i can bump...
If you read it carefully, you will notice that 48hrs should gone from the last, not from the first one and it should contain some useful information, not just that ur bumping xD


Re: I discover something on my NPC - Finn - 26.10.2011

I'd like to hear the reason you are using OnPlayerUpdate for such code?

Your code needs to be called every time you use SetPlayerScore, not 2 hundred million times a minute.

Edit: meh i am slow


Re: I discover something on my NPC - GAMER_PS2 - 27.10.2011

Oh comeon help me out