Author Topic: usefull scripts (for someone)  (Read 827 times)

Svenko

  • Full Member
  • ***
  • Posts: 239
  • Karma: +42/-47
    • View Profile
usefull scripts (for someone)
« on: December 20, 2011, 09:16:22 pm »
i will paste some SIMPLE script snippets that might help someone:
enjoy :)
NOTE: all scripts posted here works and were tested billion times so if they dont work it means you f***ed up something!

Code: (Squirrel) [Select]
function onPlayerDeath( pPlayer, iReason )
{
     if ( iReason == WEP_DROWNED )
     Message( pPlayer.Name + " has drowned", Colour( 255, 255, 0 ) );   
     else if ( iReason == WEP_EXPLOSION )
     Message( pPlayer.Name + " has died in explosion", Colour( 255, 255, 0 ) );     
     else if ( iReason == WEP_VEHICLE )
     Message( pPlayer.Name + " has been run over by a vehicle", Colour( 255, 255, 0 ) );
     else if ( iReason == WEP_FALL )
     Message( pPlayer.Name + " has died in a fall", Colour( 255, 255, 0 ) );
}

Code: (Squirrel) [Select]
function onPlayerChat( pPlayer, szParams )
{
     if ( pPlayer.Muted )
     {
     MessagePlayer( "*PM* Error: You are currently muted", pPlayer, Colour( 255, 0, 0 ) );
     }
}

Code: (Squirrel) [Select]
function onPlayerAction( pPlayer, szParams )
{
     if ( szParams == "died" )
     {
     pPlayer.Health = 0;
     pPlayer.Armour = 0;
     MessagePlayer( "*PM* Good Job. You asked for it", pPlayer, Colour( 0, 255, 0 ) );
     }
     else if ( szParams == "left the server" )
     {
     MessagePlayer( "*PM* Good Job. You asked for it", pPlayer, Colour( 0, 255, 0 ) );
     KickPlayer( pPlayer );
     }
}

Code: (Squirrel) [Select]
    else if ( szCommand == "anim")
{
if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <ID>", pPlayer, Colour( 255, 0, 0 ) );
else
{
    local pTemp = split( szParams, " " ), ID = 0;
    if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();

    if ( ( ID >= 0 ) && ( ID <= 167 ) )
{
pPlayer.SetAnim( szParams.tointeger() );
MessagePlayer( "*PM* You loaded animation with ID: " + szParams, pPlayer, Colour( 0, 255, 0 ) );
    }
else MessagePlayer( "*PM* Error: Invalid Animation ID", pPlayer, Colour( 255, 0, 0 ) );
}
}

Code: (Squirrel) [Select]
else if ( szCommand == "skin" )
{
if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <ID>", pPlayer, Colour( 255, 0, 0 ) );
else
{
pTemp = split( szParams, " " );
if ( IsNum( pTemp[ 0 ] ) )
{
local iSkin = pTemp[ 0 ].tointeger();
if ( ( iSkin >= 0 ) && ( iSkin <= 122 ) )
            {
pPlayer.Skin = iSkin;
                MessagePlayer( "*PM* You changed your skin to ID: " + iSkin, pPlayer, Colour( 0, 255, 0 ) );
                }
else MessagePlayer( "*PM* Error: Invalid Skin ID", pPlayer, Colour( 255, 0, 0 ) );
}
else MessagePlayer( "*PM* Usage: /" + szCommand + " <ID>", pPlayer, Colour( 255, 0, 0 ) );
}
}

Code: (Squirrel) [Select]
else if ( szCommand == "afk" )
{
if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <minutes>", pPlayer, Colour( 255, 0, 0 ) );
else
    {
pTemp = split( szParams, " " );
if ( IsNum( pTemp[ 0 ] ) )
{
local ID = pTemp[ 0 ].tointeger();
if ( ( ID >= 1 ) && ( ID <= 9999 ) )
    {
    pPlayer.Frozen = true;
    pPlayer.Muted = true;
    Message( pPlayer.Name + " is now away from keyboard for " + szParams + " minutes", Colour( 255, 255, 0 ) );
        MessagePlayer( "*PM* Type /back to get back, unfrozen and unmuted", pPlayer, Colour( 0, 255, 0 ) );
        }
        else MessagePlayer( "*PM* Error: Wrong ammount of minutes", pPlayer, Colour( 255, 0, 0 ) );
        }
    else MessagePlayer( "*PM* Usage: /" + szCommand + " <minutes>", pPlayer, Colour( 255, 0, 0 ) );
}
}

Code: (Squirrel) [Select]
else if ( szCommand == "msg" )
{
if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <ID/name> <message>", pPlayer, Colour( 255, 0, 0 ) );
else
{
local pTemp = split( szParams, " " ), p = GetPlayer( pTemp[ 0 ] );
if ( p )
{
local msg = szParams.slice( pTemp[ 0 ].len() + 1 );
MessagePlayer( "*PM* Private message sent to " + p.Name + ": " + msg, pPlayer, Colour( 0, 255, 0 ) );
PagerMessage( p, msg + " from " + pPlayer.Name, 150, 1, 0 );
}
else MessagePlayer( "*PM* Error: Can't find anyone with that ID or name", pPlayer, Colour( 255, 0, 0 ) );
}
}

Code: (Squirrel) [Select]
else if ( szCommand == "c1" )
{
if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <red> <green> <blue>", pPlayer, Colour( 255, 0, 0 ) );
else if ( !pPlayer.Vehicle ) MessagePlayer( "*PM* Error: You have to be inside the vehicle to paint it", pPlayer, Colour( 255, 0, 0 ) );
else
        {
local r = GetTok( szParams, " ", 1 ).tointeger(), g = GetTok( szParams, " ", 2 ).tointeger(), b = GetTok( szParams, " ", 3 ).tointeger();
    pPlayer.Vehicle.RGBColour1 = Colour( r, g, b );
        MessagePlayer( "*PM* You painted your vehicle's colour #1!", pPlayer, Colour( 0, 255, 0 ) );
   }
}

else if ( szCommand == "c2" )
{
if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <red> <green> <blue>", pPlayer, Colour( 255, 0, 0 ) );
else if ( !pPlayer.Vehicle ) MessagePlayer( "*PM* Error: You have to be inside the vehicle to paint it", pPlayer, Colour( 255, 0, 0 ) );
else
{
local r = GetTok( szParams, " ", 1 ).tointeger(), g = GetTok( szParams, " ", 2 ).tointeger(), b = GetTok( szParams, " ", 3 ).tointeger();
    pPlayer.Vehicle.RGBColour2 = Colour( r, g, b );
        MessagePlayer( "*PM* You painted your vehicle's colour #2", pPlayer, Colour( 0, 255, 0 ) );
   }
}

Code: (Squirrel) [Select]
   else if ( szCommand == "saveloc" )
   {
      if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <name>", pPlayer, Colour( 255, 0, 0 ) );
      else
      {
         local pos = pPlayer.Pos, formatize = format( "%.10f", pos.x ) + "," + format( "%.10f", pos.y ) + "," + format( "%.10f", pos.z ) + "," + format( "%.10f", pPlayer.Angle );
         SavedLocs.Add( szParams, formatize );
         SavedLocs.Save( "Hashes/SavedLocs.hsh" );
         MessagePlayer( "*PM* Location saved as: " + szParams, pPlayer, Colour( 0, 255, 0 ) );
      }
   }

   else if ( szCommand == "gotoloc" )
   {
      if ( !szParams ) MessagePlayer( "*PM* Usage: /" + szCommand + " <name>", pPlayer, Colour( 255, 0, 0 ) );
      else if ( !SavedLocs.Get( szParams ) ) MessagePlayer( "*PM* Error: That location does not exist", pPlayer, Colour( 255, 0, 0 ) );
      else
      {
         local coords = SavedLocs.Get( szParams ), spl = split( coords, "," );
         local newpos = Vector( spl[ 0 ].tofloat(), spl[ 1 ].tofloat(), spl[ 2 ].tofloat() );

         pPlayer.Pos = newpos;
         pPlayer.Angle = spl[ 3 ].tofloat();
         MessagePlayer( "*PM* Teleporting to location: " + szParams, pPlayer, Colour( 0, 255, 0 ) );
      }
   }

FOLLOWING SCRIPTS ARE CLIENT SIDE SCRIPTS:

Code: (Squirrel) [Select]
g_LocalPlayer <- FindLocalPlayer();

function onClientShot( pPlayer, iWeapon, iBodypart )
{
if ( g_LocalPlayer.Immune == false )
{
if ( iWeapon == WEP_EXPLOSION )
{
        g_LocalPlayer.RemoveLimb( BODYPART_LEFTARM );
g_LocalPlayer.RemoveLimb( BODYPART_RIGHTARM );
        g_LocalPlayer.RemoveLimb( BODYPART_LEFTLEG );
g_LocalPlayer.RemoveLimb( BODYPART_HEAD );
        g_LocalPlayer.RemoveLimb( BODYPART_RIGHTLEG );
        g_LocalPlayer.Health = 1;
}
}
}

Code: (Squirrel) [Select]
const RAMP_OBJECT = 1378;

objects <- array( GetMaxPlayers(), -1 );


function SpawnRamp( id, boost )
{
local plr = FindPlayer( id );
if ( plr )
{
local pos = plr.Pos;
local rot = plr.Angle, rad = rot * PI / 180.0;

local x = pos.x, y = pos.y;
local x2 = x + 1.0 * cos(rad) - 25.0 * sin(rad);
local y2 = y + 1.0 * sin(rad) + 25.0 * cos(rad);

if ( objects[id] != -1 )
{
local obj = FindObject( objects[id] );
if ( obj )
{
obj.Pos = Vector( x2, y2, pos.z - 0.3 );
obj.Angle = Vector( 0.0, 0.0, rot + 270.0 );
}
}
else
{
local obj = CreateObject( RAMP_OBJECT, Vector( x2, y2, pos.z ), Vector( 0.0, 0.0, rot + 270.0 ) );
if ( obj )
{
objects[id] = obj.ID;
}
}

if ( boost ) Boost( plr );
}
}

function Boost( plr )
{
local veh = plr.Vehicle;
if ( veh )
{
local vel = veh.Velocity;
vel.x *= 1.5;
vel.y *= 1.5;
vel.z *= 1.5;

veh.Velocity = vel;
}
}

function Fix( plr )
{
local veh = plr.Vehicle;
if ( veh )
{
plr.Vehicle.Fix();
}
}

function Flip( plr )
{
local veh = plr.Vehicle;
if ( veh )
{
    plr.Vehicle.Fix();
local rot = plr.Vehicle.Angle;
plr.Vehicle.Pos = plr.Vehicle.Pos;
plr.Vehicle.Angle = rot;
}
}

function Jump( plr )
{
local veh = plr.Vehicle;
if ( veh )
{
local vel = veh.Velocity;
vel.x += 0;
vel.y += 0;
vel.z += 0.5;

    veh.Velocity = vel;
}
}

function onPlayerPart( plr, reason )
{
local id = plr.ID;
if ( objects[id] != -1 )
{
local obj = FindObject( objects[id] );
if ( obj )
{
obj.Remove();
objects[id] = -1;
}
}

return 1;
}

Code: (Squirrel) [Select]
function onScriptLoad()
{
BindKey( 'O', BINDTYPE_DOWN, "Ramp" );
BindKey( 'P', BINDTYPE_DOWN, "RampWithBoost" );
BindKey( 'I', BINDTYPE_DOWN, "Boost" );
BindKey( 'U', BINDTYPE_DOWN, "Fix" );
BindKey( 'Z', BINDTYPE_DOWN, "Flip" );
BindKey( '2', BINDTYPE_DOWN, "Jump" );

g_pLocalPlayer <- FindLocalPlayer();

return 1;
}

function Ramp()
{
local veh = g_pLocalPlayer.Vehicle;
if ( veh )
{
local driver = veh.Driver;
if ( driver && driver.ID == g_pLocalPlayer.ID )
{
CallServerFunc( "binds/binds.nut", "Ramp", g_pLocalPlayer.ID, false );
}
}
}

function RampWithBoost()
{
local veh = g_pLocalPlayer.Vehicle;
if ( veh )
{
local driver = veh.Driver;
if ( driver && driver.ID == g_pLocalPlayer.ID )
{
CallServerFunc( "binds/binds.nut", "Ramp", g_pLocalPlayer.ID, true );
}
}
}

function Boost()
{
local veh = g_pLocalPlayer.Vehicle;
if ( veh )
{
local driver = veh.Driver;
if ( driver && driver.ID == g_pLocalPlayer.ID )
{
CallServerFunc( "binds/binds.nut", "Boost", g_pLocalPlayer );
}
}
}

function Fix()
{
local veh = g_pLocalPlayer.Vehicle;
if ( veh )
{
local driver = veh.Driver;
if ( driver && driver.ID == g_pLocalPlayer.ID )
{
CallServerFunc( "binds/binds.nut", "Fix", g_pLocalPlayer );
}
}
}

function Flip()
{
local veh = g_pLocalPlayer.Vehicle;
if ( veh )
{
local driver = veh.Driver;
if ( driver && driver.ID == g_pLocalPlayer.ID )
{
CallServerFunc( "binds/binds.nut", "Flip", g_pLocalPlayer );
}
}
}

function Jump()
{
local veh = g_pLocalPlayer.Vehicle;
if ( veh )
{
local driver = veh.Driver;
if ( driver && driver.ID == g_pLocalPlayer.ID )
{
CallServerFunc( "binds/binds.nut", "Jump", g_pLocalPlayer );
}
}
}
« Last Edit: March 26, 2013, 11:29:22 am by Svenko »

VetalYA

  • Guest
Re: usefull scripts (for someone)
« Reply #1 on: December 21, 2011, 05:27:59 pm »
It's great, and may be very helpful to new scripters  :)

But fix it from
Quote
function onPlayerAction( pPlayer, szParams )
{
     if ( szParams == "died" )
     {
     pPlayer.Health = 0;
     pPlayer.Armour = 0;
     MessagePlayer( "*PM* Good Job. You asked for it", pPlayer, Colour( 0, 255, 0 ) );
     }
   
     else if ( szParams == "left the server" )
     {
     KickPlayer( pPlayer );
     MessagePlayer( "*PM* Good Job. You asked for it", pPlayer, Colour( 0, 255, 0 ) );
     }
   
     return 1;
}

to


Quote
function onPlayerAction( pPlayer, szParams )
{
     if ( szParams == "died" )
     {
     pPlayer.Health = 0;
     pPlayer.Armour = 0;
     MessagePlayer( "*PM* Good Job. You asked for it", pPlayer, Colour( 0, 255, 0 ) );
     }
   
     else if ( szParams == "left the server" )
     {
     MessagePlayer( "*PM* Good Job. You asked for it", pPlayer, Colour( 0, 255, 0 ) );
     KickPlayer( pPlayer );

     }
   
     return 1;
}

Svenko

  • Full Member
  • ***
  • Posts: 239
  • Karma: +42/-47
    • View Profile
Re: usefull scripts (for someone)
« Reply #2 on: December 21, 2011, 08:06:01 pm »
done, actually it doesnt make any differences, but thanks anyway ;)

Vortrex

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +14/-16
  • Quantum Gaming Developer
    • View Profile
Re: usefull scripts (for someone)
« Reply #3 on: December 21, 2011, 10:03:22 pm »
Actually it does make a difference. Vetal's modification allows the user to be messaged before being kicked. If you kick the player first, then send the message later, the player won't receive it because he is already gone. It also (but I'm not sure) might return an error because the pPlayer doesn't exist (he was kicked, so it was cleared out).

Ankit

  • Newbie
  • *
  • Posts: 23
  • Karma: +0/-2
    • View Profile
Re: usefull scripts (for someone)
« Reply #4 on: February 19, 2012, 04:29:13 am »
do i have to copy all these codes and paste in my lu server 's main.nut
then i have to start my server?

Bryce

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: usefull scripts (for someone)
« Reply #5 on: February 19, 2012, 04:53:45 am »
do i have to copy all these codes and paste in my lu server 's main.nut
then i have to start my server?
Yup

Ankit

  • Newbie
  • *
  • Posts: 23
  • Karma: +0/-2
    • View Profile
Re: usefull scripts (for someone)
« Reply #6 on: February 19, 2012, 05:14:21 am »
gives me error

SugarD

  • Argonath RPG Dev/Manager
  • Tester
  • Sr. Member
  • ****
  • Posts: 546
  • Karma: +16/-22
  • STOP IN THE NAME OF THE COLESLAW!
    • View Profile
    • Clan Xperience
Re: usefull scripts (for someone)
« Reply #7 on: February 20, 2012, 03:47:54 am »

Raiden

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: usefull scripts (for someone)
« Reply #8 on: February 20, 2012, 04:07:24 am »
gives me error

Probably cos some of them are ClientSide functions.

Am so ye, whats the error?

 

© Liberty Unleashed Team.