Liberty Unleashed

Scripting => Script Help => Topic started by: SM999pgrz on December 21, 2015, 12:06:33 am

Title: Help me with Sprite
Post by: SM999pgrz on December 21, 2015, 12:06:33 am
 ::) i have my own server logo and i want to add it to the server, so i tried this and didn't worked  :P

g_vlogoPos <- VectorScreen( 10, ScreenHeight - 60 );
g_logo <- GUISprite( "logo.png",  ::g_vlogoPos );
 
function onClientSpawn( pClass )
{
 
   g_logo.Visible = true;
   return 1;
}

i created an client file called: spriteclient.nut, and added these script in to then.
don't worked  :o

Please if someone can give me a full information to do this correctly i aprecciate, and sorry for my crap ensglish  8)
Title: Re: Help me with Sprite
Post by: Theremin on December 21, 2015, 12:59:32 am
function onClientSpawn( pClass )
Try renaming pClass to spawnclass, also did you add a Sprite folder with the sprite in it, inside the script folder? (it must be placed inside the same script folder, not the general Scripts folder) one last question, did you add <sprite file="logo.png"/> inside Script.xml file?
Title: Re: Help me with Sprite
Post by: SM999pgrz on December 21, 2015, 04:21:19 pm
thank theremin. You took my biggest doubt,  ;D I think now is not how to fail. ps: I thought it was so <image file = "logo.png" client = "0" /> xD  :P
Title: Re: Help me with Sprite
Post by: SM999pgrz on December 21, 2015, 04:30:01 pm
<sprite file="logo.png"/>
//script.xml//

client.nut
->
g_vlogoPos <- VectorScreen( 10, ScreenHeight - 60 );
g_logo <- GUISprite( "logo.png",  ::g_vlogoPos );
 
function onClientSpawn( spawnclass )
{
 
   g_logo.Visible = true;
   return 1;
}
function onScriptLoad() {
  BindKey('X', BINDTYPE_DOWN, "PressX", 123);
  BindKey('B', BINDTYPE_DOWN "PressB", 123);
  BindKey('K', BINDTYPE_DOWN "PressK", 123);
  BindKey('R', BINDTYPE_DOWN "PressR", 123);
  BindKey('Y', BINDTYPE_DOWN "PressY", 123);
  BindKey('G', BINDTYPE_DOWN "PressG", 123);     
  return 1;
}
function PressX(somenumber) {
  CallServerFunc( "Main/main.dll", "Bust", FindLocalPlayer());
}
function PressB(somenumber) {
  CallServerFunc( "Main/main.dll", "BuyProp", FindLocalPlayer());
}
function PressK(somenumber) {
  CallServerFunc( "Main/main.dll", "LockCar", FindLocalPlayer());
}
function PressR(somenumber) {
  CallServerFunc("Main/AdminCommands.dll", "Reset", FindLocalPlayer());
}
function PressY(somenumber) {
  CallServerFunc("Main/main.dll", "Job", FindLocalPlayer());
}
function PressG(somenumber) {
  CallServerFunc("Main/main.dll", "BribeWeps", FindLocalPlayer());
}
Local <- FindLocalPlayer();
Headshot <- null;
function onClientShot(pPlayer, Weapon, Part) {
   if (Part == BODYPART_HEAD && Weapon >= 3 && Weapon <= 7) {
      Local.RemoveLimb(BODYPART_HEAD);
      Local.Health=1;
   }
}
function onPlayerJoin(pPlayer) {
   return 0;
}
function onPlayerPart(pPlayer, iReason) {
  return 0;
}
function onPlayerConnect(pPlayer) {
  return 0;
}
function onPlayerAction(pPlayer, szText) {
 return 0;
}

what is wrong?
Title: Re: Help me with Sprite
Post by: SM999pgrz on December 21, 2015, 04:31:48 pm
the 'Sprites' folder are inside Scripts/Main/Sprites !
Title: Re: Help me with Sprite
Post by: Theremin on December 21, 2015, 07:41:12 pm
I tested it in my server, you forgot
Code: [Select]
AddGUILayer( g_logo );
also
Code: [Select]
g_logo.Visible = true; isn't necessary unless you want to make it invisible elsewhere
Title: Re: Help me with Sprite
Post by: SM999pgrz on December 23, 2015, 02:19:54 pm
yeah i added it later and really worked, but i'm not using anymore because it crashes when reconnect and reload script. do u known how to fix this crashes?  ::)
Title: Re: Help me with Sprite
Post by: Theremin on December 24, 2015, 01:49:29 am
Well I have the same code I gave you, the only difference is that I use it with onScriptLoad instead of with onClientSpawn function. By the way I used a big logo when I tested your snippet and I noticed with onClientSpawn it crashes after the first reload, while with onScriptLoad it crashes only after the fourth reload. Last but not least, with onScriptLoad I get no crashes at all when using /reconnect, only when reloading it. So I guess the crashes may be caused by this:
[bug]
Sprites aren't removed correctly from memory (try to load many images, reconnect and do the same and you will see GUISprite() failed error due memory)
So in my opinion you should use GUISprite in onScriptLoad function and maybe avoid using a too large image for a logo.