Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Xmair on Sep 02, 2015, 09:02 AM

Title: [Error]Parameters.
Post by: Xmair on Sep 02, 2015, 09:02 AM
else if ( cmd == "np" )
{
if ( !text ) ClientMessage("/np <pickupid> Np is used to see if you are near the pickup.",player,255,255,0)
else if ( !IsNum( text ) ) ClientMessage("Use numbers!",player,255,255,0)
else
{
local picpi = FindPickup(GetTok( text, " ", 1 ));
if ( picpi )
{
if ( DistanceFromPoint( picpi.Pos.x, picpi.Pos.y , player.Pos.x, player.Pos.y ) < 5 ) {
{
ClientMessage("You're near the pickup.",player,255,255,0)
}
}
else ClientMessage("You're not near the pickup",player,255,255,0)
}
else MessagePlayer("Pickup doesn't exists.",player)
}
}
Error :
[SCRIPT]  OnPlayerCommand Error: parameter 1 has an invalid type 'string' ; expected: 'integer'
No line specified in the error.
Title: Re: [Error]Parameters.
Post by: KAKAN on Sep 02, 2015, 09:07 AM
On which line does it gives the error?
if this line:-
local picpi = FindPickup(GetTok( text, " ", 1 ));Then change it to
local picpi = FindPickup(text.tointeger())
Title: Re: [Error]Parameters.
Post by: DizzasTeR on Sep 02, 2015, 09:49 AM
You used IsNum( text ) that means now the rest of the code will execute only when the given parameter is number/integer. That means you have to use .tointeger() with the text parameter since the original reference to text variable will be string.

Do what Kakan said and it should work however I would advise you not to use GetTok everywhere even where it is not needed.
Title: Re: [Error]Parameters.
Post by: Thijn on Sep 02, 2015, 04:38 PM
I also like to note, please remove the try {} catch blocks around your code. It makes debugging a lot easier since it would actually show linenumbers and stack.
Title: Re: [Error]Parameters.
Post by: Xmair on Sep 02, 2015, 04:44 PM
Solved, locked and alright @Thijn .