Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: [VM_U]Spectra.PhantoM^ on Jan 18, 2016, 08:35 PM

Title: Setwep cmd help.
Post by: [VM_U]Spectra.PhantoM^ on Jan 18, 2016, 08:35 PM
I builded it this far:
else if (cmd == "setwep")
{
local plr = GetPlayer(GetTok(text, " ", 1));
if ( !text ) MessagePlayer( "[#ffd700]Syntax: /"+ cmd +" <playername>", player );
if (PlayerIsAdmin)
{
plr.GiveWeapon( text.tofloat(), 999 );
Message("[#ff0000]-> [#FF0000]Admin [#ffffff]"+ player.Name +" gave "+ plr.Name +"");
}
}
but it gives me error:
AN ERROR HAS OCCURED [cannot convert the string]
CALLSTACK
*FUNCTION [onPlayerCommand()] Main.nut line [407]
LOCALS
[plr] INSTANCE
[plr] INSTANCE
[i] 2
[text] " ult spas"
[cmd] "setwep"
[player] INSTANCE
[this] TABLE
Help fast plz. Thanx
Title: Re: Setwep cmd help.
Post by: [VM_U]Spectra.PhantoM^ on Jan 19, 2016, 05:00 AM
Quote from: hotdogcat on Jan 19, 2016, 12:24 AMif (PlayerIsAdmin)

:palmface
thats a function i have. since im using RCON.so i dont use getlevel functions to check if player is admin.
Quote from: MatheuS on Jan 18, 2016, 09:33 PMplr.GiveWeapon( text.tofloat(), 999 );
wtf?
a random idea popped into my head.....
Title: Re: Setwep cmd help.
Post by: EK.IceFlake on Jan 19, 2016, 11:54 AM
wait a minute youre converting the text to a float WTF
and that playerisadmin wont work under any circumstances whatsoever.
Title: Re: Setwep cmd help.
Post by: MatheuS on Jan 19, 2016, 12:42 PM
.tofloat
0.156
.tointeger
1 2 3 4 5 6
.tolower
Old name: Testing       New name: testing  //if you're using tolower
.toupper
Old name: blablabla        New name: BLABLABLA
Title: Re: Setwep cmd help.
Post by: Thijn on Jan 19, 2016, 09:43 PM
Quote from: NE.CrystalBlue on Jan 19, 2016, 11:54 AMwait a minute youre converting the text to a float WTF
and that playerisadmin wont work under any circumstances whatsoever.
Why not?
function onPlayerCommand( player, text, args ) {
local PlayerIsAdmin = false;
if ( getRconLevelThing( player ) > 2 ) {
   PlayerIsAdmin = true;
}

if ( PlayerIsAdmin ) {
print("Yes.");
}



The most obvious error in that snippet is the .tofloat(). You would want to use the .tointeger() function.
Make sure you validate the text a bit more first, though. Functions like IsNum should give you a pretty good idea.

(Also cleaned the topic up a bit. Replies like WTF? :facepalm and commit suicide wont help anyone. Don't post anything if you have nothing useful to post.)
Title: Re: Setwep cmd help.
Post by: [VM_U]Spectra.PhantoM^ on Jan 21, 2016, 04:44 AM
Quote from: NE.CrystalBlue on Jan 19, 2016, 11:54 AMwait a minute youre converting the text to a float WTF
and that playerisadmin wont work under any circumstances whatsoever.
Its a functiones i have for the last time and IT WORKS MAN. i use it in meh server.
Title: Re: Setwep cmd help.
Post by: KAKAN on Jan 21, 2016, 08:54 AM
Quote from: {ultimatejugo] on Jan 21, 2016, 04:44 AM
Quote from: NE.CrystalBlue on Jan 19, 2016, 11:54 AMwait a minute youre converting the text to a float WTF
and that playerisadmin wont work under any circumstances whatsoever.
Its a functiones i have for the last time and IT WORKS MAN. i use it in meh server.
Try entering the ID instead of the name.
Title: Re: Setwep cmd help.
Post by: Williams on Jan 21, 2016, 10:36 AM
if ( cmd == "setwep" )
{
if ( GetLevel( player ) >= 5 )
{
   if ( text )
{
local plr = FindPlayer(GetTok(text, " ", 1));
local wep = GetTok( text, " ", 2 );
local ammo = GetTok( text, " ", 3 );
if ((GetLevel( player ) !=10 && GetWeaponID(wep) == 30)) MessagePlayer( "You need to be admin level 10 to spawn that weapon.", player );
else if ((GetLevel( player ) !=10 && GetWeaponID(wep) == 31)) MessagePlayer( "You need to be admin level 10 to spawn that weapon.", player );
else if ((GetLevel( player ) !=10 && GetWeaponID(wep) == 33)) MessagePlayer( "You need to be admin level 10 to spawn that weapon.", player );
else
{
plr.SetWeapon( GetWeaponID( wep ), ammo.tointeger());
MessagePlayer( "Admin "+ player.Name + " gave you a " + GetWeaponName( GetWeaponID( wep ) ) +". Ammo: " + ammo + ".",plr );
MessagePlayer( "Giving " + plr.Name + " a " + GetWeaponName( GetWeaponID( wep ) ) +". Ammo: " + ammo + ".",player );
}
}
else MessagePlayer( "USAGE: /setwep [ Nick/ID ] [ Weapon Name ] [ Ammo ]",player );
}
                    else MessagePlayer ( "Error - You need to be at least level 6 to use that command.", player );
}

Try that cmd ... Its tested.
Title: Re: Setwep cmd help.
Post by: [VM_U]Spectra.PhantoM^ on Jan 22, 2016, 08:37 AM
Quote from: Williams on Jan 21, 2016, 10:36 AM if ( cmd == "setwep" )
{
if ( GetLevel( player ) >= 5 )
{
   if ( text )
{
local plr = FindPlayer(GetTok(text, " ", 1));
local wep = GetTok( text, " ", 2 );
local ammo = GetTok( text, " ", 3 );
if ((GetLevel( player ) !=10 && GetWeaponID(wep) == 30)) MessagePlayer( "You need to be admin level 10 to spawn that weapon.", player );
else if ((GetLevel( player ) !=10 && GetWeaponID(wep) == 31)) MessagePlayer( "You need to be admin level 10 to spawn that weapon.", player );
else if ((GetLevel( player ) !=10 && GetWeaponID(wep) == 33)) MessagePlayer( "You need to be admin level 10 to spawn that weapon.", player );
else
{
plr.SetWeapon( GetWeaponID( wep ), ammo.tointeger());
MessagePlayer( "Admin "+ player.Name + " gave you a " + GetWeaponName( GetWeaponID( wep ) ) +". Ammo: " + ammo + ".",plr );
MessagePlayer( "Giving " + plr.Name + " a " + GetWeaponName( GetWeaponID( wep ) ) +". Ammo: " + ammo + ".",player );
}
}
else MessagePlayer( "USAGE: /setwep [ Nick/ID ] [ Weapon Name ] [ Ammo ]",player );
}
                    else MessagePlayer ( "Error - You need to be at least level 6 to use that command.", player );
}

Try that cmd ... Its tested.
Dammit i didnt think of GetWeaponID( wep ) just had .tointeger ideas. Problem solved thanx
Title: Re: Setwep cmd help.
Post by: KAKAN on Jan 22, 2016, 03:53 PM
Quote from: {ultimatejugo] on Jan 22, 2016, 08:37 AMDammit i didnt think of GetWeaponID( wep ) just had .tointeger ideas. Problem solved thanx
Off: Can you even think?
Title: Re: Setwep cmd help.
Post by: [VM_U]Spectra.PhantoM^ on Jan 22, 2016, 03:58 PM
Quote from: KAKAN on Jan 22, 2016, 03:53 PM
Quote from: {ultimatejugo] on Jan 22, 2016, 08:37 AMDammit i didnt think of GetWeaponID( wep ) just had .tointeger ideas. Problem solved thanx
Off: Can you even think?
Yes i can. No Rude Jestures PL0X